bugfixes
This commit is contained in:
@ -381,7 +381,7 @@ def run_batch_stratin(id: UUID, runReq: RunRequest):
|
|||||||
|
|
||||||
def get_market_days_in_interval(datefrom, dateto, note = None, id = None):
|
def get_market_days_in_interval(datefrom, dateto, note = None, id = None):
|
||||||
#getting dates from calendat
|
#getting dates from calendat
|
||||||
clientTrading = TradingClient(ACCOUNT1_PAPER_API_KEY, ACCOUNT1_PAPER_SECRET_KEY, raw_data=False)
|
clientTrading = TradingClient(ACCOUNT1_PAPER_API_KEY, ACCOUNT1_PAPER_SECRET_KEY, raw_data=False, paper=True)
|
||||||
calendar_request = GetCalendarRequest(start=datefrom,end=dateto)
|
calendar_request = GetCalendarRequest(start=datefrom,end=dateto)
|
||||||
cal_dates = clientTrading.get_calendar(calendar_request)
|
cal_dates = clientTrading.get_calendar(calendar_request)
|
||||||
#list(Calendar)
|
#list(Calendar)
|
||||||
@ -469,6 +469,11 @@ def batch_run_manager(id: UUID, runReq: RunRequest, rundays: list[RunDay]):
|
|||||||
print("Entering BATCH RUN MANAGER")
|
print("Entering BATCH RUN MANAGER")
|
||||||
print("generated batch_ID", batch_id)
|
print("generated batch_ID", batch_id)
|
||||||
|
|
||||||
|
#sort rundays according to start atttibute
|
||||||
|
print("RUNDAYS before sort:", rundays)
|
||||||
|
rundays.sort(key=lambda x: x.start)
|
||||||
|
print("RUNDAYS after sort:", rundays)
|
||||||
|
|
||||||
cnt_max = len(rundays)
|
cnt_max = len(rundays)
|
||||||
cnt = 0
|
cnt = 0
|
||||||
#promenna pro sdileni mezi runy jednotlivych batchů (např. daily profit)
|
#promenna pro sdileni mezi runy jednotlivych batchů (např. daily profit)
|
||||||
@ -476,14 +481,15 @@ def batch_run_manager(id: UUID, runReq: RunRequest, rundays: list[RunDay]):
|
|||||||
note_from_run_request = runReq.note
|
note_from_run_request = runReq.note
|
||||||
first = None
|
first = None
|
||||||
last = None
|
last = None
|
||||||
first_frm = runReq.bt_from.strftime("%d.%m.")
|
|
||||||
last_frm = runReq.bt_to.strftime("%d.%m.")
|
# Find the minimum start date and maximum end date to add to Note
|
||||||
|
first = min(runday.start for runday in rundays)
|
||||||
|
last = max(runday.end for runday in rundays)
|
||||||
|
first_frm = first.strftime("%d.%m.")
|
||||||
|
last_frm = last.strftime("%d.%m.")
|
||||||
|
|
||||||
for day in rundays:
|
for day in rundays:
|
||||||
cnt += 1
|
cnt += 1
|
||||||
if cnt == 1:
|
|
||||||
first = day.start
|
|
||||||
elif cnt == cnt_max:
|
|
||||||
last = day.end
|
|
||||||
print("Datum od", day.start)
|
print("Datum od", day.start)
|
||||||
print("Datum do", day.end)
|
print("Datum do", day.end)
|
||||||
runReq.bt_from = day.start
|
runReq.bt_from = day.start
|
||||||
@ -509,7 +515,7 @@ def batch_run_manager(id: UUID, runReq: RunRequest, rundays: list[RunDay]):
|
|||||||
|
|
||||||
for i in db.stratins:
|
for i in db.stratins:
|
||||||
if str(i.id) == str(id):
|
if str(i.id) == str(id):
|
||||||
i.history += "\nBatch: "+str(batch_id)+" "+str(first)+" "+str(last)+" P:"+str(int(batch_abs_profit))+ "R:"+str(round(batch_rel_profit,4))
|
i.history += "\nBatch: "+str(batch_id)+" "+str(first_frm)+" "+str(last_frm)+" P:"+str(int(batch_abs_profit))+ "R:"+str(round(batch_rel_profit,4))
|
||||||
#i.history += str(runner.__dict__)+"<BR>"
|
#i.history += str(runner.__dict__)+"<BR>"
|
||||||
db.save()
|
db.save()
|
||||||
|
|
||||||
@ -791,7 +797,7 @@ def populate_metrics_output_directory(strat: StrategyInstance, inter_batch_param
|
|||||||
#archives runner and details
|
#archives runner and details
|
||||||
def archive_runner(runner: Runner, strat: StrategyInstance, inter_batch_params: dict = None):
|
def archive_runner(runner: Runner, strat: StrategyInstance, inter_batch_params: dict = None):
|
||||||
results_metrics = dict()
|
results_metrics = dict()
|
||||||
print("inside archive_runner")
|
print("inside store archive_runner")
|
||||||
try:
|
try:
|
||||||
if strat.bt is not None:
|
if strat.bt is not None:
|
||||||
bp_from = strat.bt.bp_from
|
bp_from = strat.bt.bp_from
|
||||||
|
|||||||
@ -50,7 +50,10 @@ class Trade_Offline_Streamer(Thread):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.main()
|
try:
|
||||||
|
self.main()
|
||||||
|
except Exception as e:
|
||||||
|
print("ERROR IN TRADE OFFLINE STREAMER"+str(e)+format_exc())
|
||||||
# #create new asyncio loop in the thread
|
# #create new asyncio loop in the thread
|
||||||
# loop = asyncio.new_event_loop()
|
# loop = asyncio.new_event_loop()
|
||||||
# asyncio.set_event_loop(loop)
|
# asyncio.set_event_loop(loop)
|
||||||
|
|||||||
@ -37,13 +37,9 @@ def generate_trading_report_image(runner_ids: list = None, batch_id: str = None,
|
|||||||
return -1, f"no batch {batch_id} found"
|
return -1, f"no batch {batch_id} found"
|
||||||
|
|
||||||
trades = []
|
trades = []
|
||||||
cnt_max = len(runner_ids)
|
|
||||||
cnt = 0
|
sada_list = []
|
||||||
#zatim zjistujeme start a end z min a max dni - jelikoz muze byt i seznam runner_ids a nejenom batch
|
|
||||||
end_date = None
|
|
||||||
start_date = None
|
|
||||||
for id in runner_ids:
|
for id in runner_ids:
|
||||||
cnt += 1
|
|
||||||
#get runner
|
#get runner
|
||||||
res, sada =cs.get_archived_runner_header_byID(id)
|
res, sada =cs.get_archived_runner_header_byID(id)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
@ -51,12 +47,9 @@ def generate_trading_report_image(runner_ids: list = None, batch_id: str = None,
|
|||||||
return -1, f"no runner {id} found"
|
return -1, f"no runner {id} found"
|
||||||
|
|
||||||
print("archrunner")
|
print("archrunner")
|
||||||
print(sada)
|
#print(sada)
|
||||||
|
sada_list.append(sada)
|
||||||
|
|
||||||
if cnt == 1:
|
|
||||||
start_date = sada.bt_from if sada.mode in [Mode.BT,Mode.PREP] else sada.started
|
|
||||||
if cnt == cnt_max:
|
|
||||||
end_date = sada.bt_to if sada.mode in [Mode.BT or Mode.PREP] else sada.stopped
|
|
||||||
# Parse trades
|
# Parse trades
|
||||||
|
|
||||||
trades_dicts = sada.metrics["prescr_trades"]
|
trades_dicts = sada.metrics["prescr_trades"]
|
||||||
@ -70,6 +63,17 @@ def generate_trading_report_image(runner_ids: list = None, batch_id: str = None,
|
|||||||
print(trades)
|
print(trades)
|
||||||
|
|
||||||
symbol = sada.symbol
|
symbol = sada.symbol
|
||||||
|
mode = sada.mode
|
||||||
|
|
||||||
|
#get from to dates
|
||||||
|
#calculate start a end z min a max dni - jelikoz muze byt i seznam runner_ids a nejenom batch, pripadne testovaci sady
|
||||||
|
if mode in [Mode.BT,Mode.PREP]:
|
||||||
|
start_date = min(runner.bt_from for runner in sada_list)
|
||||||
|
end_date = max(runner.bt_to for runner in sada_list)
|
||||||
|
else:
|
||||||
|
start_date = min(runner.started for runner in sada_list)
|
||||||
|
end_date = max(runner.stopped for runner in sada_list)
|
||||||
|
|
||||||
#hour bars for backtested period
|
#hour bars for backtested period
|
||||||
print(start_date,end_date)
|
print(start_date,end_date)
|
||||||
bars= get_historical_bars(symbol, start_date, end_date, TimeFrame.Hour)
|
bars= get_historical_bars(symbol, start_date, end_date, TimeFrame.Hour)
|
||||||
@ -542,5 +546,5 @@ def generate_trading_report_image(runner_ids: list = None, batch_id: str = None,
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# id_list = ["e8938b2e-8462-441a-8a82-d823c6a025cb"]
|
# id_list = ["e8938b2e-8462-441a-8a82-d823c6a025cb"]
|
||||||
# generate_trading_report_image(runner_ids=id_list)
|
# generate_trading_report_image(runner_ids=id_list)
|
||||||
batch_id = "90973e57"
|
batch_id = "05cb35e3"
|
||||||
generate_trading_report_image(batch_id=batch_id)
|
generate_trading_report_image(batch_id=batch_id)
|
||||||
|
|||||||
@ -408,6 +408,8 @@ class Strategy:
|
|||||||
#data loader thread
|
#data loader thread
|
||||||
self.dataloader.start()
|
self.dataloader.start()
|
||||||
|
|
||||||
|
print("jsme za spustenim loaderu")
|
||||||
|
|
||||||
if self.mode == Mode.LIVE or self.mode == Mode.PAPER:
|
if self.mode == Mode.LIVE or self.mode == Mode.PAPER:
|
||||||
#live notification thread
|
#live notification thread
|
||||||
self.order_notifs.start()
|
self.order_notifs.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user