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

TypeError: Cannot read property 'filter' of undefined #141

Closed keesgeel closed 6 years ago

keesgeel commented 6 years ago

Hi there!

When tracking 4 or more pairs through webSocket (binance.websockets.depth) I get the following exception. Anyone knows how I can prevent this?

~/project/node_modules/node-binance-api/node-binance-api.js:897 context.messageQueue = context.messageQueue.filter(depth => depth.u > context.snapshotUpdateId); ^

TypeError: Cannot read property 'filter' of undefined

bkrypt commented 6 years ago

Hi,

Just to confirm, you mean binance.websockets.depthCache right, and not binance.websockets.depth?

I find these undefined messageQueue errors most bizarre, as the array is always created first before subscribing to the data stream, and retrieving the snapshot.

I'm just trying to get a better picture of the root cause of these errors, because checking for the existence of the array is only masking the cause.

How many calls in total do you make to websockets.depthCache? ie. How many separate streams do you have open to market depths? What symbols are you passing to each call?

keesgeel commented 6 years ago

Hi @keith1024 - Thanks for your response!

Indeed, I ment binance.websockets.depthCache. I actually just found the issue, it had nothing to do with the amount of pairs tracking. When you track the same pair more then once, this error is triggered.

bkrypt commented 6 years ago

Sorry for the massive delay @keesgeel. Yeah, I was thinking it was when tracking a pair more than once. It will only happen if you start tracking the same pair again almost immediately after the last call to track that pair. I will keep this in mind and implement a guard against it as soon as I have the time.

dmzoneill commented 6 years ago

this is fixed a number of commits back