Skip to content

arbitrage history tracking#15

Open
arnavdhole wants to merge 1 commit into
MusashiBot:mainfrom
arnavdhole:feat/arbitrage-history
Open

arbitrage history tracking#15
arnavdhole wants to merge 1 commit into
MusashiBot:mainfrom
arnavdhole:feat/arbitrage-history

Conversation

@arnavdhole
Copy link
Copy Markdown

Adds a system to persist every arbitrage opportunity the detector finds.

DB (supabase/migrations/):

  • arbitrage_opportunities — one row per unique (polymarket_id, kalshi_id) pair,
    upserted each scan. Tracks first/last seen, max spread, observation count, status.
  • arbitrage_snapshots — append-only time-series, one row per scan per pair.
    Records exact prices, spread, direction, and volumes at that moment.

Recorder (src/api/arbitrage-recorder.ts):

  • Upserts pairs and inserts snapshots each run.
  • Marks opportunities closed after 10 min of absence from scans.

Cron job (api/cron/record-arbitrage.ts):

  • Runs every 5 min. Uses 1% threshold (vs 3% API default) to capture
    near-arbitrage in history.

History endpoint:

  • GET /api/markets/arbitrage/history
  • Filterable by date range, status (active/closed), minSpread, category.
  • Paginated. Each row includes a latest_snapshot join with current prices.

… history endpoint

Database (supabase/migrations/20260425000000_arbitrage_history.sql):
- arbitrage_opportunities: one row per unique (polymarket_id, kalshi_id) pair,
  upserted on every scan. Tracks first/last seen, max spread ever observed,
  observation count, and lifecycle status (active/closed).
- arbitrage_snapshots: append-only time-series, one row per scan per pair.
  Records exact prices, spread, direction, and volumes at that moment.
- Indexes on status+last_seen, category, max_spread, and observed_at.

Recorder (src/api/arbitrage-recorder.ts):
- recordArbitrageOpportunities() upserts pairs and inserts snapshots in one call.
- Closes stale opportunities that haven't been seen in 10+ minutes.
- buildSupabaseClient() creates a service-role client for server-side writes.

Cron job (api/cron/record-arbitrage.ts):
- Runs every 5 minutes via Vercel Cron.
- Uses a 1% threshold (vs 3% API default) to capture near-arbitrage in history.
- Same CRON_SECRET auth pattern as refresh-markets.

History endpoint (api/markets/arbitrage/history.ts):
- GET /api/markets/arbitrage/history
- Filterable by date range, status (active/closed/all), minSpread, category.
- Paginated with limit/offset.
- Joins latest snapshot onto each opportunity row so callers see current prices.

vercel.json:
- Registered /api/markets/arbitrage/history route.
- Registered /api/cron/record-arbitrage route and cron schedule (*/5 * * * *).
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

@arnavdhole is attempting to deploy a commit to the Victor's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant