This script automatically captures market data every 5 minutes to populate your database with historical snapshots for testing the time-travel replay feature.
Captures data every 5 minutes until you stop it (Ctrl+C):
./auto-capture.shCaptures data for a specified number of minutes:
# Run for 1 hour (12 captures)
./auto-capture.sh 60
# Run for 30 minutes (6 captures)
./auto-capture.sh 30
# Run for market hours (6.25 hours = 375 minutes, ~75 captures)
./auto-capture.sh 375- Calls the cron API every 5 minutes
- Captures 15 sectors (Bank Nifty, IT, Pharma, Auto, Metal, Energy, FMCG, Realty, Financial Services, Private Bank, PSU Bank, Media, Commodities, Infrastructure, Services Sector)
- Captures 12 stocks (PNB, SBIN, CANBK, BANKBARODA, HDFCBANK, ICICIBANK, AXISBANK, KOTAKBANK, TCS, INFY, WIPRO, MARUTI, TATAMOTORS)
- Stores snapshots in Supabase with timestamps
- Shows progress with colored output
🕐 Auto-capture will run for 60 minutes
📊 Capturing data every 5 minutes...
Press Ctrl+C to stop
[2025-12-26 14:00:00] Capturing market data...
✅ Success! Captured 15 sectors, 12 stocks
Total captures: 1
⏳ Waiting 5 minutes until next capture...
[2025-12-26 14:05:00] Capturing market data...
✅ Success! Captured 15 sectors, 12 stocks
Total captures: 2
Press Ctrl+C to stop. It will show a summary:
Stopping auto-capture...
Total successful captures: 12
Run for 30-60 minutes to create enough data points to test the timeline slider:
./auto-capture.sh 60Run during market hours (9:15 AM - 3:30 PM) to capture real market movements:
# Start at 9:15 AM and let it run until 3:30 PM
./auto-capture.sh 375Run for 15 minutes to get 3 snapshots for a quick demo:
./auto-capture.sh 15After running the script, you can:
-
Check Supabase Dashboard
- Go to https://supabase.com
- Open Table Editor →
sector_snapshots - See all captured snapshots with timestamps
-
Test the Slider
- Open http://localhost:3000/momentum
- Drag the timeline slider
- See historical data at different times
-
Query via API
# Check snapshots between 2:00 PM and 2:05 PM curl "http://localhost:3000/api/snapshots?type=sector&start=2025-12-26T08:30:00.000Z&end=2025-12-26T08:35:00.000Z"
-
Run in background: Add
&at the end to run in background./auto-capture.sh 60 & -
Save output to file: Redirect output to a log file
./auto-capture.sh 60 > capture.log 2>&1
-
Check if running: Use
psto see if the script is runningps aux | grep auto-capture
Script says "Permission denied"
chmod +x auto-capture.shAPI returns 401 Unauthorized
- Check that
CRON_SECRETin.env.localmatches the script - Default:
9f3c1a7e4b2d8f0a6e9c3d1b5f7a2e4c8a6d0b9e3f2c1a4d7e8b5c6f0
API returns 404
- Make sure dev server is running:
npm run dev - Check that the API route exists at
app/api/cron/capture-market-data/route.ts
No data in Supabase
- Verify Supabase credentials in
.env.local - Check Supabase dashboard for any errors
- Run
./test-cron.shto test manually
For production, use GitHub Actions instead of this script:
- Runs automatically every 5 minutes
- No need to keep your computer on
- Free with GitHub Actions
- See
GITHUB_ACTIONS_SETUP.mdfor setup instructions
Note: This script is for local testing only. For production, deploy to Vercel and use GitHub Actions for automated data capture.