WebSocket Connection
How to connect, stay alive, and issue commands on the 0xArchive socket.
Connection
Open one authenticated socket, answer the server heartbeat, and reuse the same session for subscriptions and replay.
Open the socket
Connect to wss://api.0xarchive.io/ws with your API key.
const ws = new WebSocket( "wss://api.0xarchive.io/ws?apiKey=0xa_your_api_key");
ws.onopen = () => { console.log("Connected to 0xArchive WebSocket");};
ws.onmessage = (event) => { const data = JSON.parse(event.data); console.log("Received:", data);};Keep-alive
The server sends ping frames every 30 seconds. Clients that do not answer within 60 seconds are disconnected.
// Send a ping to keep connection alivews.send(JSON.stringify({ op: "ping" }));
// Server responds with:// {"type": "pong"}Command model
The same socket handles subscribe, unsubscribe, replay, and keep-alive commands.
Real-time Subscriptions
subscribeSubscribe to a real-time channel
unsubscribeUnsubscribe from a channel
Historical Replay
replayStart historical replay. Use "channel" for single or "channels" (array) for multi-channel synchronized replay. All channels must be from the same exchange. Use interval for candles (1m-1w). Use granularity for lighter_orderbook.
replay.pausePause current replay
replay.resumeResume paused replay
replay.seekSeek to specific timestamp
replay.stopStop current replay
Utility
pingSend a ping to keep connection alive (server responds with pong)