@ -846,6 +846,22 @@ class ORBTradingEngine:
self . _session . session_id , date_str , phase = " eod_exit "
self . _session . session_id , date_str , phase = " eod_exit "
)
)
# Cancel any unfilled breakout candidates — must run unconditionally so
# stale pending records are cleaned up even when there are no open positions
# (e.g., server restarted after ORB detection but before any breakout).
for cand in self . _pending_cands :
self . _state . update_candidate_status (
self . _session . session_id , date_str , cand [ " ticker " ] , " timeout "
)
self . _pending_cands = [ ]
db_cands = self . _state . list_candidates ( self . _session . session_id , date_str )
for c in db_cands :
if c [ " status " ] == " pending " :
self . _state . update_candidate_status (
self . _session . session_id , date_str , c [ " ticker " ] , " timeout "
)
positions = self . _state . get_open_positions ( self . _session . session_id , date_str )
positions = self . _state . get_open_positions ( self . _session . session_id , date_str )
if not positions :
if not positions :
self . _log ( " EOD: no open positions " )
self . _log ( " EOD: no open positions " )
@ -880,21 +896,6 @@ class ORBTradingEngine:
self . _session . session_id , date_str , pos . ticker
self . _session . session_id , date_str , pos . ticker
)
)
# Cancel any unfilled breakout candidates (in-memory and DB)
for cand in self . _pending_cands :
self . _state . update_candidate_status (
self . _session . session_id , date_str , cand [ " ticker " ] , " timeout "
)
self . _pending_cands = [ ]
# Also sweep DB for any pending records not in in-memory list (e.g. after restart)
db_cands = self . _state . list_candidates ( self . _session . session_id , date_str )
for c in db_cands :
if c [ " status " ] == " pending " :
self . _state . update_candidate_status (
self . _session . session_id , date_str , c [ " ticker " ] , " timeout "
)
return { " closed " : closed }
return { " closed " : closed }
# ── Phase 6: Post-close ───────────────────────────────────────────────────
# ── Phase 6: Post-close ───────────────────────────────────────────────────