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:
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:
- Open WebSocket with
?last_seq=. - Wait for
connected. - Re-send the exact same
scope.setyou had before — server state does not persist across sockets. - Process events; advance your stored
last_seqonly after each event is durable in your system.
Hydration after long gaps
Whenresume 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 with4002 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. Acceptpermessage-deflateif your client offers it. Neither changes how you authenticate. - Put
accountsandriskon their own connection so a fill burst cannot close the stream you must not miss. - For the largest firms, open several connections with
partition(countup to 64). Events for one account stay on one connection. - You can
conflatebalances,positions, andstats. Fills, orders, trades, accounts, and risk are never conflated. - Persist
last_seqas you go so a4002reconnect is a short replay.
Suggested backoff
Never retry
4001 without first re-validating credentials — a tight loop will rate-limit your firm key.
