When using websockets to get the content of the orderbook (orderBookL2_25.Symbol) the content of the orderbook obtained when calling fetch() is out of order. When Bybitsends the orderbook the first time on the websocket it is ordered properly and then on subsequent delta pushes, pybit updates the local version of the orderbook, but does not re-sort it after delta updates. So when we call fetch() to get the orderbook we might assume the orderbook is sorted, but that is not the case and reading only the top rows for buyers/sellers sometime gives inaccurate results. Here is an example of what fetch() returns after a few delta updates.
For example:
Maybe pybitshould re-sort the local orderbook in _on_message() after each delta updates, or prior to returning the orderbook to the user in the fetch() method and if not, at least tell the user he needs to re-sort the orderbook himself prior to using it.
When using websockets to get the content of the orderbook
(orderBookL2_25.Symbol)
the content of the orderbook obtained when callingfetch()
is out of order. WhenBybit
sends the orderbook the first time on the websocket it is ordered properly and then on subsequent delta pushes,pybit
updates the local version of the orderbook, but does not re-sort it after delta updates. So when we callfetch()
to get the orderbook we might assume the orderbook is sorted, but that is not the case and reading only the top rows for buyers/sellers sometime gives inaccurate results. Here is an example of whatfetch()
returns after a few delta updates. For example:Maybe
pybit
should re-sort the local orderbook in_on_message()
after each delta updates, or prior to returning the orderbook to the user in thefetch()
method and if not, at least tell the user he needs to re-sort the orderbook himself prior to using it.