need clarification on recent changes of order book management in spot API document

The recent commit on the Spot API documentation has changed the logic of Spot order book management.

Previous logic:

  1. Open a stream to wss://stream.binance.com:9443/ws/bnbbtc@depth.
  2. Buffer the events you receive from the stream.
  3. Get a depth snapshot from https://api.binance.com/api/v3/depth?symbol=BNBBTC&limit=1000 .
  4. Drop any event where u is <= lastUpdateId in the snapshot.
  5. The first processed event should have U <= lastUpdateId+1 AND u >= lastUpdateId+1.
  6. While listening to the stream, each new event’s U should be equal to the previous event’s u+1.
  7. The data in each event is the absolute quantity for a price level.
  8. If the quantity is 0, remove the price level.
  9. Receiving an event that removes a price level that is not in your local order book can happen and is normal.

Current logic:

  1. Open a WebSocket connection to wss://stream.binance.com:9443/ws/bnbbtc@depth.
  2. Buffer the events received from the stream. Note the U of the first event you received.
  3. Get a depth snapshot from https://api.binance.com/api/v3/depth?symbol=BNBBTC&limit=5000.
  4. If the lastUpdateId from the snapshot is strictly less than the U from step 2, go back to step 3.
  5. In the buffered events, discard any event where u is <= lastUpdateId of the snapshot. The first buffered event should now have lastUpdateId within its [U;u] range.
  6. Set your local order book to the snapshot. Its update ID is lastUpdateId.
  7. Apply the update procedure below to all buffered events, and then to all subsequent events received.
    To apply an event to your local order book, follow this update procedure:
  8. If the event u (last update ID) is < the update ID of your local order book, ignore the event.
  9. If the event U (first update ID) is > the update ID of your local order book, something went wrong. Discard your local order book and restart the process from the beginning.
  10. For each price level in bids (b) and asks (a), set the new quantity in the order book:
    • If the price level does not exist in the order book, insert it with new quantity.
    • If the quantity is zero, remove the price level from the order book.
  11. Set the order book update ID to the last update ID (u) in the processed event.

Is this change actually implemented? These changes are not mentioned in the changelog, Do users actually need to change to the new logic?

@adderall-prozac

Looks like the algorithm is basically unchanged and the update is mostly a clarification.

The only new bit is

  1. If the event u (last update ID) is < the update ID of your local order book, ignore the event.
  2. If the event U (first update ID) is > the update ID of your local order book, something went wrong.

which suggests how to handle duplicate events (discard them).

it changes a lot.

this requirement is removed.

and this one changed [U,u] valid pairs from (1,3)(4,6) to (1,3)(3,6)

The first processed event should have U <= lastUpdateId+1 AND u >= lastUpdateId+1.

is different from

The square brackets in [U;u] is not clear, First event’s ‘u’ can’t be equal to ‘lastUpdateId’, since such event is dropped according to

Drop any event where u is <= lastUpdateId in the snapshot.