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
The FieldFunded API is one of the few odds APIs with built-in settlement â you send the bet details, it returns the result.
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
The settlement endpoint is lightweight â one call per bet. With event-level grouping and smart caching, most apps stay well within the Starter tier.
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
