@binance/common 1.0.1 → 1.0.3

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 CHANGED
@@ -434,13 +434,20 @@ interface WebsocketApiRateLimit {
434
434
  count: number;
435
435
  }
436
436
  /**
437
- * Represents the response from a WebSocket API request.
438
- * @template T - The type of the data returned in the response.
439
- * @property {T} data - The data from the API response.
437
+ * Extracts the result or response from a WebSocket API response type.
438
+ * @template T - The type of the WebSocket API response.
439
+ * @returns {T['result'] | T['response'] | never} The extracted result or response, or never if neither exists.
440
+ * @description Checks if the type T has a 'result' or 'response' key and returns its value, otherwise returns never.
441
+ */
442
+ type ExtractWebsocketApiResponse<T> = 'result' extends keyof T ? T['result'] : 'response' extends keyof T ? T['response'] : unknown;
443
+ /**
444
+ * Represents the response from a WebSocket API.
445
+ * @template T - The type of the WebSocket API response.
446
+ * @property {NonNullable<ExtractWebsocketApiResponse<T>>} data - The extracted, non-null data from the WebSocket API response.
440
447
  * @property {WebsocketApiRateLimit[]} [rateLimits] - An optional array of rate limit information for the response.
441
448
  */
442
449
  type WebsocketApiResponse<T> = {
443
- data: T;
450
+ data: NonNullable<ExtractWebsocketApiResponse<T>>;
444
451
  rateLimits?: WebsocketApiRateLimit[];
445
452
  };
446
453
  /**
@@ -825,7 +832,7 @@ declare class WebsocketAPIBase extends WebsocketCommon {
825
832
  * Processes incoming WebSocket messages
826
833
  * @param data The raw message data received
827
834
  */
828
- protected onMessage(data: string, connection: WebsocketConnection): void;
835
+ protected onMessage<T>(data: string, connection: WebsocketConnection): void;
829
836
  /**
830
837
  * Establishes a WebSocket connection to Binance
831
838
  * @returns Promise that resolves when connection is established
@@ -952,4 +959,4 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
952
959
  isSubscribed(stream: string): boolean;
953
960
  }
954
961
 
955
- export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, AxiosRequestArgs, 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_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_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, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, RequestArgs, RequiredError, RestApiRateLimit, RestApiResponse, 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, SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketApiRateLimit, WebsocketApiResponse, WebsocketCommon, WebsocketConnection, WebsocketEventEmitter, WebsocketSendMsgOptions, WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
962
+ export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, 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_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_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, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, 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, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
package/dist/index.d.ts CHANGED
@@ -434,13 +434,20 @@ interface WebsocketApiRateLimit {
434
434
  count: number;
435
435
  }
436
436
  /**
437
- * Represents the response from a WebSocket API request.
438
- * @template T - The type of the data returned in the response.
439
- * @property {T} data - The data from the API response.
437
+ * Extracts the result or response from a WebSocket API response type.
438
+ * @template T - The type of the WebSocket API response.
439
+ * @returns {T['result'] | T['response'] | never} The extracted result or response, or never if neither exists.
440
+ * @description Checks if the type T has a 'result' or 'response' key and returns its value, otherwise returns never.
441
+ */
442
+ type ExtractWebsocketApiResponse<T> = 'result' extends keyof T ? T['result'] : 'response' extends keyof T ? T['response'] : unknown;
443
+ /**
444
+ * Represents the response from a WebSocket API.
445
+ * @template T - The type of the WebSocket API response.
446
+ * @property {NonNullable<ExtractWebsocketApiResponse<T>>} data - The extracted, non-null data from the WebSocket API response.
440
447
  * @property {WebsocketApiRateLimit[]} [rateLimits] - An optional array of rate limit information for the response.
441
448
  */
442
449
  type WebsocketApiResponse<T> = {
443
- data: T;
450
+ data: NonNullable<ExtractWebsocketApiResponse<T>>;
444
451
  rateLimits?: WebsocketApiRateLimit[];
445
452
  };
446
453
  /**
@@ -825,7 +832,7 @@ declare class WebsocketAPIBase extends WebsocketCommon {
825
832
  * Processes incoming WebSocket messages
826
833
  * @param data The raw message data received
827
834
  */
828
- protected onMessage(data: string, connection: WebsocketConnection): void;
835
+ protected onMessage<T>(data: string, connection: WebsocketConnection): void;
829
836
  /**
830
837
  * Establishes a WebSocket connection to Binance
831
838
  * @returns Promise that resolves when connection is established
@@ -952,4 +959,4 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
952
959
  isSubscribed(stream: string): boolean;
953
960
  }
954
961
 
955
- export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, AxiosRequestArgs, 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_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_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, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, RequestArgs, RequiredError, RestApiRateLimit, RestApiResponse, 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, SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketApiRateLimit, WebsocketApiResponse, WebsocketCommon, WebsocketConnection, WebsocketEventEmitter, WebsocketSendMsgOptions, WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
962
+ export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, 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_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_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, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, 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, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
package/dist/index.js CHANGED
@@ -28,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  ALGO_REST_API_PROD_URL: () => ALGO_REST_API_PROD_URL,
34
34
  AUTO_INVEST_REST_API_PROD_URL: () => AUTO_INVEST_REST_API_PROD_URL,
35
35
  BadRequestError: () => BadRequestError,
@@ -113,7 +113,7 @@ __export(src_exports, {
113
113
  toPathString: () => toPathString,
114
114
  validateTimeUnit: () => validateTimeUnit
115
115
  });
116
- module.exports = __toCommonJS(src_exports);
116
+ module.exports = __toCommonJS(index_exports);
117
117
 
118
118
  // src/configuration.ts
119
119
  var ConfigurationRestAPI = class {
@@ -368,8 +368,7 @@ var import_fs = __toESM(require("fs"));
368
368
  var import_https = __toESM(require("https"));
369
369
  var import_axios = __toESM(require("axios"));
370
370
  function buildQueryString(params) {
371
- if (!params)
372
- return "";
371
+ if (!params) return "";
373
372
  return Object.entries(params).map(stringifyKeyValuePair).join("&");
374
373
  }
375
374
  function stringifyKeyValuePair([key, value]) {
@@ -437,8 +436,7 @@ var assertParamExists = function(functionName, paramName, paramValue) {
437
436
  }
438
437
  };
439
438
  function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
440
- if (parameter == null)
441
- return;
439
+ if (parameter == null) return;
442
440
  if (typeof parameter === "object") {
443
441
  if (Array.isArray(parameter)) {
444
442
  parameter.forEach((item) => setFlattenedQueryParams(urlSearchParams, item, key));
@@ -550,8 +548,7 @@ var httpRequestFunction = async function(axiosArgs, configuration) {
550
548
  } else {
551
549
  if (retries > 0 && attempt >= retries)
552
550
  lastError = new Error(`Request failed after ${retries} retries`);
553
- else
554
- lastError = new NetworkError("Network error or request timeout.");
551
+ else lastError = new NetworkError("Network error or request timeout.");
555
552
  break;
556
553
  }
557
554
  }
@@ -563,8 +560,7 @@ var parseRateLimitHeaders = function(headers) {
563
560
  const rateLimits = [];
564
561
  const parseIntervalDetails = (key) => {
565
562
  const match = key.match(/x-mbx-used-weight-(\d+)([smhd])|x-mbx-order-count-(\d+)([smhd])/i);
566
- if (!match)
567
- return null;
563
+ if (!match) return null;
568
564
  const intervalNum = parseInt(match[1] || match[3], 10);
569
565
  const intervalLetter = (match[2] || match[4])?.toUpperCase();
570
566
  let interval;
@@ -588,8 +584,7 @@ var parseRateLimitHeaders = function(headers) {
588
584
  };
589
585
  for (const [key, value] of Object.entries(headers)) {
590
586
  const normalizedKey = key.toLowerCase();
591
- if (value === void 0)
592
- continue;
587
+ if (value === void 0) continue;
593
588
  if (normalizedKey.startsWith("x-mbx-used-weight-")) {
594
589
  const details = parseIntervalDetails(normalizedKey);
595
590
  if (details) {
@@ -652,8 +647,7 @@ var sendRequest = function(configuration, endpoint, method, params = {}, timeUni
652
647
  );
653
648
  };
654
649
  function removeEmptyValue(obj) {
655
- if (!(obj instanceof Object))
656
- return {};
650
+ if (!(obj instanceof Object)) return {};
657
651
  return Object.fromEntries(
658
652
  Object.entries(obj).filter(
659
653
  ([, value]) => value !== null && value !== void 0 && value !== ""
@@ -669,12 +663,13 @@ function sortObject(obj) {
669
663
  function replaceWebsocketStreamsPlaceholders(str, variables) {
670
664
  const normalizedVariables = Object.keys(variables).reduce(
671
665
  (acc, key) => {
672
- acc[key.toLowerCase().replace(/[-_]/g, "")] = variables[key];
666
+ const normalizedKey = key.toLowerCase().replace(/[-_]/g, "");
667
+ acc[normalizedKey] = variables[key];
673
668
  return acc;
674
669
  },
675
670
  {}
676
671
  );
677
- return str.replace(/<([^>]+)>/g, (match, fieldName) => {
672
+ return str.replace(/(@)?<([^>]+)>/g, (match, precedingAt, fieldName) => {
678
673
  const normalizedFieldName = fieldName.toLowerCase().replace(/[-_]/g, "");
679
674
  if (Object.prototype.hasOwnProperty.call(normalizedVariables, normalizedFieldName) && normalizedVariables[normalizedFieldName] != null) {
680
675
  const value = normalizedVariables[normalizedFieldName];
@@ -685,7 +680,7 @@ function replaceWebsocketStreamsPlaceholders(str, variables) {
685
680
  case "updatespeed":
686
681
  return `@${value}`;
687
682
  default:
688
- return value;
683
+ return (precedingAt || "") + value;
689
684
  }
690
685
  }
691
686
  return "";
@@ -731,7 +726,7 @@ var WebsocketEventEmitter = class {
731
726
  this.eventEmitter.emit(event, ...args);
732
727
  }
733
728
  };
734
- var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
729
+ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
735
730
  constructor(configuration, connectionPool = []) {
736
731
  super();
737
732
  this.configuration = configuration;
@@ -743,8 +738,10 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
743
738
  this.connectionPool = connectionPool;
744
739
  this.mode = this.configuration?.mode ?? "single";
745
740
  this.poolSize = this.mode === "pool" && this.configuration?.poolSize ? this.configuration.poolSize : 1;
746
- if (!connectionPool || connectionPool.length === 0)
747
- this.initializePool(this.poolSize);
741
+ if (!connectionPool || connectionPool.length === 0) this.initializePool(this.poolSize);
742
+ }
743
+ static {
744
+ this.MAX_CONNECTION_DURATION = 23 * 60 * 60 * 1e3;
748
745
  }
749
746
  /**
750
747
  * Initializes the WebSocket connection pool by creating a specified number of connection objects
@@ -776,8 +773,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
776
773
  * @returns {WebsocketConnection} The selected WebSocket connection.
777
774
  */
778
775
  getConnection(allowNonEstablishedWebsockets = false) {
779
- if (this.mode === "single")
780
- return this.connectionPool[0];
776
+ if (this.mode === "single") return this.connectionPool[0];
781
777
  const availableConnections = this.connectionPool.filter(
782
778
  (connection) => this.isConnectionReady(connection, allowNonEstablishedWebsockets)
783
779
  );
@@ -822,10 +818,8 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
822
818
  const timers = this.connectionTimers.get(connection);
823
819
  if (timers) {
824
820
  timers.forEach(({ timer, type }) => {
825
- if (type === "timeout")
826
- clearTimeout(timer);
827
- else if (type === "interval")
828
- clearInterval(timer);
821
+ if (type === "timeout") clearTimeout(timer);
822
+ else if (type === "interval") clearInterval(timer);
829
823
  });
830
824
  this.connectionTimers.delete(connection);
831
825
  }
@@ -841,8 +835,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
841
835
  * @returns A Promise that resolves when the queue has been fully processed.
842
836
  */
843
837
  async processQueue(throttleRate = 1e3) {
844
- if (this.queueProcessing)
845
- return;
838
+ if (this.queueProcessing) return;
846
839
  this.queueProcessing = true;
847
840
  while (this.connectionQueue.length > 0) {
848
841
  const { connection, url, isRenewal } = this.connectionQueue.shift();
@@ -875,8 +868,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
875
868
  * @returns Promise that resolves when the connection is closed.
876
869
  */
877
870
  async closeConnectionGracefully(WebsocketConnectionToClose, connection) {
878
- if (!WebsocketConnectionToClose || !connection)
879
- return;
871
+ if (!WebsocketConnectionToClose || !connection) return;
880
872
  this.logger.debug("Waiting for pending requests to complete before disconnecting.");
881
873
  const closePromise = new Promise((resolve) => {
882
874
  this.scheduleTimer(
@@ -1009,10 +1001,8 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
1009
1001
  this.logger.info(
1010
1002
  `Establishing Websocket connection with id ${targetConnection.id} to: ${url}`
1011
1003
  );
1012
- if (isRenewal)
1013
- targetConnection.renewalPending = true;
1014
- else
1015
- targetConnection.ws = ws;
1004
+ if (isRenewal) targetConnection.renewalPending = true;
1005
+ else targetConnection.ws = ws;
1016
1006
  this.scheduleTimer(
1017
1007
  ws,
1018
1008
  () => {
@@ -1027,8 +1017,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
1027
1017
  );
1028
1018
  ws.on("open", () => {
1029
1019
  const oldWSConnection = targetConnection.ws;
1030
- if (targetConnection.renewalPending)
1031
- targetConnection.ws = ws;
1020
+ if (targetConnection.renewalPending) targetConnection.ws = ws;
1032
1021
  this.onOpen(url, targetConnection, oldWSConnection);
1033
1022
  });
1034
1023
  ws.on("message", (data) => {
@@ -1092,8 +1081,7 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
1092
1081
  * @throws Error if the WebSocket client is not set.
1093
1082
  */
1094
1083
  async disconnect() {
1095
- if (!this.isConnected())
1096
- this.logger.warn("No connection to close.");
1084
+ if (!this.isConnected()) this.logger.warn("No connection to close.");
1097
1085
  else {
1098
1086
  this.connectionPool.forEach((connection) => {
1099
1087
  connection.closeInitiated = true;
@@ -1143,25 +1131,20 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
1143
1131
  if (!this.isConnected(connection)) {
1144
1132
  const errorMsg = "Send can only be sent when connection is ready.";
1145
1133
  this.logger.warn(errorMsg);
1146
- if (promiseBased)
1147
- return Promise.reject(new Error(errorMsg));
1148
- else
1149
- throw new Error(errorMsg);
1134
+ if (promiseBased) return Promise.reject(new Error(errorMsg));
1135
+ else throw new Error(errorMsg);
1150
1136
  }
1151
1137
  const connectionToUse = connection ?? this.getConnection();
1152
1138
  if (!connectionToUse.ws) {
1153
1139
  const errorMsg = "Websocket Client not set";
1154
1140
  this.logger.error(errorMsg);
1155
- if (promiseBased)
1156
- return Promise.reject(new Error(errorMsg));
1157
- else
1158
- throw new Error(errorMsg);
1141
+ if (promiseBased) return Promise.reject(new Error(errorMsg));
1142
+ else throw new Error(errorMsg);
1159
1143
  }
1160
1144
  connectionToUse.ws.send(payload);
1161
1145
  if (promiseBased) {
1162
1146
  return new Promise((resolve, reject) => {
1163
- if (!id)
1164
- return reject(new Error("id is required for promise-based sending."));
1147
+ if (!id) return reject(new Error("id is required for promise-based sending."));
1165
1148
  connectionToUse.pendingRequests.set(id, { resolve, reject });
1166
1149
  this.scheduleTimer(
1167
1150
  connectionToUse.ws,
@@ -1177,8 +1160,6 @@ var _WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
1177
1160
  }
1178
1161
  }
1179
1162
  };
1180
- _WebsocketCommon.MAX_CONNECTION_DURATION = 23 * 60 * 60 * 1e3;
1181
- var WebsocketCommon = _WebsocketCommon;
1182
1163
  var WebsocketAPIBase = class extends WebsocketCommon {
1183
1164
  constructor(configuration, connectionPool = []) {
1184
1165
  super(configuration, connectionPool);
@@ -1217,9 +1198,10 @@ var WebsocketAPIBase = class extends WebsocketCommon {
1217
1198
  if (status && status >= 400) {
1218
1199
  request?.reject(message.error);
1219
1200
  } else {
1220
- const response = { data: message.result };
1221
- if (message?.rateLimits)
1222
- response.rateLimits = message.rateLimits;
1201
+ const response = {
1202
+ data: message.result ?? message.response,
1203
+ ...message.rateLimits && { rateLimits: message.rateLimits }
1204
+ };
1223
1205
  request?.resolve(response);
1224
1206
  }
1225
1207
  } else {
@@ -1241,8 +1223,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
1241
1223
  return Promise.resolve();
1242
1224
  }
1243
1225
  return new Promise((resolve, reject) => {
1244
- if (this.isConnecting)
1245
- return;
1226
+ if (this.isConnecting) return;
1246
1227
  this.isConnecting = true;
1247
1228
  const timeout = setTimeout(() => {
1248
1229
  this.isConnecting = false;
@@ -1338,15 +1319,13 @@ var WebsocketStreamsBase2 = class extends WebsocketCommon {
1338
1319
  handleStreamAssignment(streams) {
1339
1320
  const connectionStreamMap = /* @__PURE__ */ new Map();
1340
1321
  streams.forEach((stream) => {
1341
- if (!this.streamCallbackMap.has(stream))
1342
- this.streamCallbackMap.set(stream, /* @__PURE__ */ new Set());
1322
+ if (!this.streamCallbackMap.has(stream)) this.streamCallbackMap.set(stream, /* @__PURE__ */ new Set());
1343
1323
  let connection = this.streamConnectionMap.get(stream);
1344
1324
  if (!connection || connection.closeInitiated || connection.reconnectionPending) {
1345
1325
  connection = this.getConnection(true);
1346
1326
  this.streamConnectionMap.set(stream, connection);
1347
1327
  }
1348
- if (!connectionStreamMap.has(connection))
1349
- connectionStreamMap.set(connection, []);
1328
+ if (!connectionStreamMap.has(connection)) connectionStreamMap.set(connection, []);
1350
1329
  connectionStreamMap.get(connection)?.push(stream);
1351
1330
  });
1352
1331
  return connectionStreamMap;