type, and lifecycle events, connection-level signals the
client raises itself. How you receive them is the one place the two SDKs differ
in shape.
on returns an unsubscribe function. Call it to remove that
handler:
Server frames
Every frame carriestype, a v version, and a server timestamp
(serverTimestamp in TypeScript, server_timestamp in Python). The table lists
the additional fields you’ll use most; the WebSocket API’s
Message catalog documents each frame in full.
Field names are camelCase on the wire and in TypeScript, and snake_case on the
Python models:
subscriptionId is subscription_id, snapshotPending is
snapshot_pending.
A few notes:
SNAPSHOT/DELTAare the orderbook. Apply the snapshot first, then each delta (a change withsize0 deletes that price level).seqis a per-subscription monotonic counter for detecting gaps. See Orderbook channel.statusreportsLIVE,RESYNCING,CLOSED,UNSUPPORTED, orUNAVAILABLE. When the server retires a subscription (CLOSED/UNSUPPORTED) the client drops it from its resubscribe set so it isn’t replayed on reconnect.ERRORframes raised during subscription creation carry themarketandchannelthat failed (there’s no subscription id yet); the client prunes that market so it won’t be retried on reconnect. That pruning is bymarket, not bycode, so a market refused withMARKET_NOT_YET_OPENis dropped from the resubscribe set too: the client will not pick it up on its own once the book opens, and you subscribe again when the event is close to starting. See Errors for thecodevalues.GOODBYEprecedes a close. Some reasons are terminal. See Reconnection & lifecycle.
Lifecycle events
These are raised by the client, not sent by the server. They are distinct from the server’sERROR and GOODBYE frames, and the two SDKs expose a different
set.
TypeScript raises five through the same on surface:
Python takes three callbacks on the constructor, because a lifecycle event
describes the connection rather than the market and so does not belong in a
stream of market frames:
OPEN, CLOSE or SOCKET_ERROR equivalent. A socket that closes
and reconnects is reported through on_reconnecting; one that will not come
back ends the iteration, and on_terminated says why.
Python also reports a terminal failure by raising from the loop, so a
try/except around async for catches what on_terminated reports: