Messages are JSON objects. Client messages may include an id so the frontend can match acknowledgements and errors to a request.

Client Messages

Subscribe

{
  "type": "subscribe",
  "channel": "ticker:BTCUSDT",
  "id": 1
}

Unsubscribe

{
  "type": "unsubscribe",
  "channel": "ticker:BTCUSDT",
  "id": 2
}

Ping

{
  "type": "ping",
  "id": 3
}

Server Messages

Subscribed

{
  "type": "subscribed",
  "channel": "ticker:BTCUSDT",
  "id": 1,
  "timestamp": 1780816696007
}

Data

{
  "type": "data",
  "channel": "ticker:BTCUSDT",
  "data": {
    "symbol": "BTCUSDT",
    "last_price": "98517.02"
  },
  "timestamp": 1780816700011
}

Error

{
  "type": "error",
  "error": {
    "code": 4006,
    "message": "invalid interval: 7m"
  },
  "id": 4,
  "timestamp": 1780816700011
}

Batched Frames

The server writer can place multiple JSON messages in a single WebSocket text frame separated by newlines. Always split incoming text frames by \n before parsing.