@binance/common 2.1.0 → 2.2.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/dist/index.d.mts CHANGED
@@ -28,7 +28,9 @@ declare const DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL = "wss://testn
28
28
  declare const DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL = "wss://fstream.binance.com";
29
29
  declare const DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL = "wss://stream.binancefuture.com";
30
30
  declare const DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL = "https://eapi.binance.com";
31
- declare const DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL = "wss://nbstream.binance.com/eoptions";
31
+ declare const DERIVATIVES_TRADING_OPTIONS_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
32
+ declare const DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL = "wss://fstream.binance.com";
33
+ declare const DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_TESTNET_URL = "wss://fstream.binancefuture.com";
32
34
  declare const DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL = "https://papi.binance.com";
33
35
  declare const DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
34
36
  declare const DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL = "wss://fstream.binance.com/pm";
@@ -529,6 +531,33 @@ declare function buildQueryString(params: Record<string, unknown>): string;
529
531
  * @returns A random string of 16 hexadecimal characters.
530
532
  */
531
533
  declare function randomString(): string;
534
+ /**
535
+ * Generates a cryptographically secure random 32-bit unsigned integer.
536
+ *
537
+ * Uses the Web Crypto API to generate a random value between 0 and 4,294,967,295 (2^32 - 1).
538
+ *
539
+ * @returns A random 32-bit unsigned integer.
540
+ */
541
+ declare function randomInteger(): number;
542
+ /**
543
+ * Normalizes a stream ID to ensure it is valid, generating a random ID if needed.
544
+ *
545
+ * For string inputs:
546
+ * - Returns the input if it's a valid 32-character hexadecimal string (case-insensitive)
547
+ * - Otherwise, generates a new random hexadecimal string using `randomString()`
548
+ *
549
+ * For number inputs:
550
+ * - Returns the input if it's a finite, non-negative integer within the safe integer range
551
+ * - Otherwise, generates a new random integer using `randomInteger()`
552
+ *
553
+ * For null or undefined inputs:
554
+ * - Generates a new random hexadecimal string using `randomString()`
555
+ *
556
+ * @param id - The stream ID to normalize (string, number, null, or undefined).
557
+ * @param streamIdIsStrictlyNumber - Boolean forcing an id to be a number or not.
558
+ * @returns A valid stream ID as either a 32-character hexadecimal string or a safe integer.
559
+ */
560
+ declare function normalizeStreamId(id: string | number | null | undefined, streamIdIsStrictlyNumber?: boolean): string | number;
532
561
  /**
533
562
  * Validates the provided time unit string and returns it if it is either 'MILLISECOND' or 'MICROSECOND'.
534
563
  *
@@ -732,6 +761,7 @@ interface WebsocketConnection {
732
761
  }>;
733
762
  pendingSubscriptions?: string[];
734
763
  ws?: WebSocketClient;
764
+ urlPath?: string;
735
765
  isSessionLoggedOn?: boolean;
736
766
  sessionLogonReq?: {
737
767
  method: string;
@@ -766,18 +796,20 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
766
796
  * In 'single' mode, returns the first connection in the pool.
767
797
  * In 'pool' mode, filters and returns connections that are ready for use.
768
798
  * @param allowNonEstablishedWebsockets - Optional flag to include non-established WebSocket connections.
799
+ * @param urlPath - Optional URL path to filter connections.
769
800
  * @returns An array of available WebSocket connections.
770
801
  */
771
- protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean): WebsocketConnection[];
802
+ protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection[];
772
803
  /**
773
804
  * Gets a WebSocket connection from the pool or single connection.
774
805
  * If the connection mode is 'single', it returns the first connection in the pool.
775
806
  * If the connection mode is 'pool', it returns an available connection from the pool,
776
807
  * using a round-robin selection strategy. If no available connections are found, it throws an error.
777
808
  * @param allowNonEstablishedWebsockets - A boolean indicating whether to allow connections that are not established.
809
+ * @param urlPath - An optional URL path to filter connections.
778
810
  * @returns {WebsocketConnection} The selected WebSocket connection.
779
811
  */
780
- protected getConnection(allowNonEstablishedWebsockets?: boolean): WebsocketConnection;
812
+ protected getConnection(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection;
781
813
  /**
782
814
  * Checks if the provided WebSocket connection is ready for use.
783
815
  * A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
@@ -872,9 +904,10 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
872
904
  /**
873
905
  * Connects all WebSocket connections in the pool
874
906
  * @param url - The Websocket server URL.
907
+ * @param connections - An optional array of WebSocket connections to connect. If not provided, all connections in the pool are connected.
875
908
  * @returns A promise that resolves when all connections are established.
876
909
  */
877
- protected connectPool(url: string): Promise<void>;
910
+ protected connectPool(url: string, connections?: WebsocketConnection[]): Promise<void>;
878
911
  /**
879
912
  * Creates a new WebSocket client instance.
880
913
  * @param url - The URL to connect to.
@@ -966,14 +999,31 @@ declare class WebsocketAPIBase extends WebsocketCommon {
966
999
  }
967
1000
  declare class WebsocketStreamsBase extends WebsocketCommon {
968
1001
  private streamConnectionMap;
1002
+ protected urlPaths: string[];
969
1003
  protected configuration: ConfigurationWebsocketStreams;
970
1004
  protected wsURL: string;
1005
+ streamIdIsStrictlyNumber?: boolean;
971
1006
  streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
972
1007
  logger: Logger;
973
- constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
1008
+ constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[], urlPaths?: string[]);
1009
+ /**
1010
+ * Ensures the connection pool has the required size based on the configured mode and number of URL paths.
1011
+ *
1012
+ * If no URL paths are configured, the method returns early without modifications.
1013
+ * In 'pool' mode, the pool size is multiplied by the number of URL paths.
1014
+ * In 'single' mode, only one connection per URL path is maintained.
1015
+ *
1016
+ * New connections are initialized with unique IDs and default state flags when the pool
1017
+ * size is less than the expected size.
1018
+ *
1019
+ * @private
1020
+ * @returns {void}
1021
+ */
1022
+ private ensurePoolSizeForUrlPaths;
974
1023
  /**
975
1024
  * Formats the WebSocket URL for a given stream or streams.
976
1025
  * @param streams - Array of stream names to include in the URL.
1026
+ * @param urlPath - Optional URL path to include in the WebSocket URL.
977
1027
  * @returns The formatted WebSocket URL with the provided streams.
978
1028
  */
979
1029
  private prepareURL;
@@ -987,6 +1037,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
987
1037
  /**
988
1038
  * Handles subscription to streams and assigns them to specific connections
989
1039
  * @param streams Array of stream names to subscribe to
1040
+ * @param urlPath Optional URL path for the streams
990
1041
  * @returns Map of connections to streams
991
1042
  */
992
1043
  private handleStreamAssignment;
@@ -1020,6 +1071,13 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
1020
1071
  * @param oldConnection The previous WebSocket connection, if any.
1021
1072
  */
1022
1073
  protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
1074
+ /**
1075
+ * Generates a stream key by combining a stream name with an optional URL path.
1076
+ * @param stream - The stream name to use as the key or suffix.
1077
+ * @param urlPath - Optional URL path to prepend to the stream name.
1078
+ * @returns A stream key in the format `urlPath::stream` if urlPath is provided, otherwise just the stream name.
1079
+ */
1080
+ streamKey(stream: string, urlPath?: string): string;
1023
1081
  /**
1024
1082
  * Connects to the WebSocket server and subscribes to the specified streams.
1025
1083
  * This method returns a Promise that resolves when the connection is established,
@@ -1038,17 +1096,19 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
1038
1096
  * Handles both single and pool modes
1039
1097
  * @param stream Single stream name or array of stream names to subscribe to
1040
1098
  * @param id Optional subscription ID
1099
+ * @param urlPath Optional URL path for the streams
1041
1100
  * @returns void
1042
1101
  */
1043
- subscribe(stream: string | string[], id?: string): void;
1102
+ subscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
1044
1103
  /**
1045
1104
  * Unsubscribes from one or multiple WebSocket streams
1046
1105
  * Handles both single and pool modes
1047
1106
  * @param stream Single stream name or array of stream names to unsubscribe from
1048
1107
  * @param id Optional unsubscription ID
1108
+ * @param urlPath Optional URL path for the streams
1049
1109
  * @returns void
1050
1110
  */
1051
- unsubscribe(stream: string | string[], id?: string): void;
1111
+ unsubscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
1052
1112
  /**
1053
1113
  * Checks if the specified stream is currently subscribed.
1054
1114
  * @param stream - The name of the stream to check.
@@ -1075,9 +1135,10 @@ interface WebsocketStream<T> {
1075
1135
  * @param {WebsocketAPIBase | WebsocketStreamsBase} websocketBase The WebSocket base instance
1076
1136
  * @param {string} streamOrId The stream identifier
1077
1137
  * @param {string} [id] Optional additional identifier
1138
+ * @param {string} [urlPath] Optional URL path for the stream
1078
1139
  * @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
1079
1140
  */
1080
- declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
1141
+ declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string, urlPath?: string): WebsocketStream<T>;
1081
1142
  //#endregion
1082
- export { ALGO_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_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, 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, TimerRecord, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketApiRateLimit, WebsocketApiResponse, WebsocketCommon, WebsocketConnection, WebsocketEventEmitter, WebsocketSendMsgConfig, WebsocketSendMsgOptions, WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, buildUserAgent, buildWebsocketAPIMessage, clearSignerCache, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, normalizeScientificNumbers, parseCustomHeaders, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sanitizeHeaderValue, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
1143
+ export { ALGO_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_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, 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, TimerRecord, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketApiRateLimit, WebsocketApiResponse, WebsocketCommon, WebsocketConnection, WebsocketEventEmitter, WebsocketSendMsgConfig, WebsocketSendMsgOptions, WebsocketStream, 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 };
1083
1144
  //# sourceMappingURL=index.d.mts.map
package/dist/index.d.ts CHANGED
@@ -28,7 +28,9 @@ declare const DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL = "wss://testn
28
28
  declare const DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL = "wss://fstream.binance.com";
29
29
  declare const DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL = "wss://stream.binancefuture.com";
30
30
  declare const DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL = "https://eapi.binance.com";
31
- declare const DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL = "wss://nbstream.binance.com/eoptions";
31
+ declare const DERIVATIVES_TRADING_OPTIONS_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
32
+ declare const DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL = "wss://fstream.binance.com";
33
+ declare const DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_TESTNET_URL = "wss://fstream.binancefuture.com";
32
34
  declare const DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL = "https://papi.binance.com";
33
35
  declare const DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL = "https://testnet.binancefuture.com";
34
36
  declare const DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL = "wss://fstream.binance.com/pm";
@@ -529,6 +531,33 @@ declare function buildQueryString(params: Record<string, unknown>): string;
529
531
  * @returns A random string of 16 hexadecimal characters.
530
532
  */
531
533
  declare function randomString(): string;
534
+ /**
535
+ * Generates a cryptographically secure random 32-bit unsigned integer.
536
+ *
537
+ * Uses the Web Crypto API to generate a random value between 0 and 4,294,967,295 (2^32 - 1).
538
+ *
539
+ * @returns A random 32-bit unsigned integer.
540
+ */
541
+ declare function randomInteger(): number;
542
+ /**
543
+ * Normalizes a stream ID to ensure it is valid, generating a random ID if needed.
544
+ *
545
+ * For string inputs:
546
+ * - Returns the input if it's a valid 32-character hexadecimal string (case-insensitive)
547
+ * - Otherwise, generates a new random hexadecimal string using `randomString()`
548
+ *
549
+ * For number inputs:
550
+ * - Returns the input if it's a finite, non-negative integer within the safe integer range
551
+ * - Otherwise, generates a new random integer using `randomInteger()`
552
+ *
553
+ * For null or undefined inputs:
554
+ * - Generates a new random hexadecimal string using `randomString()`
555
+ *
556
+ * @param id - The stream ID to normalize (string, number, null, or undefined).
557
+ * @param streamIdIsStrictlyNumber - Boolean forcing an id to be a number or not.
558
+ * @returns A valid stream ID as either a 32-character hexadecimal string or a safe integer.
559
+ */
560
+ declare function normalizeStreamId(id: string | number | null | undefined, streamIdIsStrictlyNumber?: boolean): string | number;
532
561
  /**
533
562
  * Validates the provided time unit string and returns it if it is either 'MILLISECOND' or 'MICROSECOND'.
534
563
  *
@@ -732,6 +761,7 @@ interface WebsocketConnection {
732
761
  }>;
733
762
  pendingSubscriptions?: string[];
734
763
  ws?: WebSocketClient;
764
+ urlPath?: string;
735
765
  isSessionLoggedOn?: boolean;
736
766
  sessionLogonReq?: {
737
767
  method: string;
@@ -766,18 +796,20 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
766
796
  * In 'single' mode, returns the first connection in the pool.
767
797
  * In 'pool' mode, filters and returns connections that are ready for use.
768
798
  * @param allowNonEstablishedWebsockets - Optional flag to include non-established WebSocket connections.
799
+ * @param urlPath - Optional URL path to filter connections.
769
800
  * @returns An array of available WebSocket connections.
770
801
  */
771
- protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean): WebsocketConnection[];
802
+ protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection[];
772
803
  /**
773
804
  * Gets a WebSocket connection from the pool or single connection.
774
805
  * If the connection mode is 'single', it returns the first connection in the pool.
775
806
  * If the connection mode is 'pool', it returns an available connection from the pool,
776
807
  * using a round-robin selection strategy. If no available connections are found, it throws an error.
777
808
  * @param allowNonEstablishedWebsockets - A boolean indicating whether to allow connections that are not established.
809
+ * @param urlPath - An optional URL path to filter connections.
778
810
  * @returns {WebsocketConnection} The selected WebSocket connection.
779
811
  */
780
- protected getConnection(allowNonEstablishedWebsockets?: boolean): WebsocketConnection;
812
+ protected getConnection(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection;
781
813
  /**
782
814
  * Checks if the provided WebSocket connection is ready for use.
783
815
  * A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
@@ -872,9 +904,10 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
872
904
  /**
873
905
  * Connects all WebSocket connections in the pool
874
906
  * @param url - The Websocket server URL.
907
+ * @param connections - An optional array of WebSocket connections to connect. If not provided, all connections in the pool are connected.
875
908
  * @returns A promise that resolves when all connections are established.
876
909
  */
877
- protected connectPool(url: string): Promise<void>;
910
+ protected connectPool(url: string, connections?: WebsocketConnection[]): Promise<void>;
878
911
  /**
879
912
  * Creates a new WebSocket client instance.
880
913
  * @param url - The URL to connect to.
@@ -966,14 +999,31 @@ declare class WebsocketAPIBase extends WebsocketCommon {
966
999
  }
967
1000
  declare class WebsocketStreamsBase extends WebsocketCommon {
968
1001
  private streamConnectionMap;
1002
+ protected urlPaths: string[];
969
1003
  protected configuration: ConfigurationWebsocketStreams;
970
1004
  protected wsURL: string;
1005
+ streamIdIsStrictlyNumber?: boolean;
971
1006
  streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
972
1007
  logger: Logger;
973
- constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
1008
+ constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[], urlPaths?: string[]);
1009
+ /**
1010
+ * Ensures the connection pool has the required size based on the configured mode and number of URL paths.
1011
+ *
1012
+ * If no URL paths are configured, the method returns early without modifications.
1013
+ * In 'pool' mode, the pool size is multiplied by the number of URL paths.
1014
+ * In 'single' mode, only one connection per URL path is maintained.
1015
+ *
1016
+ * New connections are initialized with unique IDs and default state flags when the pool
1017
+ * size is less than the expected size.
1018
+ *
1019
+ * @private
1020
+ * @returns {void}
1021
+ */
1022
+ private ensurePoolSizeForUrlPaths;
974
1023
  /**
975
1024
  * Formats the WebSocket URL for a given stream or streams.
976
1025
  * @param streams - Array of stream names to include in the URL.
1026
+ * @param urlPath - Optional URL path to include in the WebSocket URL.
977
1027
  * @returns The formatted WebSocket URL with the provided streams.
978
1028
  */
979
1029
  private prepareURL;
@@ -987,6 +1037,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
987
1037
  /**
988
1038
  * Handles subscription to streams and assigns them to specific connections
989
1039
  * @param streams Array of stream names to subscribe to
1040
+ * @param urlPath Optional URL path for the streams
990
1041
  * @returns Map of connections to streams
991
1042
  */
992
1043
  private handleStreamAssignment;
@@ -1020,6 +1071,13 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
1020
1071
  * @param oldConnection The previous WebSocket connection, if any.
1021
1072
  */
1022
1073
  protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
1074
+ /**
1075
+ * Generates a stream key by combining a stream name with an optional URL path.
1076
+ * @param stream - The stream name to use as the key or suffix.
1077
+ * @param urlPath - Optional URL path to prepend to the stream name.
1078
+ * @returns A stream key in the format `urlPath::stream` if urlPath is provided, otherwise just the stream name.
1079
+ */
1080
+ streamKey(stream: string, urlPath?: string): string;
1023
1081
  /**
1024
1082
  * Connects to the WebSocket server and subscribes to the specified streams.
1025
1083
  * This method returns a Promise that resolves when the connection is established,
@@ -1038,17 +1096,19 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
1038
1096
  * Handles both single and pool modes
1039
1097
  * @param stream Single stream name or array of stream names to subscribe to
1040
1098
  * @param id Optional subscription ID
1099
+ * @param urlPath Optional URL path for the streams
1041
1100
  * @returns void
1042
1101
  */
1043
- subscribe(stream: string | string[], id?: string): void;
1102
+ subscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
1044
1103
  /**
1045
1104
  * Unsubscribes from one or multiple WebSocket streams
1046
1105
  * Handles both single and pool modes
1047
1106
  * @param stream Single stream name or array of stream names to unsubscribe from
1048
1107
  * @param id Optional unsubscription ID
1108
+ * @param urlPath Optional URL path for the streams
1049
1109
  * @returns void
1050
1110
  */
1051
- unsubscribe(stream: string | string[], id?: string): void;
1111
+ unsubscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
1052
1112
  /**
1053
1113
  * Checks if the specified stream is currently subscribed.
1054
1114
  * @param stream - The name of the stream to check.
@@ -1075,9 +1135,10 @@ interface WebsocketStream<T> {
1075
1135
  * @param {WebsocketAPIBase | WebsocketStreamsBase} websocketBase The WebSocket base instance
1076
1136
  * @param {string} streamOrId The stream identifier
1077
1137
  * @param {string} [id] Optional additional identifier
1138
+ * @param {string} [urlPath] Optional URL path for the stream
1078
1139
  * @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
1079
1140
  */
1080
- declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
1141
+ declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string, urlPath?: string): WebsocketStream<T>;
1081
1142
  //#endregion
1082
- export { ALGO_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_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, 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, TimerRecord, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketApiRateLimit, WebsocketApiResponse, WebsocketCommon, WebsocketConnection, WebsocketEventEmitter, WebsocketSendMsgConfig, WebsocketSendMsgOptions, WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, buildUserAgent, buildWebsocketAPIMessage, clearSignerCache, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, normalizeScientificNumbers, parseCustomHeaders, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sanitizeHeaderValue, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
1143
+ export { ALGO_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_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, 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, TimerRecord, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, WebsocketApiRateLimit, WebsocketApiResponse, WebsocketCommon, WebsocketConnection, WebsocketEventEmitter, WebsocketSendMsgConfig, WebsocketSendMsgOptions, WebsocketStream, 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 };
1083
1144
  //# sourceMappingURL=index.d.ts.map