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

userFutureData not working properly

Open Al3xxx19 opened this issue 4 years ago • 5 comments

when i use this code

function balance_update(data) {
 console.log(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) {
  console.log(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);
}
binance.websockets.userFutureData(balance_update, execution_update);

i only get

  eventTime: 1600252360125,
  transaction: 1600252360121,
  updateData:
   { eventReasonType: 'ORDER',
     balances: [ [Object], [Object] ],
     positions: [ [Object] ] } }
Balance Update
[ 'Parse error: data.B is not iterable' ]

Can you help please?

Al3xxx19 avatar Sep 16 '20 10:09 Al3xxx19

I don't think data.B exists here. You could use util.inspect to see the full object structure:

const util = require('util')

console.log(util.inspect(data, {showHidden: false, depth: null}))

I would expect data.updateData.B to exist, but not on margin_call_callback but on account_update_callback (the second callback parameter to binance.websockets.userFutureData: userFutureData: function userFutureData( margin_call_callback, account_update_callback = undefined, order_update_callback = undefined, subscribed_callback = undefined)

arenddeboer avatar Sep 19 '20 11:09 arenddeboer

https://binance-docs.github.io/apidocs/testnet/en/#close-user-data-stream-user_stream scroll a bit down, there you can see the different sample outputs for the different event calls

so for margin_call there is no data.B

minthauzens avatar Sep 25 '20 10:09 minthauzens

guys, i still dont get anything form the future data streams, it doesnt return anything, i need the balance updates alone, pls help, my code is similar.

kanish-111 avatar Sep 13 '21 18:09 kanish-111

I have the same issue. The second callback function doesn't work so I get all data inside the first callback. Getting the same message: [ 'Parse error: data.B is not iterable' ]

leonxx-dev avatar Sep 20 '21 13:09 leonxx-dev

Have a look here and try my sample code. It should work. https://github.com/jaggedsoft/node-binance-api/issues/432#issuecomment-919463672

arenddeboer avatar Sep 20 '21 15:09 arenddeboer