WebSocket connections are long lived, but the frontend should treat disconnects as normal network events.

Reconnect Strategy

Use exponential backoff with jitter. After reconnecting, resubscribe to every active channel from frontend state.
const channels = new Set(["ticker:BTCUSDT", "kline:BTCUSDT:1m"]);
let attempt = 0;
let socket: WebSocket | undefined;

function connect() {
  socket = new WebSocket("wss://ws.poolthewool.com/ws");

  socket.addEventListener("open", () => {
    attempt = 0;

    for (const channel of channels) {
      socket?.send(
        JSON.stringify({
          type: "subscribe",
          channel,
          id: Date.now(),
        })
      );
    }
  });

  socket.addEventListener("close", () => {
    const baseDelay = Math.min(30000, 1000 * 2 ** attempt++);
    const jitter = Math.floor(Math.random() * 500);
    window.setTimeout(connect, baseDelay + jitter);
  });
}

connect();

Error Messages

Errors use the error server message type.
{
  "type": "error",
  "error": {
    "code": 4002,
    "message": "Channel not found: depth:BTCUSDT"
  },
  "id": 12,
  "timestamp": 1780816674605
}
Common error codes:
  • 4000: invalid message.
  • 4001: authentication required or not implemented.
  • 4002: channel not found.
  • 4003: subscription failed.
  • 4006: invalid parameters.
Private channels are not available through the public frontend WebSocket path today. Public market channels do not require authentication.