INNER CODE UNIT · Python
expected
aaryansinha16/AI-trader · backend/app.py:493
expected = max(1, int((end_dt - day_start).total_seconds() / 60))
if cnt < expected * 0.5:
try:
ob = td_bf.fetch_historical_bars(sym, day_start, end_dt, interval="1min")
if not ob.empty:
for col in ["vwap", "oi"]:
if col not in ob.columns:
ob[col] = 0
ob = ob[["timestamp", "symbol", "open", "high", "low", "close", "volume", "vwap", "oi"]]
_upsert(ob)
logger.info(f"Startup backfill {sym}: {len(ob)} bars")
_time.sleep(1.1)
except Exception as e:
logger.warning(f"Startup backfill {sym}: {e}")
# ── Tick backfill (NIFTY-I only — 5-day REST window) ──────────────
# Mirrors the candle backfill: fills tick gaps from 09:15 onwards
# so the live chart and micro features have continuous data.
try: