Automate Bet Settlement with a Node.js Cron Job
Most betting APIs give you odds. Very few settle your bets for you. This tutorial builds a complete automatic settlement system: a Node.js cron job that monitors finished matches, resolves pending bets (won/lost/refund), credits user balances, and sends notifications — all without manual intervention.What This System Does
Why Automatic Settlement Matters
| Manual settlement | Automatic settlement |
|---|---|
| Check each match result by hand | API returns won/lost/refund per market |
| Look up specific market outcomes | Player props, corners, cards — all resolved |
| Calculate payouts yourself | Payout included in response |
| Delay: hours to days | Delay: seconds after match ends |
| Does not scale past 50 bets/day | Handles thousands per cycle |
Prerequisites
- Node.js 18+
- PostgreSQL database with a
betstable (see schema below) - FieldFunded API key (get one free)
Step 1: Database Schema
status = 'pending' means the settlement query stays fast even with millions of historical bets.
Step 2: Settlement Worker
Step 3: Notification System
Send alerts when bets are settled. Here are three options:Option A: Discord Webhook
Option B: Email (Nodemailer)
Option C: Generic Webhook
Step 4: Schedule and Run
Step 5: Parlay Settlement
For parlays, use the parlay endpoint instead:Rate Limit Math
| Scenario | Bets/cycle | Cycles/day | API calls/day | Monthly | Plan |
|---|---|---|---|---|---|
| Small app (20 pending bets) | 20 | 1,440 | 1,440 | 43,200 | Starter ($29) |
| Medium app (100 pending) | 100 | 1,440 | 5,000 | 150,000 | Starter ($29) |
| Large app (500 pending) | 500 | 1,440 | 12,000 | 360,000 | Pro ($59) |
Production Hardening
Before running this in production:- Add a
settlement_attemptscounter to prevent infinite retries on broken bets - Set a max age (e.g., 7 days) — bets older than that get flagged for manual review
- Add health check endpoint for your monitoring system
- Log all settlements to a separate audit table
- Add Prometheus/Grafana metrics (settled/min, errors/min)
- Run the worker as a separate process (PM2, systemd, or Docker)
Related Guides
- Build a Settlement Engine (API Deep Dive) — advanced settlement patterns and edge cases
- Build a Sports Betting Website — full-stack tutorial including this settlement system
- Build a Discord Bot — send settlement alerts as Discord embeds
- Settlement API Overview — why FieldFunded is the only affordable API with built-in settlement
- Build a Parlay Calculator — parlay resolution logic
Get Your Free API Key
Start settling bets in minutes — 10,000 free requests/month
See Pricing
All plans compared — settlement included at every tier
