INNER CODE UNIT · Python
_startup_backfill
aaryansinha16/AI-trader · backend/app.py:431
def _startup_backfill():
try:
if not _is_market_hours():
return
today = date.today()
day_start = datetime(today.year, today.month, today.day, 9, 15, 0)
end_dt = datetime.now()
# Find the first candle we have today (could be None if totally missing)
first = read_sql(
"SELECT MIN(timestamp) as first_bar FROM minute_candles "
"WHERE symbol = 'NIFTY-I' AND timestamp::date = :d",
{"d": today.isoformat()}
)
first_bar = None
if not first.empty and first.iloc[0]["first_bar"] is not None:
first_bar = pd.to_datetime(first.iloc[0]["first_bar"], utc=True)
first_bar_ist = first_bar.tz_convert("Asia/Kolkata").replace(tzinfo=None)