Authorization: Bearer $OXARCHIVE_API_KEY rather than the REST X-API-Key header. Use API keys and credential safety for creation, storage, and rotation.
1
Open the socket
2
Wait for the transport to open
3
Confirm the requested operation
subscribed after subscribe, or replay_started after replay.4
Reconnect with backoff
Reconnect after close or network failure with capped backoff. Resubscribe only after the new socket opens, then rebuild state that depended on the old stream.
Connection Setup
Connect withAuthorization: Bearer $OXARCHIVE_API_KEY in the opening handshake. The socket URL is wss://api.0xarchive.io/ws. The shell variable keeps the real credential out of the copied command. Use a server-side WebSocket library that supports custom headers. Browser clients should connect through your backend so the API key remains server-side.
Subscribe after open
Decide these before you open the socket.Keep Alive
The server sends a WebSocket ping frame every 30 seconds and tracks pong activity. A connection with active subscriptions can be closed after 60 seconds without activity; a connection with no subscriptions has a 300-second idle window. WebSocket libraries normally answer native ping frames automatically. The application{"op":"ping"} command receives {"type":"pong"} and can measure one client’s application round-trip time. Treat that as a client-side observation, not a published platform latency percentile.
Reconnect Policy
Reconnect with capped exponential backoff and jitter. Do not reconnect in a tight loop. After a new socket opens, resubscribe explicitly and rebuild any local state that depended on the previous stream. If the stream feeds a local book, replay window, alert, or model, treat the reconnect as a state transition that needs logging.Auth And Secrets
For server-side clients, sendAuthorization: Bearer $OXARCHIVE_API_KEY during the opening handshake. Load the key from the environment or application secret store, and never expose it in browser URLs, logs, telemetry, or copied prompts. Browser clients should connect through your backend.
Message Loop
Parse every message defensively. Expected classes include subscription acknowledgements, snapshots, updates, replay messages, pings or pongs, gap signals, and errors. The WebSocket error event contains a human-readablemessage; preserve it with the connection state. Preserve any request or correlation identifiers that appear in the message so a streaming issue can be tied back to the connection session.
Connection State Object
Use a local state object so reconnects and support logs describe the same stream.onopen, onmessage, onerror, and onclose. When the socket closes, clear old timers, move the status to reconnecting, open a new socket with backoff, then restore subscriptions from activeSubscriptions. If a gap arrives for a stateful channel, add the symbol to unsafeSymbols until the client rebuilds from a snapshot or replay checkpoint.