I am trying to use level2 channel in Advanced Trade WebSocket to maintain up to date orderbook for a given pair but I have noticed the following unexpected to me behaviour: some updates
in "type": "update"
WS messages are sometimes refer to the "price_level"
which does not actually exist in the current orderbook snapshot. All such messages always seem to have "new_quantity": "0"
i.e. are supposed to delete existing price levels but no such price levels actually exist in current orderbook snapshot.
The issue is easily reproducible, e.g. in my experiments for a pair BCH-USD
quite often the very next "type": "update"
message contains "updates"
with "new_quantity": "0"
for "price_level"
's which were not present in the initial ("sequence": "0"
) message of "type": "snapshot"
.
For now I assume that I can just ignore such updates but I was wondering if it is an expected behaviour or a bug. I could not find anything related to this issue in the official documentation and my assumption is that "type": "update"
's message "updated"
field should always refer to an existing in the current orderbook snapshot price level in case of "new_quantity": "0"
so such existing price level is to be deleted when such update is applied.
Example:
{
"channel": "l2_data",
"client_id": "",
"timestamp": "2024-03-20T03:57:06.897535411Z",
"sequence_num": 2,
"events": [
{
"type": "update",
"product_id": "BCH-USD",
"updates": [
{
"side": "bid",
"event_time": "2024-03-20T03:57:06.873871Z",
"price_level": "359.57",
"new_quantity": "0"
}
]
}
]
}
This update is supposed to remove price level "359.57"
but the previous "type": "snapshot"
message does not contain this price level at all.
NB: The "sequence_num": 1
message was "channel": "subscriptions"
message so it did not contain any "updates"
.
Here you can see the initial snapshot and the very next update messages in their entirety (check 359.57 update).