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 768 forks source link

userFutureData not returning anything. #591

Open thisisloze opened 3 years ago

thisisloze commented 3 years ago

I used the example for userData and replaced it with userFutureData and I am not getting anything returned. I have made several trades and I left it open. Here is my code:

function balance_update(data) { console.log("Balance Update"); for ( let obj of data.B ) { let { a:asset, f:available, l:onOrder } = obj; if ( available == "0.00000000" ) continue; console.log(asset+"\tavailable: "+available+" ("+onOrder+" on order)"); } } function execution_update(data) { let { x:executionType, s:symbol, p:price, q:quantity, S:side, o:orderType, i:orderId, X:orderStatus } = data; if ( executionType == "NEW" ) { if ( orderStatus == "REJECTED" ) { console.log("Order Failed! Reason: "+data.r); } console.log(symbol+" "+side+" "+orderType+" ORDER #"+orderId+" ("+orderStatus+")"); console.log("..price: "+price+", quantity: "+quantity); return; } //NEW, CANCELED, REPLACED, REJECTED, TRADE, EXPIRED console.log(symbol+"\t"+side+" "+executionType+" "+orderType+" ORDER #"+orderId); } const updates = this.binance.websockets.userFutureData(balance_update, execution_update); console.log(updates)

    I ran it for 12hr and this is the only message I got.

    C:\projects\binanceTrader>node index.js

undefined [ 'Futures WebSocket closed: pUlFy6cJUEc3P4lQfZJhhRRcNtvXDKeuiuNLu3eek72DsnDLd1tgZ1Y7stn7hosw (1006)' ] [ 'Futures WebSocket reconnecting: pUlFy6cJUEc3P4lQfZJhhRRcNtvXDKeuiuNLu3eek72DsnDLd1tgZ1Y7stn7hosw...' ]

cryptochancla commented 3 years ago

same problem... i read all the issues about it... and tried to understand the userFutureData method... but stucked like you, i dont find a solution :(

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);
}

const Binance = require('node-binance-api');
const binance = new Binance();
binance.options({
APIKEY: '',
APISECRET: '',
reconnect: true,
useServerTime: true
});

binance.websockets.userFutureData(balance_update, execution_update);

even "binance.websockets.userFutureData(console.log, console.log, console.log);" or " binance.userFutureData(console.log, console.log, console.log, console.log);" doesnt work :(

cryptochancla commented 3 years ago

ok it works .... u just need to create an order... hm ok but how can i have an updated pnl in real time ? or an updated list of my canceled orders ? cause the stream just updates when an order is executed thats all :(

kanish-111 commented 2 years ago

having same issue. any updates on this??

ddesvard commented 2 years ago

have you tried including the 4 callbacks?

function margin_call_update(data) { console.log(margin_call_update:data: ${JSON.stringify(data)}) } function account_update(data) { console.log(account_update:data: ${JSON.stringify(data)}) } function order_update(data) { console.log(order_update:data: ${JSON.stringify(data)}) } function subscribed_update(data) { console.log(subscribed_update:data: ${JSON.stringify(data)}) }

binance.websockets.userFutureData(margin_call_update, account_update, order_update, subscribed_update );

ordimans commented 2 years ago

I have the same problem after running it during some hours. I think the problem is the websocket is alvie for 60 minutes, and so we need to use keep alive like mentionned here :

https://binance-docs.github.io/apidocs/futures/en/#user-data-streams

It seems coded, but don't work very well ?

Because if i restart the script, old data was processed in the WS....

apiRequest( url + 'v1/listenKey', {}, function ( error, response ) { Binance.options.listenFutureKey = response.listenKey; setTimeout( function userDataKeepAlive() { // keepalive try { apiRequest( url + 'v1/listenKey?listenKey=' + Binance.options.listenFutureKey, {}, function ( err ) { if ( err ) setTimeout( userDataKeepAlive, 60000 ); // retry in 1 minute else setTimeout( userDataKeepAlive, 60 * 30 * 1000 ); // 30 minute keepalive }, 'PUT' ); } catch ( error ) { setTimeout( userDataKeepAlive, 60000 ); // retry in 1 minute } }, 60 * 30 * 1000 ); // 30 minute keepalive