How to manage a local order book?

Hi,

I’m following
How to manage a local order book correctly – Binance API Documentation (binance-docs.github.io) to manage a local order book, but still confused about the doc

  1. step 3 says: Get a depth snapshot from https://api.binance.com/api/v3/depth?symbol=BNBBTC&limit=1000, but why 1000 levels? Will the order book be built correct if using 5000 levels?

  2. What’s the range of Diff. Depth Stream levels? Does it contain all levels, or just 1000 / 5000 levels?

  3. Do I need to Get a depth snapshot from time to time even if the Diff. Depth Stream data is not missing from wss? Imagine that the price goes very high, could it be possible that low price is not updated from wss data, and when price goes down again, those levels are not updated correct?

  1. step 3 says: Get a depth snapshot from https://api.binance.com/api/v3/depth?symbol=BNBBTC&limit=1000, but why 1000 levels? Will the order book be built correct if using 5000 levels?

The 1000 limit is only a suggestion. A local order book with 5000 levels is possible, however it requires more resources to maintain.

  1. What’s the range of Diff. Depth Stream levels? Does it contain all levels, or just 1000 / 5000 levels?

All levels are included.

  1. Do I need to Get a depth snapshot from time to time even if the Diff. Depth Stream data is not missing from wss? Imagine that the price goes very high, could it be possible that low price is not updated from wss data, and when price goes down again, those levels are not updated correct?

In theory, the local order book will be an exact match to the depth snapshot if implemented correctly, irrelevant of the volatility or activity. However, it is common for clients to compare with a snapshot from time to time to confirm the solution is working as intended.

In theory, the local order book will be an exact match to the depth snapshot if implemented correctly, irrelevant of the volatility or activity. However, it is common for clients to compare with a snapshot from time to time to confirm the solution is working as intended.

We observe that it’s not an exact match when price moves. This is due to that price above / below 1000 levels are empty in local order book at the first depth snapshot, if the price never get updated, then it wouldn’t appear in any diff depth message. So local order book wouldn’t know these levels.

Yes, this is a possibility when the local snapshot shrinks below the initial limit requested. In this case, re-taking a snapshot is the most efficient way to re-build a local snapshot back to the initial limit.