@binance/common 2.3.3 → 2.3.5
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 +15 -3
- package/dist/index.d.ts +15 -3
- package/dist/index.js +32 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -687,10 +687,11 @@ const DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL = "wss://dstream.bina
|
|
|
687
687
|
const DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL = "wss://dstream.binancefuture.com";
|
|
688
688
|
const DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL = "https://fapi.binance.com";
|
|
689
689
|
const DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
|
|
690
|
+
const DERIVATIVES_TRADING_USDS_FUTURES_REST_API_DEMO_URL = "https://demo-fapi.binance.com";
|
|
690
691
|
const DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL = "wss://ws-fapi.binance.com/ws-fapi/v1";
|
|
691
692
|
const DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL = "wss://testnet.binancefuture.com/ws-fapi/v1";
|
|
692
693
|
const DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL = "wss://fstream.binance.com";
|
|
693
|
-
const DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL = "wss://
|
|
694
|
+
const DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL = "wss://fstream.binancefuture.com";
|
|
694
695
|
const DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL = "https://eapi.binance.com";
|
|
695
696
|
const DERIVATIVES_TRADING_OPTIONS_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
|
|
696
697
|
const DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL = "wss://fstream.binance.com";
|
|
@@ -714,10 +715,13 @@ const REBATE_REST_API_PROD_URL = "https://api.binance.com";
|
|
|
714
715
|
const SIMPLE_EARN_REST_API_PROD_URL = "https://api.binance.com";
|
|
715
716
|
const SPOT_REST_API_PROD_URL = "https://api.binance.com";
|
|
716
717
|
const SPOT_REST_API_TESTNET_URL = "https://testnet.binance.vision";
|
|
718
|
+
const SPOT_REST_API_DEMO_URL = "https://demo-api.binance.com";
|
|
717
719
|
const SPOT_WS_API_PROD_URL = "wss://ws-api.binance.com:443/ws-api/v3";
|
|
718
720
|
const SPOT_WS_API_TESTNET_URL = "wss://ws-api.testnet.binance.vision/ws-api/v3";
|
|
721
|
+
const SPOT_WS_API_DEMO_URL = "wss://demo-ws-api.binance.com/ws-api/v3";
|
|
719
722
|
const SPOT_WS_STREAMS_PROD_URL = "wss://stream.binance.com:9443";
|
|
720
723
|
const SPOT_WS_STREAMS_TESTNET_URL = "wss://stream.testnet.binance.vision";
|
|
724
|
+
const SPOT_WS_STREAMS_DEMO_URL = "wss://demo-stream.binance.com:9443";
|
|
721
725
|
const SPOT_REST_API_MARKET_URL = "https://data-api.binance.vision";
|
|
722
726
|
const SPOT_WS_STREAMS_MARKET_URL = "wss://data-stream.binance.vision";
|
|
723
727
|
const STAKING_REST_API_PROD_URL = "https://api.binance.com";
|
|
@@ -990,6 +994,17 @@ var WebsocketCommon = class WebsocketCommon extends WebsocketEventEmitter {
|
|
|
990
994
|
return selectedConnection;
|
|
991
995
|
}
|
|
992
996
|
/**
|
|
997
|
+
* Checks if the message is `serverShutdown`.
|
|
998
|
+
* This is used to identify server shutdown events in incoming WebSocket messages.
|
|
999
|
+
*
|
|
1000
|
+
* @param message - The message to check for a server shutdown event.
|
|
1001
|
+
* @returns `true` if the message indicates a server shutdown event, `false` otherwise.
|
|
1002
|
+
*/
|
|
1003
|
+
isServerShutdownEvent(message) {
|
|
1004
|
+
if (!message || typeof message !== "object") return false;
|
|
1005
|
+
return "event" in message && "e" in message["event"] && message?.event?.e === "serverShutdown";
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
993
1008
|
* Checks if the provided WebSocket connection is ready for use.
|
|
994
1009
|
* A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
|
|
995
1010
|
* @param connection - The WebSocket connection to check.
|
|
@@ -1241,11 +1256,11 @@ var WebsocketCommon = class WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1241
1256
|
ws.on("message", (data) => {
|
|
1242
1257
|
this.onMessage(data.toString(), targetConnection);
|
|
1243
1258
|
});
|
|
1244
|
-
ws.on("ping", () => {
|
|
1259
|
+
ws.on("ping", (data) => {
|
|
1245
1260
|
this.logger.debug("Received PING from server");
|
|
1246
|
-
this.emit("ping");
|
|
1247
|
-
ws.pong();
|
|
1248
|
-
this.logger.debug(
|
|
1261
|
+
this.emit("ping", data);
|
|
1262
|
+
ws.pong(data);
|
|
1263
|
+
this.logger.debug(`Responded PONG to server's PING message with: ${data}`);
|
|
1249
1264
|
});
|
|
1250
1265
|
ws.on("pong", () => {
|
|
1251
1266
|
this.logger.debug("Received PONG from server");
|
|
@@ -1315,7 +1330,7 @@ var WebsocketCommon = class WebsocketCommon extends WebsocketEventEmitter {
|
|
|
1315
1330
|
this.logger.debug("Sending PING to all connected Websocket servers.");
|
|
1316
1331
|
connectedConnections.forEach((connection) => {
|
|
1317
1332
|
if (connection.ws) {
|
|
1318
|
-
connection.ws.ping();
|
|
1333
|
+
connection.ws.ping(Buffer.alloc(0));
|
|
1319
1334
|
this.logger.debug(`PING sent to connection with id ${connection.id}`);
|
|
1320
1335
|
} else this.logger.error("WebSocket Client not set for a connection.");
|
|
1321
1336
|
});
|
|
@@ -1396,11 +1411,13 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1396
1411
|
onMessage(data, connection) {
|
|
1397
1412
|
try {
|
|
1398
1413
|
const message = JSONParse(data);
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1414
|
+
if (this.isServerShutdownEvent(message)) {
|
|
1415
|
+
this.logger.warn(`Received serverShutdown event on connection ${connection.id}.`);
|
|
1416
|
+
if (!connection.renewalPending && !connection.closeInitiated) this.enqueueReconnection(connection, this.prepareURL(this.configuration.wsURL), true);
|
|
1417
|
+
} else if (message.id && connection.pendingRequests.has(message.id)) {
|
|
1418
|
+
const request = connection.pendingRequests.get(message.id);
|
|
1419
|
+
connection.pendingRequests.delete(message.id);
|
|
1420
|
+
if (message.status && message.status >= 400) request?.reject(message.error);
|
|
1404
1421
|
else {
|
|
1405
1422
|
const response = {
|
|
1406
1423
|
data: message.result ?? message.response,
|
|
@@ -1749,5 +1766,5 @@ function createStreamHandler(websocketBase, streamOrId, id, urlPath) {
|
|
|
1749
1766
|
}
|
|
1750
1767
|
|
|
1751
1768
|
//#endregion
|
|
1752
|
-
export { ALGO_REST_API_PROD_URL, ALPHA_REST_API_PROD_URL, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MARGIN_TRADING_RISK_WS_STREAMS_PROD_URL, MARGIN_TRADING_WS_STREAMS_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, RequiredError, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketCommon, WebsocketEventEmitter, WebsocketStreamsBase, assertParamExists, buildQueryString, buildUserAgent, buildWebsocketAPIMessage, clearSignerCache, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, normalizeScientificNumbers, normalizeStreamId, parseCustomHeaders, parseRateLimitHeaders, randomInteger, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sanitizeHeaderValue, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
|
1769
|
+
export { ALGO_REST_API_PROD_URL, ALPHA_REST_API_PROD_URL, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_DEMO_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MARGIN_TRADING_RISK_WS_STREAMS_PROD_URL, MARGIN_TRADING_WS_STREAMS_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, RequiredError, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_DEMO_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_DEMO_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_DEMO_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketCommon, WebsocketEventEmitter, WebsocketStreamsBase, assertParamExists, buildQueryString, buildUserAgent, buildWebsocketAPIMessage, clearSignerCache, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, normalizeScientificNumbers, normalizeStreamId, parseCustomHeaders, parseRateLimitHeaders, randomInteger, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sanitizeHeaderValue, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
|
1753
1770
|
//# sourceMappingURL=index.mjs.map
|