Real-Time WebSocket Stream for Developers
A relay. The events of the venues covered are normalised and merged into a single output, pushed on a 100 ms tick. That is the only transformation performed: a trade goes in, a trade comes out.
It is not a source of metrics (no rolling window, no counter, no average), and there is no history: you receive what happens from your connection onwards. The past is served over REST, and to AI agents over MCP.
For an AI agent, the channel is the MCP server, not the stream: an AI agent does not keep a connection open, it asks when it needs to.
The get_pair_data MCP tool reads the order book and the latest trades of a pair on demand, and the real-time tools of the MCP server (get_live_data, get_market_snapshot, alerts) read this stream on the AI agent’s behalf, over one connection of your plan per key. The stream itself is for code that listens continuously.
#Connection
The same stream is served at wss://ws.bytnode.com/ws, its own server: same key, same channels, same frames. Use either address.
Two ways to pass the key, both checked at the handshake, before the connection opens:
- From a server: the key goes in the
X-API-KEYheader of the handshake. - From a web page: a short-lived token goes in the URL (
?token=, issued byPOST /v1/ws/token: 60 seconds, one connection).
It is the same key as for REST and the MCP server (?api_key= in the URL is still accepted).
The possible refusals, at the handshake then once the connection is open:
| Answer | What it means |
|---|---|
401 | Key or token missing, invalid, expired or already used (X-Deny-Reason: missing_api_key / invalid_api_key, and WWW-Authenticate as on REST). |
403 | Plan without the stream, which is the case of Free (X-Deny-Reason: plan_websocket). |
503 | Something else: the stream service has reached its capacity, all accounts together, or 20 connections are already open from your IP address. Retry a little later. |
Close 4003 | Once open: the connection too many against the ceiling of the plan. |
The session therefore opens already authenticated: the first message can be the subscription. The old op: auth frame is still accepted for clients written before the handshake check: on a connection already authenticated it is ignored and answers {"op": "authenticated", "authenticated_by": "handshake"}, whatever key it carries.
{"op": "auth", "api_key": "your_key"}#Subscribing
{
"op": "subscribe",
"channels": ["trades.futures.BTCUSDT", "orderbook.futures.BTCUSDT"],
"depth": 5
}Unsubscribing is symmetrical: op: unsubscribe, response op: unsubscribed.
- The response lists every active channel of the connection, sorted, not only those of the request. It is a state, not an acknowledgement.
depthapplies to the connection, not to a channel. Everysubscriberesets the depth of all the order books of the session; omitted, it falls back to 5. It is the number of price levels per side (bids and asks); accepted values: 1 to 5.- Subscription is all or nothing. If a single channel of the list is invalid, none is applied and the error says why. A partial subscription would let you believe you are receiving what you asked for. Channel names are case-insensitive:
trades.futures.btcusdtis listed back astrades.futures.BTCUSDT. - As soon as a subscription to an order book is accepted, the current state is sent immediately, without waiting for the next tick.
mode, optional on subscribe: two values.
frame(default) sends one message per frame, as described below.batchsends, at every tick, every pending frame in ONE message{"op": "batch", "frames": [...]}— fewer messages, the same frames inside.
A client in batch mode must read frames instead of skipping every message that carries op. Like depth, mode applies to the connection: every subscribe resets it, and omitted it falls back to frame.
The machine-readable description of the stream (channels, frames, control messages, close codes) is the AsyncAPI contract.
exchanges, optional on subscribe: a non-empty list of venues that restricts the channels of the request to one venue or to a basket. Accepted values: aster, binance, bitget, bybit, coinbase, cryptocom, gateio, hyperliquid, kraken, kucoin, mexc, okx.
- On
tradesandliquidations, you receive one frame per venue that had events in the tick, each carryingexchange. - On an order book, a single book merged over the venues of the basket only, carrying
exchanges. - The
subscribedresponse then carriesexchanges, an object that gives, for each filtered channel, the venues actually served (those of your list that carry it).
At most 20 order books per connection can be filtered this way. An unknown name, an empty list or one filtered book too many is an invalid_parameter error; a list of which no venue carries the channel is exchange_not_covered, and the error lists the venues that do. A subscribe without exchanges puts the channels it names back on the consolidated stream.
#The five channels
| Channel | Nature and cadence |
|---|---|
| trades.futures.<SYMBOL> | Events. At most one packet per 100 ms tick, absent if there is nothing to say. Under load packets are spaced further apart, sometimes by more than a second: a silence of a few seconds is not a stall. |
| trades.spot.<SYMBOL> | Events, same cadence. |
| liquidations.<SYMBOL> | Events, same cadence. |
| orderbook.spot.<SYMBOL> | State: the spot order book, consolidated across the spot books quoted in USDT only (a venue that lists the asset only against the dollar is absent from it). Broadcast at every tick, even without a change. |
| orderbook.futures.<SYMBOL> | State: the perpetual order book, consolidated across the perpetual venues, perpetuals quoted in USD or USDC included. Same cadence. |
Every perpetual pair of GET /v1/symbols is available on the five channels. The two stablecoins only exist in spot: they are served on trades.spot and orderbook.spot, and subscribing to their futures stream, to their perpetual order book or to their liquidations returns an explicit error, never a silently empty channel.
The channels and the plan
Each channel belongs to a market data family, the same as over REST and MCP:
- microstructure:
trades.futures,trades.spot,orderbook.spotandorderbook.futures; - derivatives:
liquidations.
A family missing from your plan is missing on every channel, stream included. Concretely: Free does not have the stream at all (403 at the handshake), and the whole stream is open on paid plans.
Real time is not the raw tick family, open on the plans with all the data, which designates the tick-by-tick history served over REST.
A channel outside the plan receives {"op": "error", "server_time": "…", "error": {"code": "plan_family", "message": "Channel 'orderbook.futures.BTCUSDT' is not in your plan: the 'microstructure' data family is not included in your subscription.", "param": "channels"}} and, as for any subscription, no channel of the frame is applied.
The number of simultaneous connections per account also depends on the plan: 3, 10, or 20. See the plans.
#Message format
Every pushed message carries three common keys.
Response fields
channelstring- The channel of origin.
server_timestring- The server tick that built the message, in ISO 8601 UTC with milliseconds — the same key and format as the REST envelope. The initial order book state carries the tick it was taken at, so it can be earlier than the subscribed before it. Every trade and every liquidation carries its own time in data.
seqinteger- Sequence number, monotonic per channel, and per channel and venue (or basket) when the channel is filtered with exchanges. Its starting value is arbitrary: do not expect 0 or 1. Only a jump between two consecutive messages signals lost messages.
Trades
{
"channel": "trades.futures.BTCUSDT",
"server_time": "2026-10-14T09:25:26.408Z",
"data": [
{ "time": "2026-10-14T09:25:26.176Z", "id": "3cf0988ca613980c", "side": "buy", "price": 83283.9, "quantity": 0.24, "value_usd": 19988.136 },
{ "time": "2026-10-14T09:25:26.184Z", "id": "4b408a64af719aa6", "side": "sell", "price": 83268.6, "quantity": 0.002, "value_usd": 166.5372 }
],
"seq": 443379
}Reading a trade frame:
sideis the side of the taker:buymeans a buyer consumed the offer.- One row is one execution: a taker order that sweeps several maker orders of the same size at the same price produces several identical rows, and that is normal.
- Trades are grouped per tick, but none is lost: each one keeps its original timestamp in
data[].time, distinct from theserver_timeof the message, and the trades of a message are sorted by that timestamp, oldest first. - That order holds within a message only: a later message can carry a trade older than the newest one already received (a venue reporting late, usually by less than a second, at times up to about 1.5 s).
To build candles, bucket on data[].time and close a period about two seconds after its end.
Each trade carries id, the same identifier as the tick of /v1/trades/futures or /v1/trades/spot for that trade (an opaque fingerprint: it names neither the venue nor its native id), and value_usd = price × quantity. Use id to deduplicate the live stream against the REST history.
Liquidations
{
"channel": "liquidations.BTCUSDT",
"server_time": "2026-10-10T09:11:51.652Z",
"data": [
{ "time": "2026-10-10T09:11:51.576Z", "price": 83168.0, "quantity": 0.081, "side": "short", "value_usd": 6736.608 }
],
"seq": 7
}Reading a liquidation frame:
sideis here the side of the liquidated position:longmeans a long position was liquidated. Not every venue has this convention; the normalisation is done for you.- As for trades, the liquidations of a message are sorted by
time. - A venue can report a liquidation a few seconds late: filter and window on
time, never on the moment of reception. - An old liquidation that a venue publishes again more than 60 s after its
timemay not be relayed (/v1/liquidations/eventskeeps every event).
Order book
{
"channel": "orderbook.futures.BTCUSDT",
"server_time": "2026-10-14T09:25:26.304Z",
"data": {
"bids": [[83271.0, 67.65684], [83270.0, 4.85424], [83269.0, 15.31266]],
"asks": [[83272.0, 17.0135], [83273.0, 11.33315], [83274.0, 5.34624]],
"avg_mid_price": 83271.75,
"avg_spread_bps": 0.036
},
"seq": 627302
}Each row is [price, quantity], the quantity being the sum of the venues at that price level. The bids are decreasing, the asks increasing. Prices are brought back to a common grid per asset, without which each venue would fall into its own buckets and the consolidated order book would have more rows, each of them thinner.
The step of that grid, in the quote currency:
| Step | Symbols |
|---|---|
| 1 | BTC |
| 0.1 | ETH, BNB, TAO, ZEC, BCH |
| 0.01 | SOL, HYPE, XMR, LTC, QNT, AAVE, ETC, VVV, DASH, BSV, ENS, COMP |
| 0.001 | LINK, UNI, GRAM, AVAX, NEAR, DOT, MORPHO, ICP, RENDER, ATOM, FIL, INJ, LIT, ZRO, CAKE, TRUMP, PENDLE, LDO, ETHFI, RAY, CVX, JTO, AR, RUNE |
| 0.0001 | XRP, TRX, SUI, XLM, ADA, USDCUSDT, USDTUSDC, ENA, ONDO, WLD, ASTER, WLFI, ARB, ALGO, POL, JUP, AERO, APT, STX, TIA, CRV, FET, VIRTUAL, GRASS, XPL, SPX, XTZ, M, MNT, PIEVERSE, KITE, IMX, OP, KAIA, BAT, SYRUP |
| 0.00001 | DOGE, HBAR, CC, SKY, JST, KAS, STABLE, AKE, NIGHT, PYTH, STRK, SEI, FF, CRO, SUN, MON, CFX, GRT, KMNO, JASMY |
| 0.000001 | PUMP, VET, PENGU |
| 0.00000001 | SHIB, PEPE, LUNC |
There is one order book per market: orderbook.spot merges only the spot books, orderbook.futures only the perpetual books. The two are never mixed, since their prices differ by the basis.
Within a market, a venue whose mid-price strays more than 5 basis points from the median of the others (when at least three venues are present) is left out of the merge until it comes back in line: an isolated venue cannot distort the consolidated book.
#Things to know
The consolidated order book is a depth, not one venue's book
Between several venues of the same market there is no common matching engine: their mid-prices differ by a few basis points, while one venue's bid/ask spread on BTC is about 0.1 basis point. Summed at their raw prices, their levels crossed the consolidated book in virtually every message.
Since 2026-10-08, each venue is re-centred on avg_mid_price before the merge: all its levels are shifted by avg_mid_price minus its own mid-price. Quantities are untouched, the distance of each level to its venue's mid is kept, and the consolidated book is never crossed: bids[0][0] is always below asks[0][0]. A venue that has only one side of its book at that moment does not contribute.
The number of trades does not measure activity
Some venues split their executions to the extreme, down to orders of one satoshi, a fraction of a cent. In the consolidated stream, the number of trades is therefore dominated by tiny executions. To measure activity, sum quantity or quantity × price, never count the rows.
A jump in seq means you have lost messages
The send queue of each client holds about eight ticks at full load (800 ms of absorbable jolt). A client that does not consume fast enough sees its oldest messages dropped; it degrades on its own, without affecting the others.
On the event channels, a dropped message is definitively lost; the jump in seq is what tells you. On the order book, only the last state is kept: a jump there has no consequence, the next state entirely replaces the previous one.
The credential is checked at the handshake, not in a frame
The key (or the token) is checked at the handshake, before the connection opens: a plan that does not include the stream receives a 403 and nothing is established. From a server it travels in the X-API-KEY header; a browser, which cannot set a header on a WebSocket, uses a short-lived token in the URL (?token=), so that the key itself never leaves your server.
The {"op": "auth"} frame is still accepted and answers authenticated, but it is no longer necessary: the session opens already authenticated. ?token= and ?api_key= are only accepted on the WebSocket handshake, never on the REST routes, and the request line of /ws is not logged by the gateway.
The number of simultaneous connections depends on the plan
Every plan bounds the number of connections open at the same time, for the whole account, all keys together. The connection too many is closed at once with code 4003 and the ceiling in the reason. Do not confuse it with a 503 at the handshake, which says that the service itself is full, whatever the plan, or that 20 connections are already open from your IP address.
A disconnection immediately frees its slot: there is nothing to wait for and nothing to reset.
Without exchanges, the stream names no venue
Without exchanges, no message says which venue a trade, a liquidation or a level of the order book comes from, nor how many venues fed it: the stream serves the consolidated market. With exchanges, event frames carry exchange and order books exchanges.
A venue silent for more than ten seconds leaves the order book automatically, and a venue with an empty order book is never merged into it.
#Limits and closures
| Limit | When exceeded |
|---|---|
| Key or token missing, invalid or already used | 401 at the handshake, X-Deny-Reason: missing_api_key / invalid_api_key |
| Stream missing from the plan (Free) | 403 at the handshake, X-Deny-Reason: plan_websocket |
| Simultaneous connections per account: 3, 10, or 20 | close 4003, the ceiling in the reason |
| Capacity of the stream service, all accounts together, or 20 connections open from one IP address | 503 at the handshake, retry later |
| Channel of a family outside the plan | op: error, no channel of the frame is applied |
| Openings: 1 per second, burst of 10 | 429 at the handshake |
| Send queue of about eight ticks at full load | the oldest ones dropped, seq jumps |
| 10 overflows in a row tolerated | close 4005, reason “client too slow” |
| depth between 1 and 5 | error, the subscription is not applied |
| Close code | Reason |
|---|---|
| 4003 (ceiling) | The plan’s ceiling on simultaneous connections reached, for the whole account. A disconnection frees its slot at once. |
| 4005 (client too slow) | Queue saturated for a sustained period. A client that loses eight hundred milliseconds of stream ten times in a row will not catch up. |
| 4008 | More than 20 messages per second sent by the client: control messages are rate-limited per connection. |
| 4010 | Session expired: a connection is closed after 6 hours; reconnect and subscribe again (the key and plan are checked again). |
| 1011 | Keepalive ping timeout: the server pings every 20 seconds and closes when no pong comes back within 20 seconds. Client libraries answer on their own; reconnect. |
| 4001 | No longer sent in practice: the key is checked at the handshake (401), and an auth frame on an open session answers authenticated. |
| 4002 | Session never authenticated within 5 s. Residual, since the key is checked at the handshake. |
Every impossible request receives a named error, never a silence, and the error says what was expected:
- unknown symbol;
- unknown channel;
- futures market asked for on a stablecoin;
depthout of bounds;- subscription before authentication;
- unreadable message;
- venue unknown in
exchanges(invalid_parameter) or carrying none of the channels (exchange_not_covered).
An error frame has the parts of a REST error: {"op": "error", "server_time": …, "error": {"code": …, "message": …, "param": …, "details": …}'}, param being the field of your message at fault. Every control frame (subscribed, unsubscribed, authenticated) carries server_time, and {"op": "ping"} answers {"op": "pong", "server_time": …}.
#Reconnecting
A connection can drop (a deployment, the network). To come back:
- Reconnect with a growing wait (0.5 s, doubled up to 30 s, with a random part).
- Send your
subscribeagain: subscriptions do not survive the connection. - Take the first message after a reconnection as a new start:
seqcontinues across reconnections while the service runs, but restarts from an arbitrary value when it restarts. - On a plan with individual trades, read back the trades missed in between on
/v1/trades/spotor/v1/trades/futureswithsince_ms: each carries the sameidas on the stream, deduplicate on it.
The SDKs reconnect and subscribe again for you.
#Full example
import asyncio
import json
import os
import websockets # pip install websockets
async def main() -> None:
# From a server, the key goes in the X-API-KEY header, checked at the
# handshake: the session opens already authenticated. A refused key gets 401
# before it opens, a plan without the stream 403, a service at capacity 503
# (InvalidStatus on the websockets side). In a web page: ?token= instead.
headers = {"X-API-KEY": os.environ["BYTNODE_API_KEY"]}
async with websockets.connect("wss://api.bytnode.com/ws", additional_headers=headers) as ws:
await ws.send(json.dumps({
"op": "subscribe",
"channels": ["trades.futures.BTCUSDT", "orderbook.futures.BTCUSDT"],
"depth": 5,
}))
print(await ws.recv())
expected: dict[str, int] = {}
async for raw in ws:
msg = json.loads(raw)
if "op" in msg: # a control message (error, pong...), not data
print(msg)
continue
channel, seq = msg["channel"], msg["seq"]
# seq runs per channel, and per channel + venue (or basket) when the
# channel is filtered with "exchanges": key the counter on both.
key = channel + "#" + (msg.get("exchange") or ",".join(msg.get("exchanges", [])))
# The first seq of a key is arbitrary: only a jump between two
# messages counts. It signals lost messages: the client is not
# consuming fast enough.
if key in expected and seq != expected[key]:
print(f"!! {seq - expected[key]} message(s) lost on {key}")
expected[key] = seq + 1
if channel.startswith("orderbook."):
# The book is a consolidated depth centred on avg_mid_price, not one
# venue's book: use the per-venue average spread to trade.
spread = msg["data"]["avg_spread_bps"]
if spread is not None:
print(f"{channel} mid={msg['data']['avg_mid_price']} spread={spread:.3f} bps")
else:
print(f"{channel} {len(msg['data'])} event(s)")
asyncio.run(main())To write this client with an AI coding agent, the bytnode-realtime-stream Agent Skill teaches it this page: browser tokens, live candles from trades, lost messages and reconnection.