Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Working with Binance Order Book in C++
4 points by paketick on Sept 22, 2023 | hide | past | favorite
How do you work with Binance (or other exchanges) order book in C++? Do you use any ready-to-use solutions for that, or make everything in-house?

I see these challenges:

1. You need to manually get snapshots via REST initially and combine them with ob diffs streams.

2. If you need a lot of symbols, you will exceed REST limits by getting snapshots very soon.

3. Binance gives only 1000/5000 depth via REST (depending on the weight spending you choose) 3.1. So you can’t see a whole order book at the start. 3.2. If the market goes away from the price spread of your initial snapshot, you will lack some orders because they were beyond the snapshot and placed before you started consuming the diffs.

4. When you receive a lot of stream data, your latency inside your app increases. 4.1. Data processing should be divided into dedicated CPU cores 4.2. Network packets probably too (at least smarter working with rps_cpus than default). 4.3. Data structure for order book should be lock-free - writes and reads shouldn’t lock each other. Probably, there is only 1 write per time for each symbol, but extensive reads shouldn’t lock write operations and vice versa.

5. Order book data structure should support read operations like getting a total amount from the top for a specific depth or getting a depth of a specific total amount. They should work very fast.

In the case of Python, ccxt lib can handle order book. It even refetches snapshot from time to time, but limits the depth to 1000, and it’s still a challenge to handle even 50 symbols at once. For C++ I just don't know any ready-made solutions.

Any details would be interesting )



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: