binance 2.8.14 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/coinm-client.js +5 -5
- package/lib/coinm-client.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/logger.d.ts +1 -1
- package/lib/main-client.js +7 -7
- package/lib/main-client.js.map +1 -1
- package/lib/types/coin.d.ts +2 -2
- package/lib/types/futures.d.ts +13 -13
- package/lib/types/shared.d.ts +27 -27
- package/lib/types/spot.d.ts +20 -20
- package/lib/types/websockets.d.ts +26 -9
- package/lib/usdm-client.js +4 -4
- package/lib/usdm-client.js.map +1 -1
- package/lib/util/BaseRestClient.d.ts +1 -1
- package/lib/util/BaseRestClient.js +8 -5
- package/lib/util/BaseRestClient.js.map +1 -1
- package/lib/util/WsStore.d.ts +2 -2
- package/lib/util/WsStore.js.map +1 -1
- package/lib/util/node-support.js +7 -3
- package/lib/util/node-support.js.map +1 -1
- package/lib/util/requestUtils.d.ts +2 -2
- package/lib/util/requestUtils.js +5 -4
- package/lib/util/requestUtils.js.map +1 -1
- package/lib/util/usdm/index.js +5 -1
- package/lib/util/usdm/index.js.map +1 -1
- package/lib/util/ws-utils.js.map +1 -1
- package/lib/websocket-client.d.ts +4 -4
- package/lib/websocket-client.js +88 -59
- package/lib/websocket-client.js.map +1 -1
- package/package.json +11 -14
package/lib/websocket-client.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -200,15 +204,21 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
206
|
onWsClose(event, wsKey, ws, wsUrl) {
|
|
207
|
+
var _a;
|
|
203
208
|
const wsConnectionState = this.wsStore.getConnectionState(wsKey);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
209
|
+
const { market, listenKey, isUserData } = (0, requestUtils_1.getContextFromWsKey)(wsKey);
|
|
210
|
+
this.logger.info('Websocket connection closed', Object.assign(Object.assign({}, loggerCategory), { wsKey, eventCloseCode: (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a._closeCode, wsConnectionState,
|
|
211
|
+
isUserData,
|
|
212
|
+
listenKey,
|
|
213
|
+
market }));
|
|
214
|
+
// Clear any timers before we initiate revival
|
|
215
|
+
this.clearTimers(wsKey);
|
|
207
216
|
// User data sockets include the listen key. To prevent accummulation in memory we should clean up old disconnected states
|
|
208
|
-
const { isUserData } = requestUtils_1.getContextFromWsKey(wsKey);
|
|
209
217
|
if (isUserData) {
|
|
210
218
|
this.wsStore.delete(wsKey);
|
|
211
|
-
|
|
219
|
+
if (listenKey) {
|
|
220
|
+
this.clearUserDataKeepAliveTimer(listenKey);
|
|
221
|
+
}
|
|
212
222
|
}
|
|
213
223
|
if (wsConnectionState !== WsStore_1.WsConnectionStateEnum.CLOSING) {
|
|
214
224
|
this.reconnectWithDelay(wsKey, this.options.reconnectTimeout, wsUrl);
|
|
@@ -224,19 +234,19 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
224
234
|
this.clearPongTimer(wsKey);
|
|
225
235
|
const msg = parseRawWsMessage(event);
|
|
226
236
|
// Edge case where raw event does not include event type, detect using wsKey and mutate msg.e
|
|
227
|
-
requestUtils_1.appendEventIfMissing(msg, wsKey);
|
|
228
|
-
requestUtils_1.appendEventMarket(msg, wsKey);
|
|
237
|
+
(0, requestUtils_1.appendEventIfMissing)(msg, wsKey);
|
|
238
|
+
(0, requestUtils_1.appendEventMarket)(msg, wsKey);
|
|
229
239
|
const eventType = parseEventTypeFromMessage(msg);
|
|
230
240
|
if (eventType) {
|
|
231
241
|
this.emit('message', msg);
|
|
232
242
|
if (eventType === 'listenKeyExpired') {
|
|
233
|
-
const { market } = requestUtils_1.getContextFromWsKey(wsKey);
|
|
243
|
+
const { market } = (0, requestUtils_1.getContextFromWsKey)(wsKey);
|
|
234
244
|
this.logger.info(`${market} listenKey expired - attempting to respawn user data stream: ${wsKey}`);
|
|
235
245
|
// Just closing the connection (with the last parameter as true) will handle cleanup and respawn
|
|
236
|
-
|
|
246
|
+
const shouldTriggerReconnect = true;
|
|
247
|
+
this.close(wsKey, shouldTriggerReconnect);
|
|
237
248
|
}
|
|
238
249
|
if (this.options.beautify) {
|
|
239
|
-
// call beautifier here and emit separate msg, if enabled
|
|
240
250
|
const beautifiedMessage = this.beautifier.beautifyWsMessage(msg, eventType, false);
|
|
241
251
|
this.emit('formattedMessage', beautifiedMessage);
|
|
242
252
|
// emit a separate event for user data messages
|
|
@@ -251,7 +261,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
251
261
|
'ACCOUNT_UPDATE',
|
|
252
262
|
'MARGIN_CALL',
|
|
253
263
|
'ORDER_TRADE_UPDATE',
|
|
254
|
-
'CONDITIONAL_ORDER_TRIGGER_REJECT'
|
|
264
|
+
'CONDITIONAL_ORDER_TRIGGER_REJECT',
|
|
255
265
|
].includes(eventType)) {
|
|
256
266
|
this.emit('formattedUserDataMessage', beautifiedMessage);
|
|
257
267
|
}
|
|
@@ -283,13 +293,11 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
283
293
|
}
|
|
284
294
|
onWsPing(event, wsKey, ws, source) {
|
|
285
295
|
this.logger.silly('Received ping, sending pong frame', Object.assign(Object.assign({}, loggerCategory), { wsKey,
|
|
286
|
-
event,
|
|
287
296
|
source }));
|
|
288
297
|
ws.pong();
|
|
289
298
|
}
|
|
290
299
|
onWsPong(event, wsKey, source) {
|
|
291
300
|
this.logger.silly('Received pong, clearing pong timer', Object.assign(Object.assign({}, loggerCategory), { wsKey,
|
|
292
|
-
event,
|
|
293
301
|
source }));
|
|
294
302
|
this.clearPongTimer(wsKey);
|
|
295
303
|
}
|
|
@@ -301,8 +309,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
301
309
|
this.logger.info(`${reason} - closing socket to reconnect`, Object.assign(Object.assign({}, loggerCategory), { wsKey,
|
|
302
310
|
reason }));
|
|
303
311
|
const wasOpen = this.wsStore.isWsOpen(wsKey);
|
|
304
|
-
ws_utils_1.safeTerminateWs(this.getWs(wsKey));
|
|
305
|
-
delete this.wsStore.get(wsKey, true).activePongTimer;
|
|
312
|
+
(0, ws_utils_1.safeTerminateWs)(this.getWs(wsKey));
|
|
306
313
|
this.clearPingTimer(wsKey);
|
|
307
314
|
this.clearPongTimer(wsKey);
|
|
308
315
|
if (!wasOpen) {
|
|
@@ -311,35 +318,35 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
311
318
|
this.reconnectWithDelay(wsKey, this.options.reconnectTimeout, wsUrl);
|
|
312
319
|
}
|
|
313
320
|
}
|
|
314
|
-
close(wsKey,
|
|
321
|
+
close(wsKey, shouldReconnectAfterClose) {
|
|
315
322
|
var _a;
|
|
316
|
-
this.logger.info('Closing connection', Object.assign(Object.assign({}, loggerCategory), { wsKey, willReconnect:
|
|
317
|
-
this.setWsState(wsKey,
|
|
323
|
+
this.logger.info('Closing connection', Object.assign(Object.assign({}, loggerCategory), { wsKey, willReconnect: shouldReconnectAfterClose }));
|
|
324
|
+
this.setWsState(wsKey, shouldReconnectAfterClose
|
|
318
325
|
? WsStore_1.WsConnectionStateEnum.RECONNECTING
|
|
319
326
|
: WsStore_1.WsConnectionStateEnum.CLOSING);
|
|
320
327
|
this.clearTimers(wsKey);
|
|
321
328
|
(_a = this.getWs(wsKey)) === null || _a === void 0 ? void 0 : _a.close();
|
|
322
|
-
const { listenKey } = requestUtils_1.getContextFromWsKey(wsKey);
|
|
329
|
+
const { listenKey } = (0, requestUtils_1.getContextFromWsKey)(wsKey);
|
|
323
330
|
if (listenKey) {
|
|
324
331
|
this.teardownUserDataListenKey(listenKey, this.getWs(wsKey));
|
|
325
332
|
}
|
|
326
333
|
else {
|
|
327
|
-
ws_utils_1.safeTerminateWs(this.getWs(wsKey));
|
|
334
|
+
(0, ws_utils_1.safeTerminateWs)(this.getWs(wsKey));
|
|
328
335
|
}
|
|
329
336
|
}
|
|
330
|
-
closeAll(
|
|
337
|
+
closeAll(shouldReconnectAfterClose) {
|
|
331
338
|
const keys = this.wsStore.getKeys();
|
|
332
339
|
this.logger.info(`Closing all ws connections: ${keys}`);
|
|
333
340
|
keys.forEach((key) => {
|
|
334
|
-
this.close(key,
|
|
341
|
+
this.close(key, shouldReconnectAfterClose);
|
|
335
342
|
});
|
|
336
343
|
}
|
|
337
|
-
closeWs(ws,
|
|
344
|
+
closeWs(ws, shouldReconnectAfterClose) {
|
|
338
345
|
const wsKey = this.wsUrlKeyMap[ws.url] || (ws === null || ws === void 0 ? void 0 : ws.wsKey);
|
|
339
346
|
if (!wsKey) {
|
|
340
347
|
throw new Error(`Cannot close websocket as it has no known wsKey attached.`);
|
|
341
348
|
}
|
|
342
|
-
return this.close(wsKey,
|
|
349
|
+
return this.close(wsKey, shouldReconnectAfterClose);
|
|
343
350
|
}
|
|
344
351
|
parseWsError(context, error, wsKey, wsUrl) {
|
|
345
352
|
this.logger.error(context, Object.assign(Object.assign({}, loggerCategory), { wsKey, error }));
|
|
@@ -380,7 +387,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
380
387
|
this.wsStore.get(wsKey, true).activeReconnectTimer = setTimeout(() => {
|
|
381
388
|
this.clearReconnectTimer(wsKey);
|
|
382
389
|
if (wsKey.includes('userData')) {
|
|
383
|
-
const { market, symbol, isTestnet } = requestUtils_1.getContextFromWsKey(wsKey);
|
|
390
|
+
const { market, symbol, isTestnet } = (0, requestUtils_1.getContextFromWsKey)(wsKey);
|
|
384
391
|
this.logger.info('Reconnecting to user data stream', Object.assign(Object.assign({}, loggerCategory), { wsKey,
|
|
385
392
|
market,
|
|
386
393
|
symbol }));
|
|
@@ -433,6 +440,10 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
433
440
|
this.logger.silly(`Clearing old listen key interval timer for ${listenKey}`);
|
|
434
441
|
clearInterval(state.keepAliveTimer);
|
|
435
442
|
}
|
|
443
|
+
if (state.keepAliveRetryTimer) {
|
|
444
|
+
this.logger.silly(`Clearing old listen key keepAliveRetry timer for ${listenKey}`);
|
|
445
|
+
clearTimeout(state.keepAliveRetryTimer);
|
|
446
|
+
}
|
|
436
447
|
}
|
|
437
448
|
getWsBaseUrl(market, wsKey) {
|
|
438
449
|
if (this.options.wsUrl) {
|
|
@@ -544,6 +555,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
544
555
|
market,
|
|
545
556
|
lastKeepAlive: 0,
|
|
546
557
|
keepAliveTimer: undefined,
|
|
558
|
+
keepAliveRetryTimer: undefined,
|
|
547
559
|
keepAliveFailures: 0,
|
|
548
560
|
};
|
|
549
561
|
return this.listenKeyStateStore[listenKey];
|
|
@@ -581,6 +593,10 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
581
593
|
return __awaiter(this, void 0, void 0, function* () {
|
|
582
594
|
const listenKeyState = this.getListenKeyState(listenKey, market);
|
|
583
595
|
try {
|
|
596
|
+
if (listenKeyState.keepAliveRetryTimer) {
|
|
597
|
+
clearTimeout(listenKeyState.keepAliveRetryTimer);
|
|
598
|
+
listenKeyState.keepAliveRetryTimer = undefined;
|
|
599
|
+
}
|
|
584
600
|
// Simple way to test keep alive failure handling:
|
|
585
601
|
// throw new Error(`Fake keep alive failure`);
|
|
586
602
|
yield this.sendKeepAliveForMarket(listenKey, market, ws, wsKey, symbol, isTestnet);
|
|
@@ -590,18 +606,30 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
590
606
|
}
|
|
591
607
|
catch (e) {
|
|
592
608
|
listenKeyState.keepAliveFailures++;
|
|
609
|
+
// code: -1125,
|
|
610
|
+
// message: 'This listenKey does not exist.',
|
|
611
|
+
const errorCode = e === null || e === void 0 ? void 0 : e.code;
|
|
612
|
+
if (errorCode === -1125) {
|
|
613
|
+
this.logger.error('FATAL: Failed to keep WS alive for listen key - listen key expired/invalid. Respawning with fresh listen key...', Object.assign(Object.assign({}, loggerCategory), { listenKey, error: e, errorCode, errorMsg: e === null || e === void 0 ? void 0 : e.message }));
|
|
614
|
+
const shouldReconnectAfterClose = false;
|
|
615
|
+
this.close(wsKey, shouldReconnectAfterClose);
|
|
616
|
+
this.respawnUserDataStream(market, symbol);
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
593
619
|
// If max failurees reached, tear down and respawn if allowed
|
|
594
620
|
if (listenKeyState.keepAliveFailures >= 3) {
|
|
595
621
|
this.logger.error('FATAL: Failed to keep WS alive for listen key after 3 attempts', Object.assign(Object.assign({}, loggerCategory), { listenKey, error: e }));
|
|
596
|
-
// reconnect follows a less automatic workflow
|
|
597
|
-
|
|
598
|
-
|
|
622
|
+
// reconnect follows a less automatic workflow since this is tied to a listen key (which may need a new one).
|
|
623
|
+
// Kill connection first, with instruction NOT to reconnect automatically
|
|
624
|
+
const shouldReconnectAfterClose = false;
|
|
625
|
+
this.close(wsKey, shouldReconnectAfterClose);
|
|
626
|
+
// Then respawn a connection with a potentially new listen key (since the old one may be invalid now)
|
|
599
627
|
this.respawnUserDataStream(market, symbol);
|
|
600
628
|
return;
|
|
601
629
|
}
|
|
602
630
|
const reconnectDelaySeconds = 1000 * 15;
|
|
603
631
|
this.logger.warning(`Userdata keep alive request failed due to error, trying again with short delay (${reconnectDelaySeconds} seconds)`, Object.assign(Object.assign({}, loggerCategory), { listenKey, error: e, keepAliveAttempts: listenKeyState.keepAliveFailures }));
|
|
604
|
-
setTimeout(() => this.checkKeepAliveListenKey(listenKey, market, ws, wsKey, symbol), reconnectDelaySeconds);
|
|
632
|
+
listenKeyState.keepAliveRetryTimer = setTimeout(() => this.checkKeepAliveListenKey(listenKey, market, ws, wsKey, symbol), reconnectDelaySeconds);
|
|
605
633
|
}
|
|
606
634
|
});
|
|
607
635
|
}
|
|
@@ -609,12 +637,13 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
609
637
|
if (listenKey) {
|
|
610
638
|
this.clearUserDataKeepAliveTimer(listenKey);
|
|
611
639
|
delete this.listenKeyStateStore[listenKey];
|
|
612
|
-
ws_utils_1.safeTerminateWs(ws);
|
|
640
|
+
(0, ws_utils_1.safeTerminateWs)(ws);
|
|
613
641
|
}
|
|
614
642
|
}
|
|
615
643
|
respawnUserDataStream(market, symbol, isTestnet, respawnAttempt) {
|
|
616
644
|
return __awaiter(this, void 0, void 0, function* () {
|
|
617
|
-
|
|
645
|
+
// If another connection attempt is in progress for this listen key, don't initiate a retry or the risk is multiple connections on the same listen key
|
|
646
|
+
const forceNewConnection = false;
|
|
618
647
|
const isReconnecting = true;
|
|
619
648
|
let ws;
|
|
620
649
|
try {
|
|
@@ -642,7 +671,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
642
671
|
break;
|
|
643
672
|
case 'options':
|
|
644
673
|
case 'optionsTestnet':
|
|
645
|
-
throw new Error('TODO: respawn other user data streams once subscribe methods have been
|
|
674
|
+
throw new Error('TODO: respawn other user data streams once subscribe methods have been added');
|
|
646
675
|
default:
|
|
647
676
|
throwUnhandledSwitch(market, `Failed to respawn user data stream - unhandled market: ${market}`);
|
|
648
677
|
}
|
|
@@ -673,7 +702,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
673
702
|
* Subscribe to a universal market websocket stream
|
|
674
703
|
*/
|
|
675
704
|
subscribeEndpoint(endpoint, market, forceNewConnection) {
|
|
676
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, endpoint);
|
|
705
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, endpoint);
|
|
677
706
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${endpoint}`, wsKey, forceNewConnection);
|
|
678
707
|
}
|
|
679
708
|
/**
|
|
@@ -682,7 +711,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
682
711
|
subscribeAggregateTrades(symbol, market, forceNewConnection) {
|
|
683
712
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
684
713
|
const streamName = 'aggTrade';
|
|
685
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
714
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
686
715
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${lowerCaseSymbol}@${streamName}`, wsKey, forceNewConnection);
|
|
687
716
|
}
|
|
688
717
|
/**
|
|
@@ -692,7 +721,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
692
721
|
subscribeTrades(symbol, market, forceNewConnection) {
|
|
693
722
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
694
723
|
const streamName = 'trade';
|
|
695
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
724
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
696
725
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${lowerCaseSymbol}@${streamName}`, wsKey, forceNewConnection);
|
|
697
726
|
}
|
|
698
727
|
/**
|
|
@@ -703,7 +732,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
703
732
|
const streamName = 'indexPrice';
|
|
704
733
|
const speedSuffix = updateSpeedMs === 1000 ? '@1s' : '';
|
|
705
734
|
const market = 'coinm';
|
|
706
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
735
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
707
736
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
708
737
|
`/ws/${lowerCaseSymbol}@${streamName}${speedSuffix}`, wsKey, forceNewConnection);
|
|
709
738
|
}
|
|
@@ -714,7 +743,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
714
743
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
715
744
|
const streamName = 'markPrice';
|
|
716
745
|
const speedSuffix = updateSpeedMs === 1000 ? '@1s' : '';
|
|
717
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
746
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
718
747
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
719
748
|
`/ws/${lowerCaseSymbol}@${streamName}${speedSuffix}`, wsKey, forceNewConnection);
|
|
720
749
|
}
|
|
@@ -724,7 +753,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
724
753
|
subscribeAllMarketMarkPrice(market, updateSpeedMs = 3000, forceNewConnection) {
|
|
725
754
|
const streamName = '!markPrice@arr';
|
|
726
755
|
const speedSuffix = updateSpeedMs === 1000 ? '@1s' : '';
|
|
727
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName);
|
|
756
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName);
|
|
728
757
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${streamName}${speedSuffix}`, wsKey, forceNewConnection);
|
|
729
758
|
}
|
|
730
759
|
/**
|
|
@@ -733,7 +762,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
733
762
|
subscribeKlines(symbol, interval, market, forceNewConnection) {
|
|
734
763
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
735
764
|
const streamName = 'kline';
|
|
736
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol, interval);
|
|
765
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol, interval);
|
|
737
766
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
738
767
|
`/ws/${lowerCaseSymbol}@${streamName}_${interval}`, wsKey, forceNewConnection);
|
|
739
768
|
}
|
|
@@ -743,7 +772,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
743
772
|
subscribeContinuousContractKlines(symbol, contractType, interval, market, forceNewConnection) {
|
|
744
773
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
745
774
|
const streamName = 'continuousKline';
|
|
746
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol, interval);
|
|
775
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol, interval);
|
|
747
776
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
748
777
|
`/ws/${lowerCaseSymbol}_${contractType}@${streamName}_${interval}`, wsKey, forceNewConnection);
|
|
749
778
|
}
|
|
@@ -754,7 +783,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
754
783
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
755
784
|
const streamName = 'indexPriceKline';
|
|
756
785
|
const market = 'coinm';
|
|
757
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol, interval);
|
|
786
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol, interval);
|
|
758
787
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
759
788
|
`/ws/${lowerCaseSymbol}@${streamName}_${interval}`, wsKey, forceNewConnection);
|
|
760
789
|
}
|
|
@@ -765,7 +794,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
765
794
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
766
795
|
const streamName = 'markPrice_kline';
|
|
767
796
|
const market = 'coinm';
|
|
768
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol, interval);
|
|
797
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol, interval);
|
|
769
798
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
770
799
|
`/ws/${lowerCaseSymbol}@${streamName}_${interval}`, wsKey, forceNewConnection);
|
|
771
800
|
}
|
|
@@ -775,7 +804,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
775
804
|
subscribeSymbolMini24hrTicker(symbol, market, forceNewConnection) {
|
|
776
805
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
777
806
|
const streamName = 'miniTicker';
|
|
778
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
807
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
779
808
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${lowerCaseSymbol}@${streamName}`, wsKey, forceNewConnection);
|
|
780
809
|
}
|
|
781
810
|
/**
|
|
@@ -783,7 +812,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
783
812
|
*/
|
|
784
813
|
subscribeAllMini24hrTickers(market, forceNewConnection) {
|
|
785
814
|
const streamName = 'miniTicker';
|
|
786
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName);
|
|
815
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName);
|
|
787
816
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/!${streamName}@arr`, wsKey, forceNewConnection);
|
|
788
817
|
}
|
|
789
818
|
/**
|
|
@@ -792,7 +821,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
792
821
|
subscribeSymbol24hrTicker(symbol, market, forceNewConnection) {
|
|
793
822
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
794
823
|
const streamName = 'ticker';
|
|
795
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
824
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
796
825
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${lowerCaseSymbol}@${streamName}`, wsKey, forceNewConnection);
|
|
797
826
|
}
|
|
798
827
|
/**
|
|
@@ -800,7 +829,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
800
829
|
*/
|
|
801
830
|
subscribeAll24hrTickers(market, forceNewConnection) {
|
|
802
831
|
const streamName = 'ticker';
|
|
803
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName);
|
|
832
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName);
|
|
804
833
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/!${streamName}@arr`, wsKey, forceNewConnection);
|
|
805
834
|
}
|
|
806
835
|
/**
|
|
@@ -814,7 +843,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
814
843
|
*/
|
|
815
844
|
subscribeAllRollingWindowTickers(market, windowSize, forceNewConnection) {
|
|
816
845
|
const streamName = 'ticker';
|
|
817
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, windowSize);
|
|
846
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, windowSize);
|
|
818
847
|
const wsUrl = this.getWsBaseUrl(market, wsKey) + `/ws/!${streamName}_${windowSize}@arr`;
|
|
819
848
|
return this.connectToWsUrl(wsUrl, wsKey, forceNewConnection);
|
|
820
849
|
}
|
|
@@ -824,7 +853,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
824
853
|
subscribeSymbolBookTicker(symbol, market, forceNewConnection) {
|
|
825
854
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
826
855
|
const streamName = 'bookTicker';
|
|
827
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
856
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
828
857
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${lowerCaseSymbol}@${streamName}`, wsKey, forceNewConnection);
|
|
829
858
|
}
|
|
830
859
|
/**
|
|
@@ -832,7 +861,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
832
861
|
*/
|
|
833
862
|
subscribeAllBookTickers(market, forceNewConnection) {
|
|
834
863
|
const streamName = 'bookTicker';
|
|
835
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName);
|
|
864
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName);
|
|
836
865
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/!${streamName}`, wsKey, forceNewConnection);
|
|
837
866
|
}
|
|
838
867
|
/**
|
|
@@ -841,7 +870,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
841
870
|
subscribeSymbolLiquidationOrders(symbol, market, forceNewConnection) {
|
|
842
871
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
843
872
|
const streamName = 'forceOrder';
|
|
844
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
873
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
845
874
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/${lowerCaseSymbol}@${streamName}`, wsKey, forceNewConnection);
|
|
846
875
|
}
|
|
847
876
|
/**
|
|
@@ -849,7 +878,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
849
878
|
*/
|
|
850
879
|
subscribeAllLiquidationOrders(market, forceNewConnection) {
|
|
851
880
|
const streamName = 'forceOrder@arr';
|
|
852
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName);
|
|
881
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName);
|
|
853
882
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) + `/ws/!${streamName}`, wsKey, forceNewConnection);
|
|
854
883
|
}
|
|
855
884
|
/**
|
|
@@ -858,7 +887,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
858
887
|
subscribePartialBookDepths(symbol, levels, updateMs, market, forceNewConnection) {
|
|
859
888
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
860
889
|
const streamName = 'depth';
|
|
861
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, streamName, lowerCaseSymbol);
|
|
890
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, streamName, lowerCaseSymbol);
|
|
862
891
|
const updateMsSuffx = updateMs === 100 ? `@${updateMs}ms` : '';
|
|
863
892
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
864
893
|
`/ws/${lowerCaseSymbol}@${streamName}${levels}${updateMsSuffx}`, wsKey, forceNewConnection);
|
|
@@ -869,7 +898,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
869
898
|
subscribeDiffBookDepth(symbol, updateMs = 1000, market, forceNewConnection) {
|
|
870
899
|
const lowerCaseSymbol = symbol.toLowerCase();
|
|
871
900
|
const streamName = 'depth';
|
|
872
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, 'diffBookDepth', lowerCaseSymbol, String(updateMs));
|
|
901
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, 'diffBookDepth', lowerCaseSymbol, String(updateMs));
|
|
873
902
|
const updateMsSuffx = updateMs === 100 ? `@${updateMs}ms` : '';
|
|
874
903
|
return this.connectToWsUrl(this.getWsBaseUrl(market, wsKey) +
|
|
875
904
|
`/ws/${lowerCaseSymbol}@${streamName}${updateMsSuffx}`, wsKey, forceNewConnection);
|
|
@@ -951,7 +980,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
951
980
|
*/
|
|
952
981
|
subscribeSpotUserDataStreamWithListenKey(listenKey, forceNewConnection, isReconnecting) {
|
|
953
982
|
const market = 'spot';
|
|
954
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, 'userData', undefined, listenKey);
|
|
983
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, 'userData', undefined, listenKey);
|
|
955
984
|
if (!forceNewConnection && this.wsStore.isWsConnecting(wsKey)) {
|
|
956
985
|
this.logger.silly('Existing spot user data connection in progress for listen key. Avoiding duplicate');
|
|
957
986
|
return this.getWs(wsKey);
|
|
@@ -987,7 +1016,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
987
1016
|
try {
|
|
988
1017
|
const { listenKey } = yield this.getSpotRestClient().getMarginUserDataListenKey();
|
|
989
1018
|
const market = 'margin';
|
|
990
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, 'userData', undefined, listenKey);
|
|
1019
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, 'userData', undefined, listenKey);
|
|
991
1020
|
if (!forceNewConnection && this.wsStore.isWsConnecting(wsKey)) {
|
|
992
1021
|
this.logger.silly('Existing margin user data connection in progress for listen key. Avoiding duplicate');
|
|
993
1022
|
return this.getWs(wsKey);
|
|
@@ -1017,7 +1046,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
1017
1046
|
symbol: lowerCaseSymbol,
|
|
1018
1047
|
});
|
|
1019
1048
|
const market = 'isolatedMargin';
|
|
1020
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, 'userData', lowerCaseSymbol, listenKey);
|
|
1049
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, 'userData', lowerCaseSymbol, listenKey);
|
|
1021
1050
|
if (!forceNewConnection && this.wsStore.isWsConnecting(wsKey)) {
|
|
1022
1051
|
this.logger.silly('Existing isolated margin user data connection in progress for listen key. Avoiding duplicate');
|
|
1023
1052
|
return this.getWs(wsKey);
|
|
@@ -1053,7 +1082,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
1053
1082
|
const restClient = this.getUSDMRestClient(isTestnet);
|
|
1054
1083
|
const { listenKey } = yield restClient.getFuturesUserDataListenKey();
|
|
1055
1084
|
const market = isTestnet ? 'usdmTestnet' : 'usdm';
|
|
1056
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, 'userData', undefined, listenKey);
|
|
1085
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, 'userData', undefined, listenKey);
|
|
1057
1086
|
if (!forceNewConnection && this.wsStore.isWsConnecting(wsKey)) {
|
|
1058
1087
|
this.logger.silly('Existing usd futures user data connection in progress for listen key. Avoiding duplicate');
|
|
1059
1088
|
return this.getWs(wsKey);
|
|
@@ -1081,7 +1110,7 @@ class WebsocketClient extends events_1.EventEmitter {
|
|
|
1081
1110
|
try {
|
|
1082
1111
|
const { listenKey } = yield this.getCOINMRestClient(isTestnet).getFuturesUserDataListenKey();
|
|
1083
1112
|
const market = isTestnet ? 'coinmTestnet' : 'coinm';
|
|
1084
|
-
const wsKey = requestUtils_1.getWsKeyWithContext(market, 'userData', undefined, listenKey);
|
|
1113
|
+
const wsKey = (0, requestUtils_1.getWsKeyWithContext)(market, 'userData', undefined, listenKey);
|
|
1085
1114
|
if (!forceNewConnection && this.wsStore.isWsConnecting(wsKey)) {
|
|
1086
1115
|
this.logger.silly('Existing usd futures user data connection in progress for listen key. Avoiding duplicate');
|
|
1087
1116
|
return this.getWs(wsKey);
|