sid lifecycle
sids are connection-local. They are NOT preserved across:
- Network drops
- Client-side
WebSocket.close()+ reopen - Server-side restarts
subscribe for everything you
need. Old sids from the previous connection are meaningless.
Heartbeat
Sendping every 25 seconds (or whenever your TCP connection feels
quiet):
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
Channel-specific reconnect / resync
| Channel | On reconnect, also fetch |
|---|---|
user_activity | GET /api/orders/open + GET /api/me/balances + GET /api/me/positions |
token_trades | GET /api/markets/{symbol}/trades?before=<now> to fill the visible window |
token_book | re-subscribe → book_snapshot is pushed automatically |
condition_status | GET /api/markets/{symbol} for current status |
system | GET /api/platform/status |
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:
unsubscribe/subscribe is the only way to force a fresh
book_snapshot mid-connection — the gateway does not support an
explicit “resync” command.
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.| Reason | Close code | What to do |
|---|---|---|
api_key_revoked / api_key_bad_secret | 4401 <reason> | Rotate the key on the admin panel; don’t auto-retry a revoked key. |
api_key_expired | 4401 api_key_expired | Issue a fresh key. |
api_key_suspended | 4401 api_key_suspended | Partner is suspended. Contact ops. |
api_key_unknown_key / api_key_bad_format | 4401 <reason> | Token on disk is stale or malformed. Refresh from your secrets manager. |
api_key_ip_denied | 4401 api_key_ip_denied | Caller IP isn’t in the key’s allowlist. |
api_key_auth_disabled / api_key_auth_unconfigured | 4401 <reason> | Server-side misconfig (feature flag off or pepper missing). Back off and alert. |
forbidden origin | 1008 forbidden origin | WebSocket Origin header not in the allowlist. |
keyId
immediately via a Redis apikey:invalidate pub/sub — clients see the
4401 api_key_revoked frame within milliseconds.