diff --git a/node-binance-api.d.ts b/node-binance-api.d.ts index 8aeb610f..1bb60b34 100644 --- a/node-binance-api.d.ts +++ b/node-binance-api.d.ts @@ -56,7 +56,7 @@ declare module "node-binance-api" { * @param {function} order_update_callback * @param {Function} subscribed_callback - subscription callback */ - userFutureData(margin_call_callback: _callback, account_update_callback: _callback, order_update_callback: _callback, subscribed_callback: _callback): any; + userFutureData(margin_call_callback: _callback, account_update_callback: _callback, order_update_callback: _callback, subscribed_callback: _callback, error_callback:_callback): any; userFutureData(...args: any): any; /** diff --git a/node-binance-api.js b/node-binance-api.js index a672d77e..f7928d05 100644 --- a/node-binance-api.js +++ b/node-binance-api.js @@ -2990,10 +2990,15 @@ let api = function Binance( options = {} ) { * Cancels an order * @param {string} symbol - the symbol to cancel * @param {string} orderid - the orderid to cancel + * @param {object} options - options for the request * @param {function} callback - the callback function * @return {promise or undefined} - omitting the callback returns a promise */ - cancel: function ( symbol, orderid, callback = false ) { + cancel: function ( symbol, orderid, options, callback = false ) { + if (typeof options === 'function') { // Accept callback as third parameter + callback = options; + options = {} + } if ( !callback ) { return new Promise( ( resolve, reject ) => { callback = ( error, response ) => { @@ -3003,12 +3008,17 @@ let api = function Binance( options = {} ) { resolve( response ); } } - signedRequest( base + 'v3/order', { symbol: symbol, orderId: orderid }, function ( error, data ) { + options.symbol = symbol + options.orderId = orderid + signedRequest( base + 'v3/order', options, function ( error, data ) { return callback.call( this, error, data, symbol ); }, 'DELETE' ); } ) } else { - signedRequest( base + 'v3/order', { symbol: symbol, orderId: orderid }, function ( error, data ) { + + options.symbol = symbol + options.orderId = orderid + signedRequest( base + 'v3/order', options, function ( error, data ) { return callback.call( this, error, data, symbol ); }, 'DELETE' ); } @@ -5393,7 +5403,7 @@ let api = function Binance( options = {} ) { * @param {function} order_update_callback * @param {Function} subscribed_callback - subscription callback */ - userFutureData: function userFutureData( margin_call_callback, account_update_callback = undefined, order_update_callback = undefined, subscribed_callback = undefined, account_config_update_callback = undefined ) { + userFutureData: function userFutureData( margin_call_callback, account_update_callback = undefined, order_update_callback = undefined, subscribed_callback = undefined, account_config_update_callback = undefined, error_callback = undefined ) { const url = ( Binance.options.test ) ? fapiTest : fapi; let reconnect = () => { @@ -5401,6 +5411,7 @@ let api = function Binance( options = {} ) { } apiRequest( url + 'v1/listenKey', {}, function ( error, response ) { + if (error) return error_callback && error_callback(error.body); Binance.options.listenFutureKey = response.listenKey; setTimeout( function userDataKeepAlive() { // keepalive try {