Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Order Book Issue #191

Open
cecilymiller opened this issue Apr 17, 2020 · 4 comments
Open

Order Book Issue #191

cecilymiller opened this issue Apr 17, 2020 · 4 comments
Labels

Comments

@cecilymiller
Copy link

I've issues to handle local order book. The docs says:

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

At the end of: https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#how-to-manage-a-local-order-book-correctly

But the first check never passes

  1. I fetch market depth from http://api.binance.com/api/v3/depth

  2. I'm listening depth websocket stream like so

binance.websockets.depth("BNBBTC", (depth) => {
    //
});
  1. Then I have the following checks:
if (depth.U <= lastUpdateId + 1) {
  console.log("First check passes");
}

AND

if (depth.u >= lastUpdateId + 1) {
   console.log("Second check passes");
}

But the first check never passes. So, is there a mistake in the docs, or is the docs only for v1 and if so, how should I handle the order book when using API v3?

@jaggedsoft
Copy link
Member

This is already handled in binance.websockets.chart, for anything else you will need to ask here https://t.me/binance_api_english

@cecilymiller
Copy link
Author

I'm sorry, what you mean by

This is already handled in binance.websockets.chart

Aren't those completely different datasets?

In the future I'll use telegram, I'm tying to get this solved in here if that's ok

@cecilymiller
Copy link
Author

Or are you saying the first check is redundant?

@micopero
Copy link

micopero commented Jul 29, 2020

Hello Cecily, I think the problem is you keep fetching snapshots. You only need 1 snapshot and then start processing the events. The first event to be processed is the event where its U <= snapshot.lastUpdateId AND its u >= snapshot.lastUpdateId.

However, you also need to make sure that for each event processed AFTER the first event, currentEvent.U == previousEvent.u + 1.

If the previous condition breaks at any moment, you will need to fetch another snapshot and repeat.. etc

Hope that helps, that's how I implemented it. Feel free to ask for more insight.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants