For a live sports betting odds feed, WebSocket beats REST whenever a stale price costs you something: the server pushes each change once, instead of you polling and hoping your interval was short enough. REST is still the right tool for snapshots, scheduled models, closing-line grading and anything that runs on a timer.
This post compares the two architectures without invented latency numbers, then shows working Python and Node.js code against one real odds API, PinnFeed, which serves Pinnacle odds over both REST and WebSocket. All endpoints, headers and message types below were checked against its public docs on 29 November 2026.
The core difference in one paragraph
With REST polling, freshness is bounded by your poll interval and your rate limit: if you may make one request every 5 seconds, a price that moved right after your last request waits up to 5 seconds before you see it, and you download the unchanged markets again every time. With a WebSocket, you open one connection, receive a snapshot of the current state, and then the server sends only the changes (deltas) as they happen. The trade-off is client complexity: you must keep state, answer heartbeats and reconnect cleanly.
Comparison table (architecture, not benchmarks)
| Dimension | REST polling | WebSocket push |
|---|---|---|
| How you learn about a price change | On your next poll | When the server sends the delta |
| Worst-case staleness | Roughly your poll interval (plus any plan delay) | Bounded by delivery, not by an interval you choose |
| Rate limits | Every poll counts against your request budget | One connection; no per-update request cost |
| Bandwidth | Full board on every poll, changed or not | Snapshot once, then only changed objects |
| Stale-odds risk | Grows with the interval | Lower, as long as the connection is healthy |
| Client complexity | Low: stateless request/response | Higher: local book, heartbeats, snapshot/delta, reconnect |
| Failure mode | A failed request; retry next tick | A silent or dropped socket; detect it, back off, resync |
| Caching / CDN / curl-friendly | Yes | No |
| Typical use | Dashboards, daily models, CLV grading, backfills | Live tools, line-movement alerts, in-play pricing |
We deliberately give no millisecond figures here. Latency depends on your region, network and client, so measure it yourself; PinnFeed stamps every market with updatedAt and every REST response with asOf, which makes that measurable.
What the limits look like on a real API
PinnFeed's published plan limits (pinnfeed.io/docs/limits, checked 29 Nov 2026) make the trade-off concrete:
| Plan | Price | REST rate | WebSocket | Data delay |
|---|---|---|---|---|
| Free | $0 | 1 req/s, 1,000 requests/day | No | 30 s |
| Realtime REST | $49/mo | 1 request every 5 s | No | Real time |
| Pre + Live WebSocket (Builder) | $139/mo | 10 req/s | 3 connections | Real time |
| Pro | $179/mo | 30 req/s | 10 connections | Real time |
On Realtime REST, you can refresh a board at most once every 5 seconds. On Builder, the WebSocket pushes each change and you still have 10 req/s of REST for lookups. Free and Realtime REST keys that open the socket get 403 plan_lacks_ws.
REST: a polite polling loop in Python
Base URL https://pinnfeed.io/v1, auth with the x-api-key header. /v1/odds returns events with their markets; sport is required.
# pip install requests import os, time, requests API = "https://pinnfeed.io/v1/odds" HEADERS = {"x-api-key": os.environ["PINNFEED_KEY"]} PARAMS = {"sport": "soccer", "market": "moneyline", "main": "true", "limit": 50} INTERVAL = 5 # seconds; Realtime REST allows 1 request every 5 s last_seen = {} # market id -> updatedAt while True: r = requests.get(API, headers=HEADERS, params=PARAMS, timeout=10) if r.status_code == 429: # rate_limited / daily_quota: honour Retry-After wait = int(r.headers.get("Retry-After", INTERVAL)) print("429:", r.json()["error"]["code"], "- waiting", wait, "s") time.sleep(wait) continue if not r.ok: raise SystemExit(f'HTTP {r.status_code}: {r.json()["error"]["message"]}') body = r.json() for ev in body["events"]: for m in ev["markets"]: mid = m["id"] # "eventId:key", stable across REST and WebSocket if last_seen.get(mid) != m["updatedAt"]: last_seen[mid] = m["updatedAt"] prices = {o["name"]: (o["decimal"], o["fair"]) for o in m["outcomes"]} print(body["asOf"], ev["home"], "v", ev["away"], prices) time.sleep(INTERVAL) Notes:
- Every market carries
updatedAt(its last price change), so you can skip unchanged markets client-side, but you still downloaded them. - On the Free plan, responses carry
X-Data-Delay-Seconds: 30andasOfis 30 seconds in the past. -
429 rate_limitedcarriesRetry-After;429 daily_quota(Free) resets at 00:00 UTC.
WebSocket: snapshot, deltas, heartbeats
Endpoint wss://pinnfeed.io/v1/stream. The lifecycle from the protocol docs:
- Connect with
x-api-key(header) and, ideally,permessage-deflatecompression. - Server sends
welcomewith your plan limits. - You send
subscribewithin 30 seconds (or the connection closes with4002 no_subscription). - Server sends
subscribed, then a chunkedsnapshot(parts of up to 400 events; wait forfinal: true), thendeltabatches. - Server sends
pingevery 20 seconds; reply{"type":"pong"}. Silent connections are closed after 60 seconds.
Python client with reconnect
# pip install websockets import asyncio, json, os, random import websockets URL = "wss://pinnfeed.io/v1/stream" SUB = {"type": "subscribe", "sports": ["soccer"], "markets": ["moneyline", "total"], "main": True} events, markets = {}, {} def apply_delta(changes): for c in changes: if c["kind"] == "event": if c["op"] == "remove": events.pop(c["id"], None) # an event removal means its markets go too for mid in [k for k, m in markets.items() if m["eventId"] == c["id"]]: markets.pop(mid, None) else: events[c["event"]["id"]] = c["event"] elif c["kind"] == "market": if c["op"] == "remove": markets.pop(c["id"], None) else: m = c["market"] # upsert carries the complete object markets[m["id"]] = m async def run(): attempt = 0 while True: try: async with websockets.connect( URL, additional_headers={"x-api-key": os.environ["PINNFEED_KEY"]} ) as ws: await ws.send(json.dumps(SUB)) async for raw in ws: msg = json.loads(raw) t = msg["type"] if t == "ping": await ws.send('{"type":"pong"}') elif t == "welcome": print("plan:", msg["plan"], "limits:", msg["limits"]) elif t == "snapshot": if msg["part"] == 1: events.clear(); markets.clear() events.update({e["id"]: e for e in msg["events"]}) markets.update({m["id"]: m for m in msg["markets"]}) if msg["final"]: attempt = 0 print(f"book ready: {len(events)} events, {len(markets)} markets") elif t == "delta": apply_delta(msg["changes"]) elif t == "error": print("subscribe error:", msg["code"], msg["message"]) except websockets.exceptions.InvalidStatus as e: # 401 invalid_key or 403 plan_lacks_ws: retrying will not help raise SystemExit(f"HTTP {e.response.status_code}: check your key and plan") except (websockets.ConnectionClosed, OSError) as e: print("disconnected:", e) # exponential backoff: 1, 2, 4 ... capped at 30 s, plus jitter delay = min(30, 2 ** attempt) + random.random() attempt += 1 await asyncio.sleep(delay) asyncio.run(run()) The websockets library offers permessage-deflate by default, so compressed frames come for free.
Node.js client
// npm install ws const WebSocket = require('ws'); const events = new Map(), markets = new Map(); function connect(attempt = 0) { const ws = new WebSocket('wss://pinnfeed.io/v1/stream', { headers: { 'x-api-key': process.env.PINNFEED_KEY }, perMessageDeflate: true, }); ws.on('open', () => { attempt = 0; ws.send(JSON.stringify({ type: 'subscribe', sports: ['tennis'], markets: ['moneyline'], live: true })); }); ws.on('message', (buf) => { const msg = JSON.parse(buf); if (msg.type === 'ping') return ws.send('{"type":"pong"}'); if (msg.type === 'snapshot') { if (msg.part === 1) { events.clear(); markets.clear(); } msg.events.forEach((e) => events.set(e.id, e)); msg.markets.forEach((m) => markets.set(m.id, m)); } if (msg.type === 'delta') { for (const c of msg.changes) { if (c.kind === 'event') c.op === 'remove' ? events.delete(c.id) : events.set(c.event.id, c.event); else c.op === 'remove' ? markets.delete(c.id) : markets.set(c.market.id, c.market); } } }); ws.on('unexpected-response', (_req, res) => { let body = ''; res.on('data', (c) => (body += c)); res.on('end', () => { console.error(`HTTP ${res.statusCode}: ${body}`); process.exit(1); }); }); ws.on('error', (e) => console.error('ws error:', e.message)); ws.on('close', () => setTimeout(() => connect(attempt + 1), Math.min(30000, 1000 * 2 ** attempt))); } connect(); This mirrors the "keep a live book" example in the PinnFeed examples, with a live-tennis filter.
The message shapes you will handle
A delta batch carries only what changed for your filters:
{ "type": "delta", "seq": 1023, "ts": 1762679412093, "changes": [ { "kind": "market", "op": "upsert", "market": { "id": "1640278226:s;0;m", "...": "..." } }, { "kind": "market", "op": "remove", "id": "1640278226:s;0;ou;2.5", "eventId": 1640278226 }, { "kind": "event", "op": "upsert", "event": { "id": 1640278226, "...": "..." } }, { "kind": "event", "op": "remove", "id": 1640270607 } ] } upsert carries the full object (replace what you have); remove carries only the id. seq is for logging, not gap detection, because filters skip batches you are not subscribed to. On any reconnect, rebuild from the fresh snapshot rather than trying to patch gaps.
When REST is enough
- You refresh a dashboard or spreadsheet every few minutes.
- You run a model on a schedule (hourly, pre-match).
- You grade bets against closing lines after the fact (
GET /v1/closing/{eventId}). - You need a one-off lookup inside a bot or an AI assistant.
- You are prototyping and want curl-friendly requests.
When you need a WebSocket
- In-play tools where a price can move several times between polls.
- Line-movement or steam alerts, where the moment of the move is the data.
- Many sports or markets at once, where polling the whole board would burn your rate limit.
- Multiple consumers that each need a consistent live book.
A hybrid is common: WebSocket for the live book, REST for history, single-event lookups and backfills.
Frequently Asked Questions
Is WebSocket faster than REST for sports odds?
Architecturally, push removes the poll interval from the delay: you get a change when it is sent, not on your next request. How much that matters in milliseconds depends on your setup, so measure it with the updatedAt/ts timestamps rather than trusting published claims.
Does polling a REST odds API every second get the same result as a WebSocket?
Only if your plan lets you, and even then you re-download unchanged markets each time. Rate limits usually cap polling first: on PinnFeed, Realtime REST allows 1 request every 5 seconds and Free is delayed by 30 seconds.
What happens if my WebSocket connection drops?
Reconnect with exponential backoff (1 s, 2 s, 4 s... capped at 30 s, plus jitter), resubscribe, and rebuild your local book from the new snapshot. Do not try to replay missed deltas.
Why does my odds WebSocket close after a minute?
Most odds sockets use heartbeats. On PinnFeed the server sends ping every 20 seconds and closes connections that stay silent for 60 seconds; reply with {"type":"pong"}. Also send subscribe within 30 seconds of connecting.
Can I use a WebSocket odds feed from the browser?
Yes, but keys in browser code are visible to users. PinnFeed accepts ?key= in the URL for browsers; use a dedicated key or proxy through your backend.
Which PinnFeed plan includes the WebSocket?
Pre + Live WebSocket (Builder, $139/mo, 3-day trial with card) and above. Free and Realtime REST ($49/mo) are REST only. See pricing.
18+ only. Educational content about software architecture for odds data; it does not promise any betting result.
Editorial note: Tools for Bettors publishes independent reviews and guides on betting tools and odds data.
