subscribeSubscribe to a real-time channel
Send
{ "op": "subscribe", "channel": "orderbook", "symbol": "BTC"}Receive
{ "type": "subscribed", "channel": "orderbook", "symbol": "BTC"}How to connect, stay alive, and issue commands on the 0xArchive socket.
Open one authenticated socket, answer the server heartbeat, and reuse the same session for subscriptions and replay.
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);};import asyncioimport websocketsimport json
async def connect(): uri = "wss://api.0xarchive.io/ws?apiKey=0xa_your_api_key" async with websockets.connect(uri) as ws: print("Connected to 0xArchive WebSocket") async for message in ws: data = json.loads(message) print("Received:", data)
asyncio.run(connect())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"}The same socket handles subscribe, unsubscribe, replay, and keep-alive commands.
Real-time Subscriptions
subscribeSubscribe to a real-time channel
Send
{ "op": "subscribe", "channel": "orderbook", "symbol": "BTC"}Receive
{ "type": "subscribed", "channel": "orderbook", "symbol": "BTC"}unsubscribeUnsubscribe from a channel
Send
{ "op": "unsubscribe", "channel": "orderbook", "symbol": "BTC"}Receive
{ "type": "unsubscribed", "channel": "orderbook", "symbol": "BTC"}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.
Send
{ "op": "replay", "channel": "trades", "symbol": "BTC", "start": 1704067200000, "end": 1704153600000, "speed": 10}Receive
{ "type": "replay_started", "replay_id": "rpl_abc123", "channel": "trades", "symbol": "BTC", "speed": 10}replay.pausePause current replay
Send
{ "op": "replay.pause"}Receive
{ "type": "replay_paused", "replay_id": "rpl_abc123"}replay.resumeResume paused replay
Send
{ "op": "replay.resume"}Receive
{ "type": "replay_resumed", "replay_id": "rpl_abc123"}replay.seekSeek to specific timestamp
Send
{ "op": "replay.seek", "timestamp": 1704100000000}Receive
{ "type": "replay_seeked", "replay_id": "rpl_abc123", "timestamp": 1704100000000}replay.stopStop current replay
Send
{ "op": "replay.stop"}Receive
{ "type": "replay_stopped", "replay_id": "rpl_abc123"}Utility
pingSend a ping to keep connection alive (server responds with pong)
Send
{ "op": "ping"}Receive
{ "type": "pong", "timestamp": "2026-01-01T12:00:00Z"}