jaggedsoft / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
1.58k stars 767 forks source link

depthCache returns obsolete order b #135

Closed rotemx closed 6 years ago

rotemx commented 6 years ago

Bug report

Hi, Firstly, great lib ! thank you !

When using the depthCache method, I get old values, and it doesn't update for very long.

I tried comparing the result values with a normal REST api call, the received the following input. (in this example I select the first row in asks array and show it's price):

16-02-18 18:52:11:949        buy rest    10074.90000000
16-02-18 18:52:11:953        buy socket  9740.00000000
16-02-18 18:52:12:945        buy rest    10076.82000000
16-02-18 18:52:12:950        buy socket  9740.00000000
16-02-18 18:52:13:951        buy socket  9740.00000000
16-02-18 18:52:13:977        buy rest    10076.82000000
16-02-18 18:52:14:953        buy socket  9740.00000000
16-02-18 18:52:14:957        buy rest    10076.82000000
16-02-18 18:52:15:954        buy socket  9740.00000000
16-02-18 18:52:15:978        buy rest    10077.30000000
16-02-18 18:52:16:950        buy socket  9740.00000000
16-02-18 18:52:16:960        buy rest    10077.30000000
16-02-18 18:52:17:951        buy socket  9740.00000000
16-02-18 18:52:18:004        buy rest    10077.30000000
16-02-18 18:52:18:953        buy socket  9740.00000000
16-02-18 18:52:18:960        buy rest    10076.82000000
16-02-18 18:52:19:954        buy socket  9740.00000000
16-02-18 18:52:20:000        buy rest    10078.01000000
16-02-18 18:52:20:933        buy rest    10077.30000000
16-02-18 18:52:20:950        buy socket  9740.00000000
16-02-18 18:52:21:955        buy socket  9740.00000000
16-02-18 18:52:21:984        buy rest    10078.37000000
16-02-18 18:52:22:942        buy rest    10069.02000000
16-02-18 18:52:22:956        buy socket  9740.00000000
16-02-18 18:52:23:929        buy rest    10067.81000000
16-02-18 18:52:23:957        buy socket  9740.00000000
16-02-18 18:52:24:954        buy socket  9740.00000000
16-02-18 18:52:24:983        buy rest    10071.79000000
16-02-18 18:52:25:954        buy socket  9740.00000000
16-02-18 18:52:25:966        buy rest    10068.47000000
16-02-18 18:52:26:934        buy rest    10067.84000000
16-02-18 18:52:26:954        buy socket  9740.00000000
16-02-18 18:52:27:925        buy rest    10068.47000000
16-02-18 18:52:27:955        buy socket  9740.00000000
16-02-18 18:52:28:955        buy socket  9740.00000000
16-02-18 18:52:28:960        buy rest    10067.00000000
16-02-18 18:52:29:953        buy socket  9740.00000000
16-02-18 18:52:30:002        buy rest    10065.02000000
16-02-18 18:52:30:959        buy socket  9740.00000000
16-02-18 18:52:31:023        buy rest    10065.02000000
16-02-18 18:52:31:955        buy socket  9740.00000000
16-02-18 18:52:31:990        buy rest    10065.02000000
16-02-18 18:52:32:958        buy socket  9740.00000000
16-02-18 18:52:33:096        buy rest    10068.83000000
16-02-18 18:52:33:953        buy socket  9740.00000000
16-02-18 18:52:34:039        buy rest    10076.34000000
16-02-18 18:52:34:957        buy socket  9740.00000000
16-02-18 18:52:34:965        buy rest    10076.34000000
16-02-18 18:52:35:953        buy socket  9740.00000000
16-02-18 18:52:35:985        buy rest    10076.34000000
16-02-18 18:52:36:956        buy socket  9740.00000000
16-02-18 18:52:37:010        buy rest    10076.82000000
16-02-18 18:52:37:952        buy socket  9740.00000000
16-02-18 18:52:37:975        buy rest    10076.82000000
16-02-18 18:52:38:955        buy socket  9740.00000000
16-02-18 18:52:39:017        buy rest    10071.57000000
16-02-18 18:52:39:955        buy socket  9740.00000000
16-02-18 18:52:40:036        buy rest    10075.00000000
16-02-18 18:52:40:972        buy socket  9740.00000000
16-02-18 18:52:41:001        buy rest    10071.60000000
16-02-18 18:52:41:956        buy socket  9740.00000000
16-02-18 18:52:42:033        buy rest    10071.02000000
16-02-18 18:52:42:954        buy rest    10071.02000000
16-02-18 18:52:42:958        buy socket  9740.00000000
16-02-18 18:52:43:957        buy socket  9740.00000000
16-02-18 18:52:44:003        buy rest    10071.02000000
16-02-18 18:52:44:954        buy socket  9740.00000000
16-02-18 18:52:45:061        buy rest    10070.98000000

Note that the gap between them is getting higher if the price has changed dramatically.

bkrypt commented 6 years ago

Hi

Can you confirm your node-binance-api version please?

rotemx commented 6 years ago

Hi, sure.

according to the package.json file in node_modules I am using "version": "0.4.17"

Thanks

On Fri, Feb 16, 2018 at 7:46 PM, Keith Kirton notifications@github.com wrote:

Hi

Can you confirm your node-binance-api version please?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/135#issuecomment-366323920, or mute the thread https://github.com/notifications/unsubscribe-auth/AFyCRu7ODgYRSsPF3NQY7DMFuKpdrut2ks5tVcz_gaJpZM4SIuS8 .

-- ►►Rotem Meiri rotemx@gmail.com

rotemx commented 6 years ago

should I update to 0.4.20 ? would it solve the problem ?

On Fri, Feb 16, 2018 at 7:47 PM, Rotem Meiri rotemx@gmail.com wrote:

Hi, sure.

according to the package.json file in node_modules I am using "version": "0.4.17"

Thanks

On Fri, Feb 16, 2018 at 7:46 PM, Keith Kirton notifications@github.com wrote:

Hi

Can you confirm your node-binance-api version please?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/135#issuecomment-366323920, or mute the thread https://github.com/notifications/unsubscribe-auth/AFyCRu7ODgYRSsPF3NQY7DMFuKpdrut2ks5tVcz_gaJpZM4SIuS8 .

-- ►►Rotem Meiri rotemx@gmail.com

-- ►►Rotem Meiri rotemx@gmail.com

rotemx commented 6 years ago

I can see now it was fixed in #129 ?

On Fri, Feb 16, 2018 at 7:48 PM, Rotem Meiri rotemx@gmail.com wrote:

should I update to 0.4.20 ? would it solve the problem ?

On Fri, Feb 16, 2018 at 7:47 PM, Rotem Meiri rotemx@gmail.com wrote:

Hi, sure.

according to the package.json file in node_modules I am using "version": "0.4.17"

Thanks

On Fri, Feb 16, 2018 at 7:46 PM, Keith Kirton notifications@github.com wrote:

Hi

Can you confirm your node-binance-api version please?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/135#issuecomment-366323920, or mute the thread https://github.com/notifications/unsubscribe-auth/AFyCRu7ODgYRSsPF3NQY7DMFuKpdrut2ks5tVcz_gaJpZM4SIuS8 .

-- ►►Rotem Meiri rotemx@gmail.com

-- ►►Rotem Meiri rotemx@gmail.com

-- ►►Rotem Meiri rotemx@gmail.com

bkrypt commented 6 years ago

Ah, excellent. Yeah that's right. The issue was resolved in #129 for v0.4.19, so an upgrade to the latest (v0.4.20) will sort you out.

rotemx commented 6 years ago

@keith1024 , I'm afraid the bug is still there after updating to 0.4.20.

I tried running the socket and rest in parallel, and after a few minutes of I running the socket is out of sync:

image

bkrypt commented 6 years ago

The latest version will print an error when the cache is out of sync.

Note that the REST depth will return a sorted snapshot of asks/bids. The WebSocket version cannot, since you only receive diffs of the data per update, you should run those through binance.sortAsks or binance.sortBids when wanting to access the data in a sorted manner.

https://github.com/jaggedsoft/node-binance-api#maintain-market-depth-cache-locally-via-websocket

binance.websockets.depthCache('ETHBTC', (symbol, depth) => {
  let bids = binance.sortBids(depth.bids);
  let asks = binance.sortAsks(depth.asks);
  console.log(symbol+" depth cache update");
  console.log("bids", bids);
  console.log("asks", asks);
  console.log("best bid: "+binance.first(bids));
  console.log("best ask: "+binance.first(asks));
});
adityamertia commented 6 years ago

I am facing this issue still. It does print out [ 'depthHandler :LTCUSDT: !! DEPTH CACHE OUT OF SYNC !!' ] But why does it come at all. Does it get resolved by itself ? what is the resolution.

dakovi commented 6 years ago

Interesting: While working with the API since several weeks today was the first day I saw this error constantly popping up one one pair (instead of the somewhat usual one time only at the start of a subscription). I restarted the script and it was all okay. Could argue that there was some kind of problem on Binance side since it worked perfectly the last weeks...

jaggedsoft commented 6 years ago

In the past, if the depth cache got out of sync we would just restart seamlessly. I suppose this is not working?

dakovi commented 6 years ago

Yeah I just saw my log a few minutes ago filled with out of sync errors (for both pair subscriptions I've been running) again. Manually restarted the script to get rid of them. I guess there is something wrong.

adityamertia commented 6 years ago

I wanted to see if there can be an error/exception object thrown such that it can be handled at client side accordingly. Currently i believe it only does log "DEPTH CACHE OUT OF SYNC" which client cannot handle seamlessly?

jaggedsoft commented 6 years ago

Are you guys having any issues with other websocket endpoints? I see that binance made some changes recently

dakovi commented 6 years ago

Can't give you more info on that topic since I am just using the depthCache stream in a regular way. Today without one incident...