@binance/common 1.0.0 → 1.0.2
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/dist/index.d.mts +9 -28
- package/dist/index.d.ts +9 -28
- package/dist/index.js +69 -137
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -2
package/dist/index.mjs
CHANGED
|
@@ -61,26 +61,12 @@ var TimeUnit = {
|
|
|
61
61
|
MICROSECOND: "MICROSECOND",
|
|
62
62
|
microsecond: "microsecond"
|
|
63
63
|
};
|
|
64
|
-
var SPOT_REST_API_PROD_URL = "https://api.binance.com";
|
|
65
|
-
var SPOT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
66
|
-
var SPOT_WS_API_PROD_URL = "wss://ws-api.binance.com:443/ws-api/v3";
|
|
67
|
-
var SPOT_WS_API_TESTNET_URL = "wss://ws-api.testnet.binance.vision/ws-api/v3";
|
|
68
|
-
var SPOT_WS_STREAMS_PROD_URL = "wss://stream.binance.com:9443";
|
|
69
|
-
var SPOT_WS_STREAMS_TESTNET_URL = "wss://stream.testnet.binance.vision";
|
|
70
|
-
var SPOT_REST_API_MARKET_URL = "https://data-api.binance.vision";
|
|
71
|
-
var SPOT_WS_STREAMS_MARKET_URL = "wss://data-stream.binance.vision";
|
|
72
64
|
var ALGO_REST_API_PROD_URL = "https://api.binance.com";
|
|
73
|
-
var ALGO_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
74
65
|
var AUTO_INVEST_REST_API_PROD_URL = "https://api.binance.com";
|
|
75
|
-
var AUTO_INVEST_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
76
66
|
var C2C_REST_API_PROD_URL = "https://api.binance.com";
|
|
77
|
-
var C2C_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
78
67
|
var CONVERT_REST_API_PROD_URL = "https://api.binance.com";
|
|
79
|
-
var CONVERT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
80
68
|
var COPY_TRADING_REST_API_PROD_URL = "https://api.binance.com";
|
|
81
|
-
var COPY_TRADING_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
82
69
|
var CRYPTO_LOAN_REST_API_PROD_URL = "https://api.binance.com";
|
|
83
|
-
var CRYPTO_LOAN_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
84
70
|
var DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL = "https://dapi.binance.com";
|
|
85
71
|
var DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
|
|
86
72
|
var DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL = "wss://ws-dapi.binance.com/ws-dapi/v1";
|
|
@@ -100,31 +86,26 @@ var DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL = "https://testnet
|
|
|
100
86
|
var DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL = "https://fapi.binance.com";
|
|
101
87
|
var DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
|
|
102
88
|
var DUAL_INVESTMENT_REST_API_PROD_URL = "https://api.binance.com";
|
|
103
|
-
var DUAL_INVESTMENT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
104
89
|
var FIAT_REST_API_PROD_URL = "https://api.binance.com";
|
|
105
|
-
var FIAT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
106
90
|
var GIFT_CARD_REST_API_PROD_URL = "https://api.binance.com";
|
|
107
|
-
var GIFT_CARD_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
108
91
|
var MARGIN_TRADING_REST_API_PROD_URL = "https://api.binance.com";
|
|
109
|
-
var MARGIN_TRADING_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
110
92
|
var MINING_REST_API_PROD_URL = "https://api.binance.com";
|
|
111
|
-
var MINING_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
112
93
|
var NFT_REST_API_PROD_URL = "https://api.binance.com";
|
|
113
|
-
var NFT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
114
94
|
var PAY_REST_API_PROD_URL = "https://api.binance.com";
|
|
115
|
-
var PAY_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
116
95
|
var REBATE_REST_API_PROD_URL = "https://api.binance.com";
|
|
117
|
-
var REBATE_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
118
96
|
var SIMPLE_EARN_REST_API_PROD_URL = "https://api.binance.com";
|
|
119
|
-
var
|
|
97
|
+
var SPOT_REST_API_PROD_URL = "https://api.binance.com";
|
|
98
|
+
var SPOT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
99
|
+
var SPOT_WS_API_PROD_URL = "wss://ws-api.binance.com:443/ws-api/v3";
|
|
100
|
+
var SPOT_WS_API_TESTNET_URL = "wss://ws-api.testnet.binance.vision/ws-api/v3";
|
|
101
|
+
var SPOT_WS_STREAMS_PROD_URL = "wss://stream.binance.com:9443";
|
|
102
|
+
var SPOT_WS_STREAMS_TESTNET_URL = "wss://stream.testnet.binance.vision";
|
|
103
|
+
var SPOT_REST_API_MARKET_URL = "https://data-api.binance.vision";
|
|
104
|
+
var SPOT_WS_STREAMS_MARKET_URL = "wss://data-stream.binance.vision";
|
|
120
105
|
var STAKING_REST_API_PROD_URL = "https://api.binance.com";
|
|
121
|
-
var STAKING_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
122
106
|
var SUB_ACCOUNT_REST_API_PROD_URL = "https://api.binance.com";
|
|
123
|
-
var SUB_ACCOUNT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
124
107
|
var VIP_LOAN_REST_API_PROD_URL = "https://api.binance.com";
|
|
125
|
-
var VIP_LOAN_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
126
108
|
var WALLET_REST_API_PROD_URL = "https://api.binance.com";
|
|
127
|
-
var WALLET_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
128
109
|
|
|
129
110
|
// src/errors.ts
|
|
130
111
|
var ConnectorClientError = class _ConnectorClientError extends Error {
|
|
@@ -270,8 +251,7 @@ import fs from "fs";
|
|
|
270
251
|
import https from "https";
|
|
271
252
|
import globalAxios from "axios";
|
|
272
253
|
function buildQueryString(params) {
|
|
273
|
-
if (!params)
|
|
274
|
-
return "";
|
|
254
|
+
if (!params) return "";
|
|
275
255
|
return Object.entries(params).map(stringifyKeyValuePair).join("&");
|
|
276
256
|
}
|
|
277
257
|
function stringifyKeyValuePair([key, value]) {
|
|
@@ -339,8 +319,7 @@ var assertParamExists = function(functionName, paramName, paramValue) {
|
|
|
339
319
|
}
|
|
340
320
|
};
|
|
341
321
|
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
|
|
342
|
-
if (parameter == null)
|
|
343
|
-
return;
|
|
322
|
+
if (parameter == null) return;
|
|
344
323
|
if (typeof parameter === "object") {
|
|
345
324
|
if (Array.isArray(parameter)) {
|
|
346
325
|
parameter.forEach((item) => setFlattenedQueryParams(urlSearchParams, item, key));
|
|
@@ -396,6 +375,7 @@ var httpRequestFunction = async function(axiosArgs, configuration) {
|
|
|
396
375
|
const retries = configuration?.retries ?? 0;
|
|
397
376
|
const backoff = configuration?.backoff ?? 0;
|
|
398
377
|
let attempt = 0;
|
|
378
|
+
let lastError;
|
|
399
379
|
while (attempt <= retries) {
|
|
400
380
|
try {
|
|
401
381
|
const response = await globalAxios.request({
|
|
@@ -411,50 +391,59 @@ var httpRequestFunction = async function(axiosArgs, configuration) {
|
|
|
411
391
|
};
|
|
412
392
|
} catch (error) {
|
|
413
393
|
attempt++;
|
|
394
|
+
const axiosError = error;
|
|
414
395
|
if (shouldRetryRequest(
|
|
415
|
-
|
|
396
|
+
axiosError,
|
|
416
397
|
axiosRequestArgs?.method?.toUpperCase(),
|
|
417
398
|
retries - attempt
|
|
418
399
|
)) {
|
|
419
400
|
await delay(backoff * attempt);
|
|
420
401
|
} else {
|
|
421
|
-
if (
|
|
422
|
-
const status =
|
|
423
|
-
const
|
|
424
|
-
|
|
425
|
-
)
|
|
402
|
+
if (axiosError.response && axiosError.response.status) {
|
|
403
|
+
const status = axiosError.response?.status;
|
|
404
|
+
const responseData = axiosError.response.data;
|
|
405
|
+
let data = {};
|
|
406
|
+
if (responseData && responseData !== null) {
|
|
407
|
+
if (typeof responseData === "string" && responseData !== "")
|
|
408
|
+
data = JSON.parse(responseData);
|
|
409
|
+
else if (typeof responseData === "object")
|
|
410
|
+
data = responseData;
|
|
411
|
+
}
|
|
412
|
+
const errorMsg = data.msg;
|
|
426
413
|
switch (status) {
|
|
427
414
|
case 400:
|
|
428
|
-
throw new BadRequestError(
|
|
415
|
+
throw new BadRequestError(errorMsg);
|
|
429
416
|
case 401:
|
|
430
|
-
throw new UnauthorizedError(
|
|
417
|
+
throw new UnauthorizedError(errorMsg);
|
|
431
418
|
case 403:
|
|
432
|
-
throw new ForbiddenError(
|
|
419
|
+
throw new ForbiddenError(errorMsg);
|
|
433
420
|
case 404:
|
|
434
|
-
throw new NotFoundError(
|
|
421
|
+
throw new NotFoundError(errorMsg);
|
|
435
422
|
case 418:
|
|
436
|
-
throw new RateLimitBanError(
|
|
423
|
+
throw new RateLimitBanError(errorMsg);
|
|
437
424
|
case 429:
|
|
438
|
-
throw new TooManyRequestsError(
|
|
425
|
+
throw new TooManyRequestsError(errorMsg);
|
|
439
426
|
default:
|
|
440
427
|
if (status >= 500 && status < 600)
|
|
441
428
|
throw new ServerError(`Server error: ${status}`, status);
|
|
442
|
-
throw new ConnectorClientError(
|
|
429
|
+
throw new ConnectorClientError(errorMsg);
|
|
443
430
|
}
|
|
444
431
|
} else {
|
|
445
|
-
|
|
432
|
+
if (retries > 0 && attempt >= retries)
|
|
433
|
+
lastError = new Error(`Request failed after ${retries} retries`);
|
|
434
|
+
else lastError = new NetworkError("Network error or request timeout.");
|
|
435
|
+
break;
|
|
446
436
|
}
|
|
447
437
|
}
|
|
448
438
|
}
|
|
449
439
|
}
|
|
450
|
-
throw
|
|
440
|
+
throw lastError;
|
|
451
441
|
};
|
|
452
442
|
var parseRateLimitHeaders = function(headers) {
|
|
453
443
|
const rateLimits = [];
|
|
454
444
|
const parseIntervalDetails = (key) => {
|
|
455
445
|
const match = key.match(/x-mbx-used-weight-(\d+)([smhd])|x-mbx-order-count-(\d+)([smhd])/i);
|
|
456
|
-
if (!match)
|
|
457
|
-
return null;
|
|
446
|
+
if (!match) return null;
|
|
458
447
|
const intervalNum = parseInt(match[1] || match[3], 10);
|
|
459
448
|
const intervalLetter = (match[2] || match[4])?.toUpperCase();
|
|
460
449
|
let interval;
|
|
@@ -478,8 +467,7 @@ var parseRateLimitHeaders = function(headers) {
|
|
|
478
467
|
};
|
|
479
468
|
for (const [key, value] of Object.entries(headers)) {
|
|
480
469
|
const normalizedKey = key.toLowerCase();
|
|
481
|
-
if (value === void 0)
|
|
482
|
-
continue;
|
|
470
|
+
if (value === void 0) continue;
|
|
483
471
|
if (normalizedKey.startsWith("x-mbx-used-weight-")) {
|
|
484
472
|
const details = parseIntervalDetails(normalizedKey);
|
|
485
473
|
if (details) {
|
|
@@ -542,8 +530,7 @@ var sendRequest = function(configuration, endpoint, method, params = {}, timeUni
|
|
|
542
530
|
);
|
|
543
531
|
};
|
|
544
532
|
function removeEmptyValue(obj) {
|
|
545
|
-
if (!(obj instanceof Object))
|
|
546
|
-
return {};
|
|
533
|
+
if (!(obj instanceof Object)) return {};
|
|
547
534
|
return Object.fromEntries(
|
|
548
535
|
Object.entries(obj).filter(
|
|
549
536
|
([, value]) => value !== null && value !== void 0 && value !== ""
|
|
@@ -559,12 +546,13 @@ function sortObject(obj) {
|
|
|
559
546
|
function replaceWebsocketStreamsPlaceholders(str, variables) {
|
|
560
547
|
const normalizedVariables = Object.keys(variables).reduce(
|
|
561
548
|
(acc, key) => {
|
|
562
|
-
|
|
549
|
+
const normalizedKey = key.toLowerCase().replace(/[-_]/g, "");
|
|
550
|
+
acc[normalizedKey] = variables[key];
|
|
563
551
|
return acc;
|
|
564
552
|
},
|
|
565
553
|
{}
|
|
566
554
|
);
|
|
567
|
-
return str.replace(
|
|
555
|
+
return str.replace(/(@)?<([^>]+)>/g, (match, precedingAt, fieldName) => {
|
|
568
556
|
const normalizedFieldName = fieldName.toLowerCase().replace(/[-_]/g, "");
|
|
569
557
|
if (Object.prototype.hasOwnProperty.call(normalizedVariables, normalizedFieldName) && normalizedVariables[normalizedFieldName] != null) {
|
|
570
558
|
const value = normalizedVariables[normalizedFieldName];
|
|
@@ -575,7 +563,7 @@ function replaceWebsocketStreamsPlaceholders(str, variables) {
|
|
|
575
563
|
case "updatespeed":
|
|
576
564
|
return `@${value}`;
|
|
577
565
|
default:
|
|
578
|
-
return value;
|
|
566
|
+
return (precedingAt || "") + value;
|
|
579
567
|
}
|
|
580
568
|
}
|
|
581
569
|
return "";
|
|
@@ -621,7 +609,7 @@ var WebsocketEventEmitter = class {
|
|
|
621
609
|
this.eventEmitter.emit(event, ...args);
|
|
622
610
|
}
|
|
623
611
|
};
|
|
624
|
-
var
|
|
612
|
+
var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
625
613
|
constructor(configuration, connectionPool = []) {
|
|
626
614
|
super();
|
|
627
615
|
this.configuration = configuration;
|
|
@@ -633,8 +621,10 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
633
621
|
this.connectionPool = connectionPool;
|
|
634
622
|
this.mode = this.configuration?.mode ?? "single";
|
|
635
623
|
this.poolSize = this.mode === "pool" && this.configuration?.poolSize ? this.configuration.poolSize : 1;
|
|
636
|
-
if (!connectionPool || connectionPool.length === 0)
|
|
637
|
-
|
|
624
|
+
if (!connectionPool || connectionPool.length === 0) this.initializePool(this.poolSize);
|
|
625
|
+
}
|
|
626
|
+
static {
|
|
627
|
+
this.MAX_CONNECTION_DURATION = 23 * 60 * 60 * 1e3;
|
|
638
628
|
}
|
|
639
629
|
/**
|
|
640
630
|
* Initializes the WebSocket connection pool by creating a specified number of connection objects
|
|
@@ -666,8 +656,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
666
656
|
* @returns {WebsocketConnection} The selected WebSocket connection.
|
|
667
657
|
*/
|
|
668
658
|
getConnection(allowNonEstablishedWebsockets = false) {
|
|
669
|
-
if (this.mode === "single")
|
|
670
|
-
return this.connectionPool[0];
|
|
659
|
+
if (this.mode === "single") return this.connectionPool[0];
|
|
671
660
|
const availableConnections = this.connectionPool.filter(
|
|
672
661
|
(connection) => this.isConnectionReady(connection, allowNonEstablishedWebsockets)
|
|
673
662
|
);
|
|
@@ -712,10 +701,8 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
712
701
|
const timers = this.connectionTimers.get(connection);
|
|
713
702
|
if (timers) {
|
|
714
703
|
timers.forEach(({ timer, type }) => {
|
|
715
|
-
if (type === "timeout")
|
|
716
|
-
|
|
717
|
-
else if (type === "interval")
|
|
718
|
-
clearInterval(timer);
|
|
704
|
+
if (type === "timeout") clearTimeout(timer);
|
|
705
|
+
else if (type === "interval") clearInterval(timer);
|
|
719
706
|
});
|
|
720
707
|
this.connectionTimers.delete(connection);
|
|
721
708
|
}
|
|
@@ -731,8 +718,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
731
718
|
* @returns A Promise that resolves when the queue has been fully processed.
|
|
732
719
|
*/
|
|
733
720
|
async processQueue(throttleRate = 1e3) {
|
|
734
|
-
if (this.queueProcessing)
|
|
735
|
-
return;
|
|
721
|
+
if (this.queueProcessing) return;
|
|
736
722
|
this.queueProcessing = true;
|
|
737
723
|
while (this.connectionQueue.length > 0) {
|
|
738
724
|
const { connection, url, isRenewal } = this.connectionQueue.shift();
|
|
@@ -765,8 +751,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
765
751
|
* @returns Promise that resolves when the connection is closed.
|
|
766
752
|
*/
|
|
767
753
|
async closeConnectionGracefully(WebsocketConnectionToClose, connection) {
|
|
768
|
-
if (!WebsocketConnectionToClose || !connection)
|
|
769
|
-
return;
|
|
754
|
+
if (!WebsocketConnectionToClose || !connection) return;
|
|
770
755
|
this.logger.debug("Waiting for pending requests to complete before disconnecting.");
|
|
771
756
|
const closePromise = new Promise((resolve) => {
|
|
772
757
|
this.scheduleTimer(
|
|
@@ -899,10 +884,8 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
899
884
|
this.logger.info(
|
|
900
885
|
`Establishing Websocket connection with id ${targetConnection.id} to: ${url}`
|
|
901
886
|
);
|
|
902
|
-
if (isRenewal)
|
|
903
|
-
|
|
904
|
-
else
|
|
905
|
-
targetConnection.ws = ws;
|
|
887
|
+
if (isRenewal) targetConnection.renewalPending = true;
|
|
888
|
+
else targetConnection.ws = ws;
|
|
906
889
|
this.scheduleTimer(
|
|
907
890
|
ws,
|
|
908
891
|
() => {
|
|
@@ -917,8 +900,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
917
900
|
);
|
|
918
901
|
ws.on("open", () => {
|
|
919
902
|
const oldWSConnection = targetConnection.ws;
|
|
920
|
-
if (targetConnection.renewalPending)
|
|
921
|
-
targetConnection.ws = ws;
|
|
903
|
+
if (targetConnection.renewalPending) targetConnection.ws = ws;
|
|
922
904
|
this.onOpen(url, targetConnection, oldWSConnection);
|
|
923
905
|
});
|
|
924
906
|
ws.on("message", (data) => {
|
|
@@ -982,8 +964,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
982
964
|
* @throws Error if the WebSocket client is not set.
|
|
983
965
|
*/
|
|
984
966
|
async disconnect() {
|
|
985
|
-
if (!this.isConnected())
|
|
986
|
-
this.logger.warn("No connection to close.");
|
|
967
|
+
if (!this.isConnected()) this.logger.warn("No connection to close.");
|
|
987
968
|
else {
|
|
988
969
|
this.connectionPool.forEach((connection) => {
|
|
989
970
|
connection.closeInitiated = true;
|
|
@@ -1033,25 +1014,20 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1033
1014
|
if (!this.isConnected(connection)) {
|
|
1034
1015
|
const errorMsg = "Send can only be sent when connection is ready.";
|
|
1035
1016
|
this.logger.warn(errorMsg);
|
|
1036
|
-
if (promiseBased)
|
|
1037
|
-
|
|
1038
|
-
else
|
|
1039
|
-
throw new Error(errorMsg);
|
|
1017
|
+
if (promiseBased) return Promise.reject(new Error(errorMsg));
|
|
1018
|
+
else throw new Error(errorMsg);
|
|
1040
1019
|
}
|
|
1041
1020
|
const connectionToUse = connection ?? this.getConnection();
|
|
1042
1021
|
if (!connectionToUse.ws) {
|
|
1043
1022
|
const errorMsg = "Websocket Client not set";
|
|
1044
1023
|
this.logger.error(errorMsg);
|
|
1045
|
-
if (promiseBased)
|
|
1046
|
-
|
|
1047
|
-
else
|
|
1048
|
-
throw new Error(errorMsg);
|
|
1024
|
+
if (promiseBased) return Promise.reject(new Error(errorMsg));
|
|
1025
|
+
else throw new Error(errorMsg);
|
|
1049
1026
|
}
|
|
1050
1027
|
connectionToUse.ws.send(payload);
|
|
1051
1028
|
if (promiseBased) {
|
|
1052
1029
|
return new Promise((resolve, reject) => {
|
|
1053
|
-
if (!id)
|
|
1054
|
-
return reject(new Error("id is required for promise-based sending."));
|
|
1030
|
+
if (!id) return reject(new Error("id is required for promise-based sending."));
|
|
1055
1031
|
connectionToUse.pendingRequests.set(id, { resolve, reject });
|
|
1056
1032
|
this.scheduleTimer(
|
|
1057
1033
|
connectionToUse.ws,
|
|
@@ -1067,8 +1043,6 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1067
1043
|
}
|
|
1068
1044
|
}
|
|
1069
1045
|
};
|
|
1070
|
-
_WebsocketCommon.MAX_CONNECTION_DURATION = 23 * 60 * 60 * 1e3;
|
|
1071
|
-
var WebsocketCommon = _WebsocketCommon;
|
|
1072
1046
|
var WebsocketAPIBase = class extends WebsocketCommon {
|
|
1073
1047
|
constructor(configuration, connectionPool = []) {
|
|
1074
1048
|
super(configuration, connectionPool);
|
|
@@ -1108,8 +1082,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1108
1082
|
request?.reject(message.error);
|
|
1109
1083
|
} else {
|
|
1110
1084
|
const response = { data: message.result };
|
|
1111
|
-
if (message?.rateLimits)
|
|
1112
|
-
response.rateLimits = message.rateLimits;
|
|
1085
|
+
if (message?.rateLimits) response.rateLimits = message.rateLimits;
|
|
1113
1086
|
request?.resolve(response);
|
|
1114
1087
|
}
|
|
1115
1088
|
} else {
|
|
@@ -1131,8 +1104,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1131
1104
|
return Promise.resolve();
|
|
1132
1105
|
}
|
|
1133
1106
|
return new Promise((resolve, reject) => {
|
|
1134
|
-
if (this.isConnecting)
|
|
1135
|
-
return;
|
|
1107
|
+
if (this.isConnecting) return;
|
|
1136
1108
|
this.isConnecting = true;
|
|
1137
1109
|
const timeout = setTimeout(() => {
|
|
1138
1110
|
this.isConnecting = false;
|
|
@@ -1228,15 +1200,13 @@ var WebsocketStreamsBase2 = class extends WebsocketCommon {
|
|
|
1228
1200
|
handleStreamAssignment(streams) {
|
|
1229
1201
|
const connectionStreamMap = /* @__PURE__ */ new Map();
|
|
1230
1202
|
streams.forEach((stream) => {
|
|
1231
|
-
if (!this.streamCallbackMap.has(stream))
|
|
1232
|
-
this.streamCallbackMap.set(stream, /* @__PURE__ */ new Set());
|
|
1203
|
+
if (!this.streamCallbackMap.has(stream)) this.streamCallbackMap.set(stream, /* @__PURE__ */ new Set());
|
|
1233
1204
|
let connection = this.streamConnectionMap.get(stream);
|
|
1234
1205
|
if (!connection || connection.closeInitiated || connection.reconnectionPending) {
|
|
1235
1206
|
connection = this.getConnection(true);
|
|
1236
1207
|
this.streamConnectionMap.set(stream, connection);
|
|
1237
1208
|
}
|
|
1238
|
-
if (!connectionStreamMap.has(connection))
|
|
1239
|
-
connectionStreamMap.set(connection, []);
|
|
1209
|
+
if (!connectionStreamMap.has(connection)) connectionStreamMap.set(connection, []);
|
|
1240
1210
|
connectionStreamMap.get(connection)?.push(stream);
|
|
1241
1211
|
});
|
|
1242
1212
|
return connectionStreamMap;
|
|
@@ -1392,18 +1362,12 @@ var WebsocketStreamsBase2 = class extends WebsocketCommon {
|
|
|
1392
1362
|
};
|
|
1393
1363
|
export {
|
|
1394
1364
|
ALGO_REST_API_PROD_URL,
|
|
1395
|
-
ALGO_REST_API_TESTNET_URL,
|
|
1396
1365
|
AUTO_INVEST_REST_API_PROD_URL,
|
|
1397
|
-
AUTO_INVEST_REST_API_TESTNET_URL,
|
|
1398
1366
|
BadRequestError,
|
|
1399
1367
|
C2C_REST_API_PROD_URL,
|
|
1400
|
-
C2C_REST_API_TESTNET_URL,
|
|
1401
1368
|
CONVERT_REST_API_PROD_URL,
|
|
1402
|
-
CONVERT_REST_API_TESTNET_URL,
|
|
1403
1369
|
COPY_TRADING_REST_API_PROD_URL,
|
|
1404
|
-
COPY_TRADING_REST_API_TESTNET_URL,
|
|
1405
1370
|
CRYPTO_LOAN_REST_API_PROD_URL,
|
|
1406
|
-
CRYPTO_LOAN_REST_API_TESTNET_URL,
|
|
1407
1371
|
ConfigurationRestAPI,
|
|
1408
1372
|
ConfigurationWebsocketAPI,
|
|
1409
1373
|
ConfigurationWebsocketStreams,
|
|
@@ -1427,30 +1391,21 @@ export {
|
|
|
1427
1391
|
DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL,
|
|
1428
1392
|
DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL,
|
|
1429
1393
|
DUAL_INVESTMENT_REST_API_PROD_URL,
|
|
1430
|
-
DUAL_INVESTMENT_REST_API_TESTNET_URL,
|
|
1431
1394
|
FIAT_REST_API_PROD_URL,
|
|
1432
|
-
FIAT_REST_API_TESTNET_URL,
|
|
1433
1395
|
ForbiddenError,
|
|
1434
1396
|
GIFT_CARD_REST_API_PROD_URL,
|
|
1435
|
-
GIFT_CARD_REST_API_TESTNET_URL,
|
|
1436
1397
|
LogLevel,
|
|
1437
1398
|
Logger,
|
|
1438
1399
|
MARGIN_TRADING_REST_API_PROD_URL,
|
|
1439
|
-
MARGIN_TRADING_REST_API_TESTNET_URL,
|
|
1440
1400
|
MINING_REST_API_PROD_URL,
|
|
1441
|
-
MINING_REST_API_TESTNET_URL,
|
|
1442
1401
|
NFT_REST_API_PROD_URL,
|
|
1443
|
-
NFT_REST_API_TESTNET_URL,
|
|
1444
1402
|
NetworkError,
|
|
1445
1403
|
NotFoundError,
|
|
1446
1404
|
PAY_REST_API_PROD_URL,
|
|
1447
|
-
PAY_REST_API_TESTNET_URL,
|
|
1448
1405
|
REBATE_REST_API_PROD_URL,
|
|
1449
|
-
REBATE_REST_API_TESTNET_URL,
|
|
1450
1406
|
RateLimitBanError,
|
|
1451
1407
|
RequiredError,
|
|
1452
1408
|
SIMPLE_EARN_REST_API_PROD_URL,
|
|
1453
|
-
SIMPLE_EARN_REST_API_TESTNET_URL,
|
|
1454
1409
|
SPOT_REST_API_MARKET_URL,
|
|
1455
1410
|
SPOT_REST_API_PROD_URL,
|
|
1456
1411
|
SPOT_REST_API_TESTNET_URL,
|
|
@@ -1460,17 +1415,13 @@ export {
|
|
|
1460
1415
|
SPOT_WS_STREAMS_PROD_URL,
|
|
1461
1416
|
SPOT_WS_STREAMS_TESTNET_URL,
|
|
1462
1417
|
STAKING_REST_API_PROD_URL,
|
|
1463
|
-
STAKING_REST_API_TESTNET_URL,
|
|
1464
1418
|
SUB_ACCOUNT_REST_API_PROD_URL,
|
|
1465
|
-
SUB_ACCOUNT_REST_API_TESTNET_URL,
|
|
1466
1419
|
ServerError,
|
|
1467
1420
|
TimeUnit,
|
|
1468
1421
|
TooManyRequestsError,
|
|
1469
1422
|
UnauthorizedError,
|
|
1470
1423
|
VIP_LOAN_REST_API_PROD_URL,
|
|
1471
|
-
VIP_LOAN_REST_API_TESTNET_URL,
|
|
1472
1424
|
WALLET_REST_API_PROD_URL,
|
|
1473
|
-
WALLET_REST_API_TESTNET_URL,
|
|
1474
1425
|
WebsocketAPIBase,
|
|
1475
1426
|
WebsocketCommon,
|
|
1476
1427
|
WebsocketEventEmitter,
|