node-binance-api icon indicating copy to clipboard operation
node-binance-api copied to clipboard

Futures UserDataStream websocket for multiple users

Open bcfsunali opened this issue 4 years ago • 21 comments
trafficstars

Hi Can someone help me, please

The library is working fine, but when I add more than 15 user accounts I'm getting this error, can you please help me to fix this issue, please.

Error

/var/www/api/nodejs/futures/node_modules/node-binance-api/node-binance-api.js:902 const queryParams = streams.join( '/' ); ^

TypeError: Cannot read property 'join' of undefined

Code

async function WS() { const Binance = require('node-binance-api'); const dbConnection = require("./connection");

var sqltt = 'SELECT * from auto_trading WHERE futures=1';
BceConnection.query(sqltt, async function(err, result) {
   if (err) throw err;
   numRows = result.length;
   console.log( 'numRows :' , numRows);

for(let x=0, len=numRows; x<len; x++){

    FApikey= result[x].futures_api;
    FSecret= result[x].futures_secret;

const binance = new Binance(); binance.options({ APIKEY: await FApikey(FuturesApikey), APISECRET: await FSecret(FuturesSecret), reconnect: true, useServerTime: true });

function balance_update(data) { const util = require('util') console.log('balance_update :',util.inspect(data, {showHidden: false, depth: null})); }

function execution_update(data) { const util = require('util') var arr = util.inspect(data, {showHidden: false, depth: null}); console.log('execution_update :',arr); }

}

}

binance.websockets.userFutureData(balance_update, execution_update);

} });
}

WS();

bcfsunali avatar Dec 21 '20 06:12 bcfsunali

It might be worthwhile to turn on automatic exception reporting, this throws a catastrophic error on an unhandled failure which often gives more information on the root cause of this issue

process.on( 'unhandledRejection', async ( reason, p ) => { console.log( 'Unhandled Rejection at:', p, 'reason:', reason ); process.exit(1);} );

https://github.com/jaggedsoft

On Mon, Dec 21, 2020 at 7:16 AM bcfsunali [email protected] wrote:

Hi Can someone help me, please

The library is working fine, but when I add more than 15 user accounts I'm getting this error, can you please help me to fix this issue, please. Error

/var/www/api/nodejs/futures/node_modules/node-binance-api/node-binance-api.js:902 const queryParams = streams.join( '/' ); ^

TypeError: Cannot read property 'join' of undefined Code

async function WS() { const Binance = require('node-binance-api'); const dbConnection = require("./connection");

var sqltt = 'SELECT * from auto_trading WHERE futures=1'; BceConnection.query(sqltt, async function(err, result) { if (err) throw err; numRows = result.length; console.log( 'numRows :' , numRows);

for(let x=0, len=numRows; x<len; x++){

FApikey= result[x].futures_api;
FSecret= result[x].futures_secret;

const binance = new Binance(); binance.options({ APIKEY: await FApikey(FuturesApikey), APISECRET: await FSecret(FuturesSecret), reconnect: true, useServerTime: true });

function balance_update(data) { const util = require('util') console.log('balance_update :',util.inspect(data, {showHidden: false, depth: null})); }

function execution_update(data) { const util = require('util') var arr = util.inspect(data, {showHidden: false, depth: null}); console.log('execution_update :',arr); }

}

}

binance.websockets.userFutureData(balance_update, execution_update);

} }); }

WS();

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jaggedsoft/node-binance-api/issues/545, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABAVXYAF2MX6F6EVPUMGBXLSV3R2FANCNFSM4VDYIGYQ .

jaggedsoft avatar Dec 21 '20 08:12 jaggedsoft

It seems to me that this is not a problem in 15 or 16 users, but in one invalid apiKey / apiSecret. And check that you have the latest version of "node-binance-api": "^ 0.12.4", where the server crash was fixed.

Kuzmich100kM avatar Dec 25 '20 16:12 Kuzmich100kM

Hi after long time of execution (4-5 hours maybe) i have the same problem than @bcfsunali

SECRET_PATH/node_modules/node-binance-api/node-binance-api.js:924
        const queryParams = streams.join( '/' );
                                    ^

TypeError: Cannot read property 'join' of undefined
    at futuresSubscribe (SECRET_PATH/node_modules/node-binance-api/node-binance-api.js:924:37)
    at SECRET_PATH/node_modules/node-binance-api/node-binance-api.js:5228:42
    at Request._callback (SECRET_PATH/node_modules/node-binance-api/node-binance-api.js:186:29)
    at self.callback (SECRET_PATH/node_modules/request/request.js:185:22)
    at Request.emit (events.js:315:20)
    at Request.onRequestError (SECRET_PATH/node_modules/request/request.js:877:8)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:467:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:100:8)

And i have the lastest version latest version "node-binance-api": "^ 0.12.4" but my binance is on test: true possible it was that ?

I have launch an other test with more trace, i will keep you informed.

clcreuso avatar Jan 07 '21 08:01 clcreuso

const pry = require('pryjs');
const Binance = require('node-binance-api');

dotenv.config();

const binance = new Binance().options({
    APIKEY: process.env.APIKEY,
    APISECRET: process.env.APISECRET,
    test: true,
    reconnect: true
});

async function main() {

    const newMarginSignal = (res) => {
        console.log(res);
    };

    const newSubscribedSignal = (res) => {
        console.log(res);
    };

    const newAccountSignal = (res) => {
        console.log(res);
    };

    const newOrderSignal = (res) => {
        console.log(res);
    };

    binance.websockets.userFutureData(
        newMarginSignal,
        newAccountSignal,
        newOrderSignal,
        newSubscribedSignal
    );
}

main();

clcreuso avatar Jan 07 '21 11:01 clcreuso

after 2 hours of execution i have this:

node websocketStayConnected.js
rZqPps4xfHY0xBikrz1BL4UQSSGWbgm... [Function: userFutureDataHandler] { reconnect: [Function: reconnect] }
rZqPps4xfHY0xBikrz1BL4UQSSGWbgm...
[ 'Unexpected userFutureData: listenKeyExpired' ]
[ 'Unexpected userFutureData: listenKeyExpired' ]

clcreuso avatar Jan 07 '21 11:01 clcreuso

Hi, clcreuso. Have you solved the problem with the "test: true" option? I have the same problem. Uncaught Exception... TypeError: Cannot read property 'join' of undefined at futuresSubscribe (C:\Users\Александр\node_modules\node-binance-api\node-binance-api.js:924:37) at C:\Users\Александр\node_modules\node-binance-api\node-binance-api.js:5228:42 at Request._callback (C:\Users\Александр\node_modules\node-binance-api\node-binance-api.js:187:63) at Request.self.callback (C:\Users\Александр\node_modules\request\request.js:185:22) at Request.emit (events.js:315:20) at Request. (C:\Users\Александр\node_modules\request\request.js:1154:10) at Request.emit (events.js:315:20) at IncomingMessage. (C:\Users\Александр\node_modules\request\request.js:1076:12) at Object.onceWrapper (events.js:421:28) at IncomingMessage.emit (events.js:327:22)

maxah avatar Jan 29 '21 08:01 maxah

@maxah Hi, This is a very occasional error, i have not find why streams is undefined. But I am still looking for a solution on this bug, I will keep you informed. Leave me a message if you find something ;-)

clcreuso avatar Jan 29 '21 08:01 clcreuso

@maxah Look my last PR. I make my reconnection manually, it's fix the error on streams.join.

clcreuso avatar Feb 01 '21 09:02 clcreuso

The error of streams.join comes from here (if we have an error):

https://github.com/jaggedsoft/node-binance-api/blob/7cbe4276c66519f55e228b84c8951a966310b92e/node-binance-api.js#L5224

@jaggedsoft what we can do ? if (error) reconnect(); is good ?

clcreuso avatar Feb 04 '21 18:02 clcreuso

And i think this line are false:

https://github.com/jaggedsoft/node-binance-api/blob/7cbe4276c66519f55e228b84c8951a966310b92e/node-binance-api.js#L5228

It should be url instead of fapi, right?

clcreuso avatar Feb 04 '21 18:02 clcreuso

I faced this problem too, when test: true, with using futureUserData stream.

image

liho00 avatar Jun 20 '21 11:06 liho00

facing the same issue. Any temporary workaround?

nikhilch86 avatar Jul 06 '21 05:07 nikhilch86

I have made my own library now, but if i remember the probleme was here for userFutureData.

https://github.com/jaggedsoft/node-binance-api/blob/8bad385c70e4a3f9252fc203f5500c1976d0c9ea/node-binance-api.js#L5277 https://github.com/jaggedsoft/node-binance-api/blob/8bad385c70e4a3f9252fc203f5500c1976d0c9ea/node-binance-api.js#L5292

Binance.options.listenFutureKey is the stream var and is undefined

clcreuso avatar Jul 06 '21 08:07 clcreuso

https://github.com/jaggedsoft/node-binance-api/blob/8bad385c70e4a3f9252fc203f5500c1976d0c9ea/node-binance-api.js#L5276

Yes is that the error in apiRequest is not catch you need to catch it when append and rerty after few seconds

clcreuso avatar Jul 06 '21 08:07 clcreuso

Did anyone fix it? It seems I'm still having problems on last version with multiple subscriptions.

MyWay avatar Sep 18 '21 19:09 MyWay

Thanks to @raricy

@jaggedsoft you didn't push in the stable version this PR ?

use this :

if ( error ) {
                        if ( error.code && error.code === 'ESOCKETTIMEDOUT' )
                            return reconnect();
                        else if ( error.body ) {
                            subscribed_callback( JSON.parse( error.body ) );
                            return;
                        }
                    }

must i use reconnect at true ?

ordimans avatar Mar 23 '22 20:03 ordimans

after 2 hours of execution i have this:

node websocketStayConnected.js
rZqPps4xfHY0xBikrz1BL4UQSSGWbgm... [Function: userFutureDataHandler] { reconnect: [Function: reconnect] }
rZqPps4xfHY0xBikrz1BL4UQSSGWbgm...
[ 'Unexpected userFutureData: listenKeyExpired' ]
[ 'Unexpected userFutureData: listenKeyExpired' ]

Hi for this Error in expiration you need send a requestes ever 3 minutes for example to this endpoind in PUT request -> /fapi/v1/listenKey for keep the listenkey alive

julio899 avatar Sep 05 '22 12:09 julio899

https://github.com/jaggedsoft/node-binance-api/pull/851/commits/64bff63930a7cffc3efafc6ee27416697df7e8ab

maxah avatar Sep 06 '22 05:09 maxah

after 2 hours of execution i have this:

node websocketStayConnected.js
rZqPps4xfHY0xBikrz1BL4UQSSGWbgm... [Function: userFutureDataHandler] { reconnect: [Function: reconnect] }
rZqPps4xfHY0xBikrz1BL4UQSSGWbgm...
[ 'Unexpected userFutureData: listenKeyExpired' ]
[ 'Unexpected userFutureData: listenKeyExpired' ]

Hi for this Error in expiration you need send a requestes ever 3 minutes for example to this endpoind in PUT request -> /fapi/v1/listenKey for keep the listenkey alive

The lib doesn't take care of this alone? I have to manage it myself?

luiztools avatar Sep 15 '22 14:09 luiztools

Add 'family': 4, I solved this error with this solution:

const binance = new Binance().options({ APIKEY: '<YOUR-APIKEY>', APISECRET: '<YOUR-APISECRET>', 'family': 4, });

https://stackoverflow.com/questions/72033310/typeerror-err-invalid-arg-value-the-property-options-family-must-be-one-of

kiriman avatar Dec 10 '22 16:12 kiriman

BTW, to avoid this Uncaught Exception errors like (because not catched by author):

const queryParams = streams.join( '/' );
TypeError: Cannot read property 'join' of undefined

We can use this instead:

process.on('uncaughtException', (error) => {
  if (error instanceof TypeError) {
    console.error('Uncaught Exception - ', error);
  }
});

doppelgunner avatar Apr 23 '23 04:04 doppelgunner