Skip to main content
The Realtime WebSocket is designed for long-lived connections. Plan for transient disconnects on every deploy boundary and for occasional backpressure-driven disconnects under load.

Close codes

In addition to application ping/pong, the server emits standard WebSocket control ping frames roughly every 30 seconds.

Replay with last_seq

Persist the highest seq you have fully processed (not just received). On reconnect, supply it as a query parameter:
After you re-send scope.set, read resume on scope.confirmed: seq is the sequence of the shared FIRM_EVENTS stream. Other firms’ events sit in the same stream, so your numbers jump. Store the highest seq you have processed. Do not treat a hole as a missed event. stream_seq on scope.confirmed is the stream head at confirm time, not your cursor. The stream keeps events for about 24 hours for other consumers. The socket will not replay that whole day. A few minutes offline is already a gap. When reconnecting:
  1. Open WebSocket with ?last_seq=.
  2. Wait for connected.
  3. Re-send the exact same scope.set you had before — server state does not persist across sockets.
  4. Process events; advance your stored last_seq only after each event is durable in your system.

Hydration after long gaps

When resume is gap, or it is your first connect, run HTTP reads in parallel with the live tail. Recommended order:

Backpressure

If your consumer cannot keep up, the server closes the socket with 4002 on the first overflow. It does not silently drop events. To stay connected while watching a whole firm:
  • Read and queue. Do not do synchronous HTTP or database work on the socket read loop.
  • Open with ?format=batch. Accept permessage-deflate if your client offers it. Neither changes how you authenticate.
  • Put accounts and risk on their own connection so a fill burst cannot close the stream you must not miss.
  • For the largest firms, open several connections with partition (count up to 64). Events for one account stay on one connection.
  • You can conflate balances, positions, and stats. Fills, orders, trades, accounts, and risk are never conflated.
  • Persist last_seq as you go so a 4002 reconnect is a short replay.

Suggested backoff

Never retry 4001 without first re-validating credentials — a tight loop will rate-limit your firm key.