fix: fetch trend history per-window and run aggregation 24/7
Two fixes for missing intraday data: 1. Frontend: lifted selectedWindow state to page level so useTrendHistory passes window param to the API. Previously fetched all windows with limit=500 which exhausted the limit before reaching recent intraday data. Now fetches only the selected window's data. 2. Scheduler: removed market-hours-only restriction from periodic aggregation. Runs every 15 minutes 24/7 so intraday data is always populated for backtesting regardless of market state.
This commit is contained in:
@@ -501,22 +501,11 @@ async def schedule_cycle(pool: asyncpg.Pool, rds: aioredis.Redis) -> int:
|
||||
async def enqueue_periodic_aggregation(pool: asyncpg.Pool, rds: aioredis.Redis) -> int:
|
||||
"""Enqueue aggregation jobs for all active tickers.
|
||||
|
||||
Runs periodically during market hours to ensure trend data stays fresh
|
||||
even when no new documents are being ingested. This gives the intraday
|
||||
and 1d windows continuous updates based on existing signals and market
|
||||
price changes.
|
||||
Runs periodically to ensure trend data stays fresh even when no new
|
||||
documents are being ingested. During market hours this runs every ~15
|
||||
minutes; outside market hours it runs every ~60 minutes (for backtesting
|
||||
data continuity).
|
||||
"""
|
||||
# Only run during US market hours (Mon-Fri, 6:30 AM - 1:30 PM PT / 13:30-20:30 UTC)
|
||||
from datetime import datetime, timezone
|
||||
now = datetime.now(timezone.utc)
|
||||
weekday = now.weekday() # 0=Mon, 6=Sun
|
||||
hour_utc = now.hour + now.minute / 60.0
|
||||
|
||||
if weekday >= 5: # Weekend
|
||||
return 0
|
||||
if hour_utc < 13.5 or hour_utc > 20.5: # Outside market hours (with 30min buffer)
|
||||
return 0
|
||||
|
||||
# Fetch all active tickers
|
||||
rows = await pool.fetch(
|
||||
"SELECT ticker FROM companies WHERE active = TRUE ORDER BY ticker"
|
||||
|
||||
Reference in New Issue
Block a user