23 lines
876 B
Python
23 lines
876 B
Python
from database import TradeDB
|
|
import json
|
|
|
|
db = TradeDB()
|
|
try:
|
|
for strat in ['MOMENTUM', 'BREAKOUT', 'SCALP', 'TAIL']:
|
|
row = db.conn.execute("SELECT id, out_data FROM optuna_jobs WHERE strategy=%s ORDER BY id DESC LIMIT 1", (strat,)).fetchone()
|
|
if not row: continue
|
|
|
|
job_id = row['id']
|
|
out_data = json.loads(row['out_data'] or '{}')
|
|
|
|
# Get latest whipsaw result
|
|
# Actually I can just run attach_whipsaw_recommend on this out_data
|
|
from kis_trader.backtest.optuna_whipsaw_recommend import attach_whipsaw_recommend
|
|
out_data = attach_whipsaw_recommend(out_data)
|
|
|
|
db.conn.execute("UPDATE optuna_jobs SET out_data=%s WHERE id=%s", (json.dumps(out_data, ensure_ascii=False), job_id))
|
|
db.conn.commit()
|
|
print(f"Updated job {job_id} for {strat}")
|
|
finally:
|
|
db.close()
|