WebSocket

Subscribing

Subscribe to channels, manage subscriptions, and configure Brotli compression.

Subscribe to one or more channels using the public/subscribe method. All WebSocket subscriptions share this format. Before subscribing, connect to the endpoint family that matches your channels:

  • Use a book connection (/ws) for BLOCK_BOOK_SNAPSHOT
  • Use a nonbook connection (/nonbook/ws) for every other channel If you need both channel families, maintain one connection to each.

Subscribe

JSON
{
  "jsonrpc": "2.0",
  "id": 0,
  "method": "public/subscribe",
  "params": {
    "channels": [
      {
        "type": "TRADE_AGG",
        "exchange": "BINANCE_FUTURES",
        "symbol": "BTCUSDT",
        "category": "*",
        "batchInterval": "200ms"
      }
    ],
    "compression": "brotli",
    "version": "v2"
  }
}

Request parameters

FieldTypeRequiredDescription
jsonrpcstringYesJSON-RPC version. Always "2.0".
idintYesRequest ID. Must be unique across the lifetime of the connection. Echoed back in responses for correlation.
methodstringYespublic/subscribe, public/unsubscribe, or public/unsubscribe_all.
params.channelsChannel[]YesChannels to subscribe to.
params.compressionstringNoMessage compression. Use brotli for compressed JSON payloads.
params.versionstringNoProtocol version. Use v2 for metadata support.

Channel parameters

Every channel object requires these fields. Individual channel types accept additional type-specific parameters -- see their respective pages.

ParameterTypeRequiredDescription
typestringYesData type (e.g., TRADE, TRADE_AGG, BLOCK_BOOK_SNAPSHOT).
exchangestringYesExchange to subscribe to. Use * for all exchanges.
symbolstringYesSymbol selector. For per-symbol subscriptions, use the exchange-native rawSymbol such as BTCUSDT. For coin-aggregated subscriptions on supported channels, pass the coin identifier such as BTC.
categorystringNoMarket class filter. Use SPOT for spot markets or PERPETUAL for perpetual derivatives. Default: * (all categories).
quotestringNoQuote denomination: USD, COIN, or DEFAULT.

Unsubscribe

Unsubscribe from specific channels:

JSON
{
  "jsonrpc": "2.0",
  "method": "public/unsubscribe",
  "params": {
    "channels": [
      {
        "type": "TRADE_AGG",
        "exchange": "BINANCE_FUTURES",
        "symbol": "BTCUSDT"
      }
    ]
  }
}

Or unsubscribe from everything:

JSON
{
  "jsonrpc": "2.0",
  "method": "public/unsubscribe_all",
  "params": {}
}

Compression

When you set compression to "brotli" in your subscription, the server compresses all data messages. Your client must decompress incoming messages before parsing them.

Compression applies to data messages only -- heartbeat pong responses are not compressed.