Skip to main content
WebSocket delivery is at-least-once during normal operation. On disconnect or reconnect you must rebuild subscriptions and reconcile against REST.

sid lifecycle

sids are connection-local. They are NOT preserved across:
  • Network drops
  • Client-side WebSocket.close() + reopen
  • Server-side restarts
After every reconnect, run a fresh subscribe for everything you need. Old sids from the previous connection are meaningless.

Heartbeat

Send ping every 25 seconds (or whenever your TCP connection feels quiet):
Server responds:
If you don’t get a pong within ~5 seconds, treat it as a dead connection — close and reconnect. ts is the server clock in ms. Use it as a clock-skew probe if you care about latency-sensitive timing on the client.

Reconnect strategy

After a successful reconnect-and-resubscribe, reconcile state from REST — don’t trust the WS to have replayed missed events from before the disconnect.

Channel-specific reconnect / resync

Orderbook resync

token_book deltas carry seq and prevSeq. Track the last seq you applied per tokenId. If the next delta arrives with prevSeq != lastSeq, request a fresh snapshot — without dropping the existing subscription:
If the snapshot fetch fails the server pushes { "type": "book_snapshot_failed", "data": { "tokenId", "reason", "tsMs" } } on the same sid. Back off and retry, or fall back to GET /api/markets/{symbol}/orderbook?outcome=N&depth=100. In v1 the only way to force a fresh book_snapshot was an unsubscribe + resubscribe round-trip — get_book_snapshot removes that gap.

Auth on reconnect

Auth is validated at handshake only. If a key rotates mid-session, the open socket keeps working with the original credential until it closes. Close + reopen to pick up the new one. Revoking a key closes every live socket bound to that keyId immediately via a Redis apikey:invalidate pub/sub — clients see the 4401 api_key_revoked frame within milliseconds.