* Future Userdata websockets function * @param {function} all_updates_callback * @param {function} margin_call_callback * @param {function} account_update_callback * @param {function} order_update_callback * @param {Function} subscribed_callback - subscription callback
(all_updates_callback?: Callback, margin_call_callback?: Callback, account_update_callback?: Callback, order_update_callback?: Callback, subscribed_callback?: Callback, account_config_update_callback?: Callback)
| 6269 | * @param {Function} subscribed_callback - subscription callback |
| 6270 | */ |
| 6271 | userFutureData(all_updates_callback?: Callback, margin_call_callback?: Callback, account_update_callback?: Callback, order_update_callback?: Callback, subscribed_callback?: Callback, account_config_update_callback?: Callback) { |
| 6272 | // const url = (this.Options.test) ? this.fapiTest : this.fapi; |
| 6273 | const url = this.getFapiUrl(); |
| 6274 | |
| 6275 | const reconnect = () => { |
| 6276 | if (this.Options.reconnect) this.userFutureData(all_updates_callback, margin_call_callback, account_update_callback, order_update_callback, subscribed_callback); |
| 6277 | }; |
| 6278 | |
| 6279 | // const response = await this.apiRequest(url + 'v1/listenKey', {}, 'POST'); |
| 6280 | this.apiRequest(url + 'v1/listenKey', {}, 'POST').then((response: any) => { |
| 6281 | this.Options.listenFutureKey = response.listenKey; |
| 6282 | const self = this; |
| 6283 | const keepAlive = this.futuresListenKeyKeepAlive; |
| 6284 | setTimeout(async function userDataKeepAlive() { // keepalive |
| 6285 | try { |
| 6286 | await self.apiRequest(url + 'v1/listenKey?listenKey=' + self.Options.listenFutureKey, {}, 'PUT'); |
| 6287 | setTimeout(userDataKeepAlive, keepAlive); // 30 minute keepalive |
| 6288 | } catch (error) { |
| 6289 | setTimeout(userDataKeepAlive, 60000); // retry in 1 minute |
| 6290 | } |
| 6291 | }, keepAlive); // 30 minute keepalive |
| 6292 | this.Options.futures_all_updates_callback = all_updates_callback; |
| 6293 | this.Options.future_margin_call_callback = margin_call_callback; |
| 6294 | this.Options.future_account_update_callback = account_update_callback; |
| 6295 | this.Options.future_account_config_update_callback = account_config_update_callback; |
| 6296 | this.Options.future_order_update_callback = order_update_callback; |
| 6297 | const subscription = this.futuresSubscribe(this.Options.listenFutureKey, this.userFutureDataHandler.bind(this), { reconnect }); |
| 6298 | if (subscribed_callback) subscribed_callback(subscription.endpoint); |
| 6299 | |
| 6300 | }); |
| 6301 | // const response = await this.apiRequest(url + 'v1/listenKey', {}, 'POST'); |
| 6302 | |
| 6303 | } |
| 6304 | |
| 6305 | /** |
| 6306 | * Delivery Userdata websockets function |
no test coverage detected