* Delivery Userdata websockets function * @param {function} margin_call_callback * @param {function} account_update_callback * @param {function} order_update_callback * @param {Function} subscribed_callback - subscription callback
(
margin_call_callback: Callback,
account_update_callback?: Callback,
order_update_callback?: Callback,
subscribed_callback?: Callback
)
| 6310 | * @param {Function} subscribed_callback - subscription callback |
| 6311 | */ |
| 6312 | userDeliveryData( |
| 6313 | margin_call_callback: Callback, |
| 6314 | account_update_callback?: Callback, |
| 6315 | order_update_callback?: Callback, |
| 6316 | subscribed_callback?: Callback |
| 6317 | ) { |
| 6318 | const url = this.getDapiUrl(); |
| 6319 | |
| 6320 | const reconnect = async () => { |
| 6321 | if (this.Options.reconnect) |
| 6322 | await this.userDeliveryData( |
| 6323 | margin_call_callback, |
| 6324 | account_update_callback, |
| 6325 | order_update_callback, |
| 6326 | subscribed_callback |
| 6327 | ); |
| 6328 | }; |
| 6329 | |
| 6330 | this.apiRequest(url + "v1/listenKey", {}, "POST").then((response: any) => { |
| 6331 | this.Options.listenDeliveryKey = response.listenKey; |
| 6332 | const getDeliveryKey = () => this.Options.listenDeliveryKey; |
| 6333 | const self = this; |
| 6334 | const keepAlive = this.futuresListenKeyKeepAlive; |
| 6335 | setTimeout(async function userDataKeepAlive() { |
| 6336 | // keepalive |
| 6337 | try { |
| 6338 | await self.apiRequest( |
| 6339 | url + |
| 6340 | "v1/listenKey?listenKey=" + |
| 6341 | getDeliveryKey(), |
| 6342 | {}, |
| 6343 | "PUT" |
| 6344 | ); |
| 6345 | // function (err: any) { |
| 6346 | // if (err) setTimeout(userDataKeepAlive, 60000); |
| 6347 | // // retry in 1 minute |
| 6348 | setTimeout(userDataKeepAlive, keepAlive); // 30 minute keepalive |
| 6349 | } catch (error) { |
| 6350 | setTimeout(userDataKeepAlive, 60000); // retry in 1 minute |
| 6351 | } |
| 6352 | }, keepAlive); // 30 minute keepalive |
| 6353 | this.Options.delivery_margin_call_callback = margin_call_callback; |
| 6354 | this.Options.delivery_account_update_callback = account_update_callback; |
| 6355 | this.Options.delivery_order_update_callback = order_update_callback; |
| 6356 | const subscription = this.deliverySubscribe( |
| 6357 | this.Options.listenDeliveryKey, |
| 6358 | this.userDeliveryDataHandler.bind(this), |
| 6359 | { reconnect } |
| 6360 | ); |
| 6361 | if (subscribed_callback) subscribed_callback(subscription.endpoint); |
| 6362 | |
| 6363 | }); |
| 6364 | |
| 6365 | // } |
| 6366 | } |
| 6367 | |
| 6368 | // /** |
| 6369 | // * Subscribe to a generic websocket |
no test coverage detected