Historical bars seed
Pre-warms the historical_bars table so the first backtest is fast.
Run once after FLAG_HISTORICAL_BARS_ON_DEMAND is enabled on production.
When to use
- After enabling
FLAG_HISTORICAL_BARS_ON_DEMAND=1onraxx-api-prod. - After provisioning a new production Postgres instance (table is empty).
- Any time the
historical_barstable is truncated or restored from backup.
Invocation
heroku run --app raxx-api-prod \
python scripts/seed_historical_bars.py \
--symbols SPY,QQQ,IWM,AAPL,MSFT \
--lookback-days 730
Common variants:
# Dry run — prints what would be fetched, no DB writes
heroku run --app raxx-api-prod \
python scripts/seed_historical_bars.py \
--symbols SPY,QQQ --lookback-days 365 --dry-run
# 5-year seed for the full default symbol set
heroku run --app raxx-api-prod \
python scripts/seed_historical_bars.py \
--symbols SPY,QQQ,IWM,AAPL,MSFT,TSLA,NVDA \
--lookback-days 1825
Expected output
Seed parameters:
symbols: SPY, QQQ, IWM, AAPL, MSFT
date range: 2024-05-28 .. 2026-05-28
lookback_days: 730
mode: paper
dry_run: False
Seeding SPY (2024-05-28 .. 2026-05-28) ... 502 bars cached.
Seeding QQQ (2024-05-28 .. 2026-05-28) ... 502 bars cached.
...
Done. 2510 real bars ensured in historical_bars table.
Already-cached bars are skipped (gap detection). Re-running is idempotent.
Notes
- Requires
ALPACA_PAPER_API_KEY/ALPACA_PAPER_API_SECRET(or live equivalents) set on the dyno. - The script exits with an error if credentials are missing rather than writing synthetic bars to the persistent DB.
- On first backtest for any symbol not in the seed list, the runner fetches bars on demand and caches them automatically.