Connect to TheRundown WebSocket feeds for real-time odds updates and live market data.
TheRundown provides WebSocket endpoints for real-time data delivery. Instead of polling REST endpoints, open a persistent connection and receive updates as they happen. WebSocket connections do not count against your REST API rate limit.
The Hedge WebSocket delivers pre-computed hedge and arbitrage opportunities. These are pairs (or sets) of bets across different sportsbooks that guarantee a profit or minimize risk.
All WebSocket endpoints send periodic heartbeat messages to keep the connection alive. Your client must handle these to avoid treating them as data updates.
let lastHeartbeat = Date.now();ws.onmessage = (event) => { const data = JSON.parse(event.data); if (data.meta?.type === "heartbeat") { lastHeartbeat = Date.now(); return; // Do not process as data } // Process actual data update handleUpdate(data);};// Monitor heartbeat healthsetInterval(() => { const elapsed = Date.now() - lastHeartbeat; if (elapsed > 60_000) { console.warn("No heartbeat in 60s, reconnecting..."); ws.close(); // Trigger reconnection logic }}, 10_000);
Exponential backoff — start at 1 second, double on each failure, cap at 30 seconds.
Add jitter — randomize the delay slightly to avoid thundering herd reconnections.
Reset backoff on success — once a connection is established and receives data, reset the delay to 1 second.
Refetch REST state after reconnect — you may have missed updates during the disconnection. Fetch the latest state from the REST API to ensure consistency.
Always specify sport_ids and market_ids in your WebSocket URL. Receiving updates for all sports and markets generates significant traffic that your client may not need.
Process messages asynchronously
Do not block the WebSocket message handler with slow operations (database writes, API calls). Queue updates and process them in a separate thread or task.
Use the REST API as source of truth after reconnection
After a reconnect, fetch the latest state from the REST API to fill any gaps. WebSocket updates are incremental — if you miss one, your state may be stale.
Monitor connection health
Track heartbeat intervals and reconnection frequency. Alert if the connection drops repeatedly, which may indicate a network issue or an invalid API key.