Skip to main content

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 bets table (see schema below)
  • FieldFunded API key (get one free)

Step 1: Database Schema

The partial index on 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

Run it:
Output:

Step 5: Parlay Settlement

For parlays, use the parlay endpoint instead:
For a deeper dive on parlay math and edge cases, see the Parlay Calculator guide.

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_attempts counter 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)

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