wss://api.0xarchive.io/ws, confirm each command, and reconnect without losing your subscriptions. The socket uses your 0xArchive API key, sent in the opening handshake as Authorization: Bearer $OXARCHIVE_API_KEY instead of the REST X-API-Key header. To create, store or rotate a key, see API keys and credential safety.
1
Open the socket
ws in Node.js.2
Send commands after the transport opens
3
Confirm each command
subscribed after subscribe, or replay_started after replay.4
Reconnect with backoff
After a close or network failure, reconnect with capped backoff. Resubscribe only after the new socket opens, then rebuild any state that depended on the old stream.
Message contract version
Add?version=2026-10-01 to the socket URL to receive the current message contract: subscribed and replay_started then echo the version, and Lighter replay rows use the live shapes. See Versioning. Every error message carries a stable error_code; the codes are listed on Errors.
Keep the connection alive
The server sends a WebSocket ping frame every 30 seconds and tracks pong activity. WebSocket libraries normally answer ping frames automatically. A connection with active subscriptions can be closed after 60 seconds without activity; a connection with no subscriptions has a 300-second idle window. You can also send the application command{"op":"ping"}, which receives {"type":"pong"}. The round trip it measures is your own client’s observation, not a published platform latency figure. Keep-alive has the ping loop and the full reconnect sequence.
Track connection state
Keep one state object per stream so a reconnect restores exactly what was running, and so your logs describe the same stream support sees.onopen, onmessage, onerror, and onclose:
- On close: clear the old socket’s timers, set the status to
reconnecting, and open a new socket with capped exponential backoff and jitter. Never reconnect in a tight loop. - On open: restore subscriptions from
activeSubscriptions, not from assumptions about the old stream. - On a gap: add the symbol to
unsafeSymbolsuntil the client rebuilds from a snapshot or replay checkpoint. - On every message: parse defensively. Expect acknowledgements, snapshots, updates, replay events, pongs, gap events, and errors. Keep the
messagetext of eacherrorand any request or correlation ID with the connection state.