WebSocket odds API stream

WebSocket odds API guide: subscribe to leagues and events, receive a snapshot then sequence-numbered deltas, detect gaps and resync, with code samples.

The stream pushes every price change to you over a single WebSocket. Subscribe to leagues or events, receive a full snapshot, then deltas containing only the markets that changed. It is part of the Syndicate plan (10 concurrent connections), together with live in-play odds.

Endpoint
wss://api.preciseapi.com/v1/stream

Connecting

Authenticate with the Authorization header. Where your client can't set headers (browsers), send {"type":"auth","api_key":"…"} as the first message within 5 seconds (token works in place of api_key). Keys in the URL (?api_key=) are refused, because URLs are written to proxy and browser logs. Billing is one credit when the connection opens and one per minute while it stays open.

import WebSocket from 'ws'; // npm i ws

const ws = new WebSocket('wss://api.preciseapi.com/v1/stream', {
  headers: { Authorization: `Bearer ${process.env.PRECISEAPI_KEY}` },
});

let lastSeq = 0;
ws.on('open', () => {
  ws.send(JSON.stringify({"type":"subscribe","leagues":["nba"],"markets":["moneyline","spread","total"]}));
});

ws.on('message', (raw) => {
  const msg = JSON.parse(raw);
  // Heartbeats repeat the latest seq; every other message advances it by one.
  const expected = msg.type === 'heartbeat' ? lastSeq : lastSeq + 1;
  if (msg.seq && lastSeq !== 0 && msg.seq !== expected) {
    ws.send(JSON.stringify({ type: 'resync' })); // gap detected
  }
  if (msg.seq) lastSeq = msg.seq;

  if (msg.type === 'snapshot') console.log('events:', msg.data.length);
  if (msg.type === 'delta') {
    for (const { event_id, book, market } of msg.changes) {
      console.log(event_id, book, market.key, market.outcomes.map((o) => o.price));
    }
  }
});

Subscribing

Send a subscribe message. Every field except one of leagues / event_ids is optional.

Client → server
{
  "type": "subscribe",
  "leagues": [
    "nba",
    "nfl"
  ],
  "event_ids": [],
  "books": [
    "pinnacle",
    "draftkings",
    "fanduel"
  ],
  "markets": [
    "moneyline",
    "spread",
    "total"
  ],
  "periods": [
    "full_game"
  ]
}
FieldDefaultDescription
leagues—League ids to follow.
event_ids—Specific events (max 200). Overrides leagues.
booksallSource ids to include.
marketsmoneyline, spread, totalMarket keys, or the shortcuts main, props and all as on REST. Include player_* keys to stream props.
periodsfull_gamePeriods to include.
max_source_age_ms—Only quotes the source confirmed within this many milliseconds (1 to 300000). A quote that ages past it is removed with reason source_expired. Such a subscription can cover at most 100,000 markets.
state—Use a destination code from the book’s deep_link_regions, e.g. "nj". Snapshots and deltas carry the regional selection link.

Sending a new subscribe replaces the previous subscription. Other client messages: {"type":"unsubscribe"}, {"type":"resync"} and {"type":"ping"}.

Limits per connection: 30 client messages per 10 seconds (more closes the socket with 1008), and one subscribe or resync per second; per account, 12 subscribes or resyncs a minute across all its sockets. A refused subscribe costs nothing and keeps the previous subscription.

Server messages

typeWhen
welcomeOn connect: connection_id, plan, credits_remaining, heartbeat_ms and billing.
subscribedEchoes the normalized subscription (shortcuts expanded into market keys).
unsubscribedAnswers unsubscribe. Nothing more is sent until you subscribe again.
snapshotFull state for the subscription — every subscribed event, with or without prices, same shape as /v1/odds — with snapshot_id, part, last, events_total and version (every change up to it is in the snapshot). Large snapshots continue in snapshot_part frames.
snapshot_partThe rest of a large snapshot, about 5,000 markets per frame, with the same snapshot_id. The last frame has last: true; no delta is sent before it.
deltaChanged markets (changes) and removed markets (removed, each with a reason), batched every 250 ms.
eventA new event, or a change to its status, score, score status, clock or kickoff, including a clock going stale (clock: null). Sent before the first delta that names an event you haven't been sent. See Live scores & game clock.
event_removedAn event left the board (six hours after it ended, or dropped as abandoned, expired or never posted): data holds event_id, league and reason. Forget it if you keep your own board. It has no sequence number, so it never opens a gap.
heartbeatEvery 15 s with the current sequence number.
pongAnswers ping, with ts.
reconnectThe server is restarting. The socket closes with 1012 next; reconnect after retry_after_ms and subscribe again.
errorcode and message; the connection stays open unless the error is fatal. Codes below.

Stream error codes

invalid_subscriptionUnknown league, book, market or period, a bad max_source_age_ms, or resync before any subscribe. The connection stays open.
invalid_messageThe message isn't a JSON object. The connection stays open.
unknown_typeA message type the server doesn't know. The connection stays open.
rate_limitedMore than one subscribe or resync a second, or 12 a minute per account. The connection stays open; try again later.
too_many_messagesMore than 30 messages in 10 seconds. Closed with 1008.
subscription_too_broadA max_source_age_ms subscription matched more than 100,000 markets. Closed with 1008; narrow the filters.
heartbeat_timeoutNo pong or message for 35 seconds. Closed with 4000.
too_many_connectionsOver your plan's concurrent connections, or too many connection attempts from one address. Closed with 4029.
slow_consumerYour client fell more than 16 MB behind. Closed with 4008.
internal_errorThe snapshot couldn't be built. Send resync.
REST auth and plan codesmissing_api_key, invalid_api_key, account_inactive (4001), insufficient_credits, key_credit_cap (4002), plan_feature_unavailable, key_scope, ip_not_allowed (4003): see Errors.
delta
{
  "type": "delta",
  "seq": 42,
  "ts": "2026-10-14T01:02:03.250Z",
  "changes": [
    {
      "event_id": "evt_0uuc6p2dsqa",
      "book": "draftkings",
      "market": {
        "id": "mkt_14r1od1l1vw",
        "key": "moneyline",
        "period": "full_game",
        "outcomes": [
          {
            "id": "sel_2d3ja0zugwd",
            "name": "Phoenix Suns",
            "side": "home",
            "price": -230
          },
          {
            "id": "sel_1pojklgy6cc",
            "name": "San Antonio Spurs",
            "side": "away",
            "price": 180
          }
        ],
        "suspended": false,
        "updated_at": "2026-10-14T23:33:15.863Z"
      }
    }
  ],
  "removed": []
}

Removal reasons

source_droppedThe source stopped listing the market. While its game hasn't finished, the market is first sent as suspended for 150 seconds (books leave a market out of their feed while it is suspended): if the source lists it again in that time, it reopens without being removed.
line_movedThe source's main spread or total moved, or a pick'em app replaced a player's line with another; the new line arrives in the same or an earlier delta. A pick'em line that moves back is listed again as a new change, with new clocks.
expiredThe market was suspended and nothing re-sent or confirmed it for 5 minutes, or the source hasn't sent it for 30 minutes.
promotion_expiredA DFS promotion ended.
closedThe event finished and left the feed.
settledThe source settled the market.
event_mergedThe event was another id for a game the feed already had. merged_into names that game; its markets follow under that id.
player_mergedBooks spelled one player of the game two ways ("Kenny" and "Kenneth Gainwell"): the market follows in the same delta under the player id most books use, or, when one book lists both spellings at one line, back under its own.
source_expiredOnly with max_source_age_ms: the quote is older than you asked for.

Sequence numbers and gaps

Every message carries a per-connection seq that increases by exactly one. If you see a jump, you missed a message — send resync to receive a fresh snapshot. After a disconnect, reconnect with exponential backoff and subscribe again.

Versions

seq orders one connection's messages; version orders the states of a market across REST, snapshots and the stream. A REST answer is built and written over a moment while the stream goes on, so a REST copy of a market can be older than one the stream already sent. Keep, per market id, the copy with the highest version; ignore a copy whose version is not above one you hold, and once a removal arrives, ignore copies of that market id with a lower version than the removal's. Removals carry their version on the stream; a market a REST answer's filters cover but that it doesn't list, while its meta.version is above the version you hold for that market, has been removed.

Close codes

4001Authentication failed (missing, invalid or revoked key), or the account isn't active.
4002Insufficient credits.
4003Streaming is not included in your plan, the key is limited to REST (key_scope), or the address is outside the key's IP allowlist.
4029Too many concurrent connections for your plan.
4000No pong or message for two heartbeats (35 s). Reconnect and resync.
4008Your client fell more than 16 MB behind reading the stream. Reconnect, and narrow the subscription or read faster.
1008Policy: more than 30 messages in 10 seconds, or a freshness subscription over 100,000 markets.
1012The server is restarting (sent after a reconnect message). Reconnect.
1013Maintenance.

Previous: Versioning · Next: Webhooks & alerts