Skip to content

Commit

Permalink
Fix keep alive url for user future data + log message fix by arenddeboer
Browse files Browse the repository at this point in the history
  • Loading branch information
jaggedsoft authored Sep 15, 2020
2 parents c73dd18 + bcaa21b commit e2088e8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions node-binance-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,7 @@ let api = function Binance( options = {} ) {
Binance.options.future_order_update_callback( fUserDataOrderUpdateConvertData(data));
}
} else {
Binance.options.log( 'Unexpected userMarginData: ' + type );
Binance.options.log( 'Unexpected userFutureData: ' + type );
}
};

Expand Down Expand Up @@ -4945,11 +4945,16 @@ let api = function Binance( options = {} ) {
*/
userFutureData: function userFutureData( margin_call_callback, account_update_callback = undefined, order_update_callback = undefined, subscribed_callback = undefined) {
const url = ( Binance.options.test ) ? fapiTest : fapi;

let reconnect = () => {
if (Binance.options.reconnect) userFutureData(margin_call_callback, account_update_callback, order_update_callback, subscribed_callback)
}

apiRequest( url + 'v1/listenKey', {}, function ( error, response ) {
Binance.options.listenFutureKey = response.listenKey;
setTimeout( function userDataKeepAlive() { // keepalive
try {
apiRequest( fapi + 'v1/userDataStream?listenKey=' + Binance.options.listenFutureKey, {}, function ( err ) {
apiRequest( fapi + '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' );
Expand All @@ -4960,7 +4965,7 @@ let api = function Binance( options = {} ) {
Binance.options.future_margin_call_callback = margin_call_callback;
Binance.options.future_account_update_callback = account_update_callback;
Binance.options.future_order_update_callback = order_update_callback;
const subscription = futuresSubscribe( Binance.options.listenFutureKey, userFutureDataHandler, Binance.options.reconnect );
const subscription = futuresSubscribe( Binance.options.listenFutureKey, userFutureDataHandler, { reconnect } );
if ( subscribed_callback ) subscribed_callback( subscription.endpoint );
}, 'POST' );
},
Expand Down

0 comments on commit e2088e8

Please sign in to comment.