question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

binance.websockets.depthCache fails recently

See original GitHub issue

Hi, I am simply using:

        binance.websockets.depthCache(favMarkets, (symbol, depth) => {
            let bids = binance.sortBids(depth.bids);
            let asks = binance.sortAsks(depth.asks);
            var mdata = {
                bid: Number(binance.first(bids)),
                ask: Number(binance.first(asks)),
                bids: depth.bids,
                asks: depth.asks
            };
            socketService.sendDepth({
                market: symbol,
                depth: mdata
            });
            marketDataService.insertDepth(symbol, mdata);
        });

where favMarkets is about 15 markets. All this worked until half an hour ago. Other WebSocket subscriptions (binance.websockets.trades,binance.websockets.userData,binance.websockets.miniTicker) work.

Now binance.websockets.depthCache fails like this:

Array(1) [“WebSocket closed: 1960720743 (1006)”] node-binance-api.js:46 Array(1) [“WebSocket reconnecting: 1960720743…”] node-binance-api.js:46 Array(1) [“WebSocket closed: 1960720743 (1006)”] node-binance-api.js:46 Array(1) [“WebSocket reconnecting: 1960720743…”] node-binance-api.js:46 Array(1) [“WebSocket closed: 1960720743 (1006)”] node-binance-api.js:46 Array(1) [“WebSocket reconnecting: 1960720743…”] node-binance-api.js:46 Array(1) [“WebSocket closed: 1960720743 (1006)”] node-binance-api.js:46 Array(1) [“WebSocket reconnecting: 1960720743…”] node-binance-api.js:46 Error: IncomingMessage {_readableState: ReadableState, readable: false, _events: Object, …} at api.websockets.depthCache.async.mapLimit (file:///home/john/Testing/node_modules/node-binance-api/node-binance-api.js:1825:37) at (anonymous) (file:///home/john/Testing/node_modules/node-binance-api/node_modules/async/dist/async.js:1140:8) at iteratorSymbol (file:///home/john/Testing/node_modules/node-binance-api/node_modules/async/dist/async.js:473:15) at iterateeCallback (file:///home/john/Testing/node_modules/node-binance-api/node_modules/async/dist/async.js:988:16) at (anonymous) (file:///home/john/Testing/node_modules/node-binance-api/node_modules/async/dist/async.js:969:15) at (anonymous) (file:///home/john/Testing/node_modules/node-binance-api/node_modules/async/dist/async.js:1137:12) at (anonymous) (file:///home/john/Testing/node_modules/node-binance-api/node-binance-api.js:1780:35) at cb (file:///home/john/Testing/node_modules/node-binance-api/node-binance-api.js:109:60) at Request.init.self.callback (file:///home/john/Testing/node_modules/request/request.js:185:21) at emit (events.js:198:12) at (anonymous) (file:///home/john/Testing/node_modules/request/request.js:1161:9) at emit (events.js:198:12) at (anonymous) (file:///home/john/Testing/node_modules/request/request.js:1083:11) at onceWrapper (events.js:286:19) at emit (events.js:203:14) at endReadableNT (_stream_readable.js:1129:11) at _tickCallback (internal/process/next_tick.js:63:18)

What could be the issue here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jaggedsoftcommented, May 19, 2020

Hi dbvcode, long time no see. I hope you are well.

But you mean to say that getting a depth size of 500 will make more calls to binance than a request for a 100 depth size?

No. It’s one call, but a depth size 500 uses 5 times the weight. You are allowed 1200 weight per minute. https://www.binance.com/api/v3/exchangeInfo

If you’re connecting to lots of depthCache or chart endpoints at once, you probably need to stagger them with a delay between connections for this reason.

1reaction
bminocommented, May 19, 2020

Watch out! The depthCache method, as you noted, will make a REST call to fetch the initial snapshot of each symbol. This call has a variable weight depending on how big the depth cache is.

By default, this size is 500 which corresponds to a weight of 5. You can override this to fetch a depth of 100 which corresponds to a weight of 1 instead.

Use the limit parameter of the websockets.depthCache function like so:

binance.websockets.depthCache(favMarkets, (symbol, depth) => {
    let bids = binance.sortBids(depth.bids);
    let asks = binance.sortAsks(depth.asks);
    var mdata = {
        bid: Number(binance.first(bids)),
        ask: Number(binance.first(asks)),
        bids: depth.bids,
        asks: depth.asks
    };
    socketService.sendDepth({
        market: symbol,
        depth: mdata
    });
    marketDataService.insertDepth(symbol, mdata);
}, 100);  // <----- This additional parameter with a value of 100
Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for binance.depthcache
Source code for binance.depthcache. import logging from operator import itemgetter import asyncio import time from typing import Optional, Dict, ...
Read more >
ypmei-binance-api - npm Package Health Analysis - Snyk
This function pulls existing chart data before connecting to the WebSocket, and provides you realtime synchronized chart information including ...
Read more >
python-binance initializing client class gives error
It looks like a missing library to me, try to run this in a terminal then rerun the program : pip install websocket-client....
Read more >
python-binance Documentation - Read the Docs
Vanilla options Depth Cache works the same, update the symbol to a current one ... from binance.websockets import BinanceSocketManager.
Read more >
unicorn-binance-local-depth-cache - PyPI
Start or stop multiple caches with just one command create_depth_cache() or stop_depth_cache() . Control websocket out of sync detection with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found