WebSocket Connection

How to connect, stay alive, and issue commands on the 0xArchive socket.

Endpoint
wss://api.0xarchive.io/ws
Auth
API key on connect
Heartbeat
30s ping, 60s timeout

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.

JavaScript
// Send a ping to keep connection alive
ws.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

subscribe

Subscribe to a real-time channel

Params: channel, symbol

unsubscribe

Unsubscribe from a channel

Params: channel, symbol

Historical Replay

replay

Start 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.

Params: channel|channels, symbol, start, end, speed, [interval], [granularity]

replay.pause

Pause current replay

Params: -

replay.resume

Resume paused replay

Params: -

replay.seek

Seek to specific timestamp

Params: timestamp

replay.stop

Stop current replay

Params: -

Utility

ping

Send a ping to keep connection alive (server responds with pong)

Params: -