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

messageQueue[symbol] undefined #44

Closed bitcoinvsalts closed 6 years ago

bitcoinvsalts commented 6 years ago

Parse error: Cannot read property 'push' of undefined

depthCache: function depthCacheFunction(symbols, callback, limit = 500) {
                if ( typeof symbols === 'string' ) symbols = [symbols]; // accept both strings and arrays
                for ( let symbol of symbols ) {
                    if ( typeof info[symbol] === 'undefined' ) info[symbol] = {};
                    info[symbol].firstUpdateId = 0;
                    depthCache[symbol] = {bids: {}, asks: {}};
                    messageQueue[symbol] = [];
                    let reconnect = function() {
                        if ( options.reconnect ) depthCacheFunction([symbol], callback);
                    };
                    subscribe(symbol.toLowerCase()+'@depth', function(depth) {
                        if ( !info[symbol].firstUpdateId ) {
                            console.log(messageQueue[symbol])  **// UNDEFINED**
                            messageQueue[symbol].push(depth);  // BUG IS HERE
                            return;
                        }
jaggedsoft commented 6 years ago

That is really strange. I don't even see how that can become undefined. Looking in to it

jaggedsoft commented 6 years ago

I am really behind on some work at the moment, can you please try adding this above the bug line

if ( typeof messageQueue[symbol] === 'undefined' ) messageQueue[symbol] = [];

bitcoinvsalts commented 6 years ago

no problem I understand I fixed it by adding this:


if ( !info[symbol].firstUpdateId ) {
                            messageQueue[symbol] = [];
                            messageQueue[symbol].push(depth);
                            return;
                        }

if it's ok I can create a PR for this