binance.websockets.depthCache fails recently
See original GitHub issueHi, 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:
- Created 4 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top GitHub Comments
Hi dbvcode, long time no see. I hope you are well.
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.
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 thewebsockets.depthCache
function like so: