How to manage futures order book properly

I’m using the spot code as a base, but it’s not the same logic, see:

  1. Connect to the websocket

  2. u of the snapshot: 8058369969964

  3. Save this snapshot as the local workbook

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

  5. The first processed event should have U <= lastUpdateId** AND **u >= lastUpdateId

After completing steps 4 and 5, the event buffer was cleared, leaving only the snapshot and the initial event.

  1. While listening to the stream, each new event’s pu should be equal to the previous event’s u. Otherwise, initialize the process from step 3.

In the next event, the pu is: 8058369966560, which is different from the local orderbook (8058369969964), thus generating infinite retries.

If I take the python code and modify the wss endpoint and consider the pu as the future require I also get eternal loop.