I have a hft bot and I am using a dedicated network. However sometimes I face a better latency than my dedicated network. I am planning to use both my dedicated network connection and the binance web socket api itself at the same time. When the ticker information coming from two different channels I am planning to use the last update id as a distinguisher for the up to date info. Is the latest update time always increasing and sequential? Does it ever get resetted to 0 or something like that?
About the latest update ID in the ticker information, Yes, the lastUpdateId that you receive from Binance tickers via the WebSocket API is generally increasing and sequential. Each new update has a higher lastUpdateId than the previous one, reflecting the order of transactions on the exchange.
Under normal circumstances, the lastUpdateId does not reset to 0. It should consistently increase as long as the WebSocket connection remains open and data flows continuously. However, in certain rare cases like significant platform updates, maintenance, or issues on the exchange’s side, there could be irregularities.
When integrating data from both your dedicated network and the direct Binance WebSocket feed, consider the following:
Use lastUpdateId to filter and determine the most recent data.
Continuously measure and log the latency for both connections.
Implement logic in your bot to seamlessly switch to the alternative data source if one starts showing signs of increased latency or data irregularities.
My answer to your question is as follows and I think it is. Please correct me if I am wrong.
The u (last update id) in the @bookTicker stream on Binance is indeed a sequential and incrementing value. It acts as a unique identifier for each update. However, it is important to note that the update time is not guaranteed to be strictly sequential due to network latency and other factors. While it usually increases, there may be occasional changes.
Reset: The u value is not reset to 0. However, if you disconnect from the WebSocket stream or encounter issues, you may need to carefully handle reconnecting and syncing.