node-binance-api
node-binance-api copied to clipboard
userFutureData not working properly
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?
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)
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
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.
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' ]
Have a look here and try my sample code. It should work. https://github.com/jaggedsoft/node-binance-api/issues/432#issuecomment-919463672