WebSocket Subscriptions

Subscribe to real-time data channels for market data, orderbook updates, trades, and account events.

Subscribe

{ "method": "subscribe", "subscription": { "type": "...", ... } }

Unsubscribe

{ "method": "unsubscribe", "subscription": { "type": "...", ... } }

The unsubscribe message must match the original subscription exactly.


Public Channels

All Mid Prices

Streams mid price updates for all markets whenever any price changes.

{ "method": "subscribe", "subscription": { "type": "allMids" } }

Message format:

{
  "channel": "allMids",
  "data": {
    "mids": { "BTC": "67432.5", "ETH": "3521.2", "SOL": "142.8" }
  }
}

L2 Order Book

Streams L2 orderbook snapshots and incremental updates for a specific market.

{ "method": "subscribe", "subscription": { "type": "l2Book", "coin": "BTC" } }

Message format:

{
  "channel": "l2Book",
  "data": {
    "coin": "BTC",
    "levels": [
      [{ "px": "67430.0", "sz": "1.50000", "n": 3 }],
      [{ "px": "67435.0", "sz": "0.50000", "n": 2 }]
    ],
    "time": 1700000000000
  }
}

The levels array contains [bids, asks]. Each level has:

FieldTypeDescription
pxstringPrice level
szstringTotal size at this level
nintNumber of orders

Trades

Streams real-time trade events for a specific market.

{ "method": "subscribe", "subscription": { "type": "trades", "coin": "BTC" } }

Message format:

{
  "channel": "trades",
  "data": [
    {
      "coin": "BTC",
      "side": "B",
      "px": "67432.0",
      "sz": "0.01000",
      "hash": "0xabc...",
      "time": 1700000000000
    }
  ]
}
FieldTypeDescription
coinstringMarket symbol
sidestring"B" (buy) or "A" (sell) — taker side
pxstringTrade price
szstringTrade size
hashstringTransaction hash
timeintTrade timestamp (ms)

Candles

Streams live candlestick updates.

{
  "method": "subscribe",
  "subscription": { "type": "candle", "coin": "BTC", "interval": "1m" }
}

Supported intervals: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 8h, 12h, 1d, 3d, 1w

Message format:

{
  "channel": "candle",
  "data": {
    "t": 1700000000000,
    "T": 1700000060000,
    "s": "BTC",
    "i": "1m",
    "o": "67430.0",
    "c": "67435.0",
    "h": "67440.0",
    "l": "67425.0",
    "v": "12.50000",
    "n": 42
  }
}

Best Bid/Offer (BBO)

Streams best bid and best offer updates. Lower bandwidth than the full L2 book.

{ "method": "subscribe", "subscription": { "type": "bbo", "coin": "BTC" } }

Message format:

{
  "channel": "bbo",
  "data": {
    "coin": "BTC",
    "bestBid": { "px": "67430.0", "sz": "1.50000" },
    "bestAsk": { "px": "67435.0", "sz": "0.50000" },
    "time": 1700000000000
  }
}

Active Asset Context

Streams asset context updates including funding rate, open interest, and mark price.

{ "method": "subscribe", "subscription": { "type": "activeAssetCtx", "coin": "BTC" } }

Message format:

{
  "channel": "activeAssetCtx",
  "data": {
    "coin": "BTC",
    "ctx": {
      "funding": "0.0001",
      "openInterest": "1250.00",
      "markPx": "67432.5",
      "oraclePx": "67430.0"
    }
  }
}

User Channels

User channels require the user’s Ethereum address. No signature is needed for subscriptions — the data is associated with a public address.

User Events

Streams account events including order fills, liquidations, and funding payments.

{ "method": "subscribe", "subscription": { "type": "userEvents", "user": "0x..." } }

User Fills

Streams real-time fill notifications for the specified user.

{ "method": "subscribe", "subscription": { "type": "userFills", "user": "0x..." } }

Message format:

{
  "channel": "userFills",
  "data": {
    "user": "0x...",
    "fills": [
      {
        "coin": "BTC",
        "px": "67432.0",
        "sz": "0.01000",
        "side": "B",
        "time": 1700000000000,
        "oid": 12345,
        "closedPnl": "0.00",
        "crossed": true
      }
    ]
  }
}

Order Updates

Streams order status change notifications (placed, filled, cancelled, etc.).

{ "method": "subscribe", "subscription": { "type": "orderUpdates", "user": "0x..." } }

Message format:

{
  "channel": "orderUpdates",
  "data": [
    {
      "order": {
        "coin": "BTC",
        "oid": 12345,
        "side": "B",
        "limitPx": "67000.0",
        "sz": "0.01000",
        "timestamp": 1700000000000
      },
      "status": "filled",
      "statusTimestamp": 1700000001000
    }
  ]
}

User Funding Payments

Streams funding payment notifications.

{ "method": "subscribe", "subscription": { "type": "userFundings", "user": "0x..." } }

Channel Limits

A single WebSocket connection supports up to 100 active subscriptions. If you need more channels, open additional connections.

Multiple Subscriptions

Send multiple subscribe messages on the same connection:

const subscriptions = [
  { type: "l2Book", coin: "BTC" },
  { type: "l2Book", coin: "ETH" },
  { type: "trades", coin: "BTC" },
  { type: "userFills", user: "0x..." },
];
 
for (const sub of subscriptions) {
  ws.send(JSON.stringify({ method: "subscribe", subscription: sub }));
}

Initial Snapshot

Some channels (such as l2Book) send a full snapshot as the first message after subscribing, followed by incremental updates. Rebuild your local state from the snapshot and apply subsequent deltas.