Orderbook manage
How to manage a local order book correctly
The full-depth channel depth@<symbol> follows a subscribe-time snapshot + delta model (Bybit style). You no longer pull a REST snapshot or align on the matching-engine updateId.
All frames use the unified envelope {ch, event, data}. Dispatch on ch = depth_update; the fields below (type, u, pu, b, a) live inside data.
1.Subscribe to depth@btc_usdt.
2.The first frame is a snapshot (data.type = snapshot): replace your whole local book and record lastU = data.u.
3.For each following delta (data.type = delta): if data.pu == lastU, apply the levels one by one and set lastU = data.u; otherwise discard the local book and re-subscribe (or wait for the server to actively re-push a snapshot).
4.Each level is the absolute quantity for a price level; a level whose quantity is "0" is removed, otherwise upsert.
5.The server re-pushes a snapshot on restart / when the client falls behind, so a broken sequence self-heals on the next snapshot.
Note: data.u here is the push local sequence (per-symbol monotonic +1), which is a different source from the fixed-level depth channels (depth5|depth10|depth20|depth50|depth100@<symbol>, ch = depth) where data.id is the matching updateId (a string). Do not mix the two.