import sys sys.path.append('.') from database import TradeDB from datetime import timedelta db = TradeDB() try: res = db.conn.execute("SELECT code, buy_date, pnl FROM trade_history WHERE strategy='MOMENTUM' AND pnl > 0 ORDER BY buy_date DESC LIMIT 1").fetchone() if res: code, buy_dt = dict(res)["code"], dict(res)["buy_date"] start_time = (buy_dt - timedelta(seconds=180)).strftime("%Y%m%d%H%M%S") end_time = buy_dt.strftime("%Y%m%d%H%M%S") print(f"Fetching ticks for {code} from {start_time} to {end_time}") ticks = db.get_ws_ticks(code, market="KR", start_tick_time=start_time, end_tick_time=end_time) print(f"Found {len(ticks)} ticks") else: print("No trades found") finally: db.close()