Right now Binance has two types of APIs (Spot as well as Futures):
- A REST API that has weights and limits but is quite featured
- A Websocket API that probably came later, it’s realtime and performant
My problem with the websocket API is that it is ONLY realtime.
If my application restarts is disconnected there is a data gap, this ruins the integrity of the orderbook and misses realtime trades.
The official (and only) solution is to synchronize the missing data through the REST API, which is complex to do and costs a lot more performance on Binance side.
The orderbook needs a full synchronization on each restart so the removals are all caught.
My suggestion:
Give the Websocket a time buffer on Binance side, for example 1 week, 1 day or just 1 hour.
Add optional parameter -> timeStart
When we use that parameter the websocket stream doesn’t start realtime, it instead starts at the timestamp given and catches up to realtime at a set rate.