INNER CODE UNIT · Python
strike
aaryansinha16/AI-trader · backend/app.py:484
strike = atm + delta * 50
for opt in ["CE", "PE"]:
sym = f"NIFTY{exp_code}{strike}{opt}"
chk = read_sql(
"SELECT COUNT(*) as cnt FROM minute_candles WHERE symbol=:s AND timestamp::date=:d",
{"s": sym, "d": today.isoformat()}
)
cnt = int(chk.iloc[0]["cnt"]) if not chk.empty else 0
# Only fetch if less than 50% expected bars
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"]]