Skip to main content

Depth Stream

Streaming order book snapshots for a symbol.

WebSocket URL: wss://stream.pipai.io/ws

Subscription

Subscribe:

{
"op": "subscribe",
"channel": "market.depth",
"params": { "symbol": "BTCUSDT", "depth": 20 },
"req_id": "client-301"
}

Unsubscribe:

{
"op": "unsubscribe",
"channel": "market.depth",
"params": { "symbol": "BTCUSDT", "depth": 20 },
"req_id": "client-302"
}

Subscription parameters

NameTypeMandatoryDescription
symbolstringYesTrading pair, uppercase, e.g. BTCUSDT.
depthenumYesNumber of price levels per side. One of 5, 10, 20, 50, 100.

Payload

{
"event": "depth",
"ts": 1745923200412,
"symbol": "BTCUSDT",
"lastUpdateId": 9823412531,
"bids": [
["67431.90", "0.4221"],
["67431.80", "1.0312"],
["67431.50", "0.8800"],
["67431.10", "2.5410"],
["67430.90", "0.0500"]
],
"asks": [
["67432.40", "0.3110"],
["67432.60", "0.7821"],
["67432.90", "1.4422"],
["67433.20", "0.2200"],
["67433.80", "3.1100"]
]
}

Payload fields

FieldTypeDescription
eventstringAlways "depth".
tsintegerServer push time, Unix milliseconds.
symbolstringTrading pair, uppercase.
lastUpdateIdintegerMonotonic update id of the snapshot. Strictly increases between consecutive messages.
bidsarrayArray of [price, qty] pairs (both strings). Sorted descending by price. Length equals the subscribed depth.
asksarrayArray of [price, qty] pairs (both strings). Sorted ascending by price. Length equals the subscribed depth.

Update frequency

A full snapshot of the top-of-book to the subscribed depth is pushed every 100 ms. Each message replaces the previous one — this is intentionally a snapshot stream, not an incremental diff stream, so no internal book maintenance is required by the client.

Reconnection

After a reconnect and re-subscribe, the next snapshot (within ~100 ms) supplies a full, authoritative top-of-book view. Consumers who only need the visible depth do not need to bootstrap from REST. If lastUpdateId does not strictly increase between two received messages, treat the older message as stale and discard it.

Future: incremental diff stream

A market.depth.diff channel for incremental order-book diffs (with REST snapshot bootstrap) is planned for a later release. Schema and bootstrap procedure will be documented when that channel ships; until then, the snapshot channel above is the only depth stream available.