INNER CODE UNIT · Python
_is_market_hours
aaryansinha16/AI-trader · backend/app.py:523
def _is_market_hours() -> bool:
"""Return True if current IST time is within market hours 9:15–15:30."""
now_ist = datetime.now()
t = now_ist.time()
from datetime import time as dtime
return dtime(9, 15) <= t <= dtime(15, 31)
# How long the tick stream can be silent before we trigger a REST backfill
# (the WebSocket sends ~150-180 ticks/min during a normal session, so >120s
# gap means a real disconnect, not just illiquid quiet)
TICK_STALENESS_THRESHOLD_SECS = 120
# Throttle: never run the tick backfill more than once every N seconds
_last_tick_backfill_run = 0.0
_TICK_BACKFILL_MIN_INTERVAL = 60.0
# Consecutive SL tracking (ported from backtest 2026-04-15). After 2