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
| Name | Type | Mandatory | Description |
|---|---|---|---|
symbol | string | Yes | Trading pair, uppercase, e.g. BTCUSDT. |
depth | enum | Yes | Number 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
| Field | Type | Description |
|---|---|---|
event | string | Always "depth". |
ts | integer | Server push time, Unix milliseconds. |
symbol | string | Trading pair, uppercase. |
lastUpdateId | integer | Monotonic update id of the snapshot. Strictly increases between consecutive messages. |
bids | array | Array of [price, qty] pairs (both strings). Sorted descending by price. Length equals the subscribed depth. |
asks | array | Array 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.