2 Commits

Author SHA1 Message Date
9830cbee71 archrunner db query searches for symbol, name 2024-03-15 10:03:35 +01:00
5fce627fe3 toml validation to frontend (#174) 2024-03-14 17:39:52 +01:00
3 changed files with 20 additions and 19 deletions

View File

@ -3,7 +3,7 @@ from uuid import UUID, uuid4
import pickle import pickle
from alpaca.data.historical import StockHistoricalDataClient from alpaca.data.historical import StockHistoricalDataClient
from alpaca.data.requests import StockTradesRequest, StockBarsRequest from alpaca.data.requests import StockTradesRequest, StockBarsRequest
from alpaca.data.enums import DataFeed from alpaca.data.enums import DataFeed
from alpaca.data.timeframe import TimeFrame from alpaca.data.timeframe import TimeFrame
from v2realbot.strategy.base import StrategyState from v2realbot.strategy.base import StrategyState
from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Account, OrderSide from v2realbot.enums.enums import RecordType, StartBarAlign, Mode, Account, OrderSide
@ -103,10 +103,10 @@ def create_stratin(si: StrategyInstance):
#validate toml #validate toml
res, stp = parse_toml_string(si.stratvars_conf) res, stp = parse_toml_string(si.stratvars_conf)
if res < 0: if res < 0:
return (-1,"stratvars invalid") return (-1,f"stratvars invalid: {stp}")
res, adp = parse_toml_string(si.add_data_conf) res, adp = parse_toml_string(si.add_data_conf)
if res < 0: if res < 0:
return (-1, "None") return (-1, f"add data conf invalid {adp}")
si.id = uuid4() si.id = uuid4()
#print(si) #print(si)
db.stratins.append(si) db.stratins.append(si)
@ -120,10 +120,10 @@ def modify_stratin(si: StrategyInstance, id: UUID):
return (-1, "strat is running, use modify_stratin_running") return (-1, "strat is running, use modify_stratin_running")
res, stp = parse_toml_string(si.stratvars_conf) res, stp = parse_toml_string(si.stratvars_conf)
if res < 0: if res < 0:
return (-1, "stratvars invalid") return (-1, f"stratvars invalid {stp}")
res, adp = parse_toml_string(si.add_data_conf) res, adp = parse_toml_string(si.add_data_conf)
if res < 0: if res < 0:
return (-1, "add data conf invalid") return (-1, f"add data conf invalid {adp}")
for i in db.stratins: for i in db.stratins:
if str(i.id) == str(id): if str(i.id) == str(id):
#print("removing",i) #print("removing",i)
@ -181,14 +181,14 @@ def modify_stratin_running(si: StrategyInstance, id: UUID):
#validate toml #validate toml
res,stp = parse_toml_string(si.stratvars_conf) res,stp = parse_toml_string(si.stratvars_conf)
if res < 0: if res < 0:
return (-1, "new stratvars format invalid") return (-1, f"new stratvars format invalid {stp}")
for i in db.stratins: for i in db.stratins:
if str(i.id) == str(id): if str(i.id) == str(id):
if not is_stratin_running(id=str(id)): if not is_stratin_running(id=str(id)):
return (-1, "not running") return (-1, "not running")
res,stp_old = parse_toml_string(i.stratvars_conf) res,stp_old = parse_toml_string(i.stratvars_conf)
if res < 0: if res < 0:
return (-1, "current stratin stratvars invalid") return (-1, f"current stratin stratvars invalid {stp_old}")
#TODO reload running strat #TODO reload running strat
#print(stp) #print(stp)
#print("starting injection", stp) #print("starting injection", stp)
@ -447,7 +447,7 @@ def run_batch_stratin(id: UUID, runReq: RunRequest):
cal_list.append(RunDay(start = start_time, end = end_time, note = note, id = id)) cal_list.append(RunDay(start = start_time, end = end_time, note = note, id = id))
print(f"Getting interval dates from - to - RESULT ({len(cal_list)}):") print(f"Getting interval dates from - to - RESULT ({len(cal_list)}):")
print(cal_list) #print(cal_list)
return cal_list return cal_list
#getting days to run into RunDays format #getting days to run into RunDays format
@ -619,10 +619,10 @@ def run_stratin(id: UUID, runReq: RunRequest, synchronous: bool = False, inter_b
#validate toml #validate toml
res, stp = parse_toml_string(i.stratvars_conf) res, stp = parse_toml_string(i.stratvars_conf)
if res < 0: if res < 0:
return (-1, "stratvars invalid") return (-1, f"stratvars invalid {stp}")
res, adp = parse_toml_string(i.add_data_conf) res, adp = parse_toml_string(i.add_data_conf)
if res < 0: if res < 0:
return (-1, "add data conf invalid") return (-1, f"add data conf invalid {adp}")
id = uuid4() id = uuid4()
print(f"RUN {id} INITIATED") print(f"RUN {id} INITIATED")
name = i.name name = i.name
@ -1114,7 +1114,7 @@ def get_all_archived_runners_p(request: DataTablesRequest) -> Tuple[int, RunArch
# Total count query # Total count query
total_count_query = """ total_count_query = """
SELECT COUNT(*) FROM runner_header SELECT COUNT(*) FROM runner_header
WHERE (:search_value = '' OR strat_id LIKE :search_value OR batch_id LIKE :search_value) WHERE (:search_value = '' OR strat_id LIKE :search_value OR batch_id LIKE :search_value OR symbol like :search_value OR name like :search_value)
""" """
c.execute(total_count_query, {'search_value': f'%{search_value}%'}) c.execute(total_count_query, {'search_value': f'%{search_value}%'})
total_count = c.fetchone()[0] total_count = c.fetchone()[0]
@ -1129,7 +1129,7 @@ def get_all_archived_runners_p(request: DataTablesRequest) -> Tuple[int, RunArch
SUM(profit) OVER (PARTITION BY batch_id) AS batch_profit, SUM(profit) OVER (PARTITION BY batch_id) AS batch_profit,
COUNT(*) OVER (PARTITION BY batch_id) AS batch_count COUNT(*) OVER (PARTITION BY batch_id) AS batch_count
FROM runner_header FROM runner_header
WHERE (:search_value = '' OR strat_id LIKE :search_value OR batch_id LIKE :search_value) WHERE (:search_value = '' OR strat_id LIKE :search_value OR batch_id LIKE :search_value OR symbol like :search_value OR name like :search_value)
), ),
InterleavedGroups AS ( InterleavedGroups AS (
SELECT *, SELECT *,
@ -1156,7 +1156,7 @@ def get_all_archived_runners_p(request: DataTablesRequest) -> Tuple[int, RunArch
# Filtered count query # Filtered count query
filtered_count_query = """ filtered_count_query = """
SELECT COUNT(*) FROM runner_header SELECT COUNT(*) FROM runner_header
WHERE (:search_value = '' OR strat_id LIKE :search_value OR batch_id LIKE :search_value) WHERE (:search_value = '' OR strat_id LIKE :search_value OR batch_id LIKE :search_value OR symbol like :search_value OR name like :search_value)
""" """
c.execute(filtered_count_query, {'search_value': f'%{search_value}%'}) c.execute(filtered_count_query, {'search_value': f'%{search_value}%'})
filtered_count = c.fetchone()[0] filtered_count = c.fetchone()[0]
@ -1595,7 +1595,7 @@ def preview_indicator_byTOML(id: UUID, indicator: InstantIndicator, save: bool =
# print(row) # print(row)
res, toml_parsed = parse_toml_string(tomlino) res, toml_parsed = parse_toml_string(tomlino)
if res < 0: if res < 0:
return (-2, "toml invalid") return (-2, f"toml invalid: {toml_parsed}")
#print("parsed toml", toml_parsed) #print("parsed toml", toml_parsed)
@ -1841,10 +1841,10 @@ def preview_indicator_byTOML(id: UUID, indicator: InstantIndicator, save: bool =
#vracime list, kde pozice 0 je bar indicators, pozice 1 je ticks indicators #vracime list, kde pozice 0 je bar indicators, pozice 1 je ticks indicators
if output == "bar": if output == "bar":
return 0, [output_dict, []] return 0, [output_dict, {}]
#return 0, [new_inds[indicator.name], []] #return 0, [new_inds[indicator.name], []]
else: else:
return 0, [[], output_dict] return 0, [{}, output_dict]
#return 0, [[], new_tick_inds[indicator.name]] #return 0, [[], new_tick_inds[indicator.name]]
except Exception as e: except Exception as e:

View File

@ -462,7 +462,7 @@ function display_batch_report(batch_id) {
function refresh_logfile() { function refresh_logfile() {
logfile = $("#logFileSelect").val() logfile = $("#logFileSelect").val()
lines = 700 lines = 1200
$.ajax({ $.ajax({
url:"/log?lines="+lines+"&logfile="+logfile, url:"/log?lines="+lines+"&logfile="+logfile,
beforeSend: function (xhr) { beforeSend: function (xhr) {

View File

@ -678,8 +678,9 @@ def parse_toml_string(tomlst: str):
try: try:
tomlst = tomli.loads(tomlst) tomlst = tomli.loads(tomlst)
except tomli.TOMLDecodeError as e: except tomli.TOMLDecodeError as e:
print("Not valid TOML.", str(e)) msg = f"Not valid TOML: " + str(e)
return (-1, None) richprint(msg)
return (-1, msg)
return (0, dict_replace_value(tomlst,"None",None)) return (0, dict_replace_value(tomlst,"None",None))
#class to persist #class to persist