@binance/common 2.1.1 → 2.3.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 +56 -16
- package/dist/index.d.ts +56 -16
- package/dist/index.js +132 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
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";
|
|
@@ -310,7 +312,8 @@ declare class ConfigurationWebsocketStreams {
|
|
|
310
312
|
* @param msg - An optional error message.
|
|
311
313
|
*/
|
|
312
314
|
declare class ConnectorClientError extends Error {
|
|
313
|
-
|
|
315
|
+
code?: number;
|
|
316
|
+
constructor(msg?: string, code?: number);
|
|
314
317
|
}
|
|
315
318
|
/**
|
|
316
319
|
* Represents an error that occurs when a required parameter is missing or undefined.
|
|
@@ -326,28 +329,32 @@ declare class RequiredError extends Error {
|
|
|
326
329
|
* @param msg - An optional error message.
|
|
327
330
|
*/
|
|
328
331
|
declare class UnauthorizedError extends Error {
|
|
329
|
-
|
|
332
|
+
code?: number;
|
|
333
|
+
constructor(msg?: string, code?: number);
|
|
330
334
|
}
|
|
331
335
|
/**
|
|
332
336
|
* Represents an error that occurs when a resource is forbidden to the client.
|
|
333
337
|
* @param msg - An optional error message.
|
|
334
338
|
*/
|
|
335
339
|
declare class ForbiddenError extends Error {
|
|
336
|
-
|
|
340
|
+
code?: number;
|
|
341
|
+
constructor(msg?: string, code?: number);
|
|
337
342
|
}
|
|
338
343
|
/**
|
|
339
344
|
* Represents an error that occurs when client is doing too many requests.
|
|
340
345
|
* @param msg - An optional error message.
|
|
341
346
|
*/
|
|
342
347
|
declare class TooManyRequestsError extends Error {
|
|
343
|
-
|
|
348
|
+
code?: number;
|
|
349
|
+
constructor(msg?: string, code?: number);
|
|
344
350
|
}
|
|
345
351
|
/**
|
|
346
352
|
* Represents an error that occurs when client's IP has been banned.
|
|
347
353
|
* @param msg - An optional error message.
|
|
348
354
|
*/
|
|
349
355
|
declare class RateLimitBanError extends Error {
|
|
350
|
-
|
|
356
|
+
code?: number;
|
|
357
|
+
constructor(msg?: string, code?: number);
|
|
351
358
|
}
|
|
352
359
|
/**
|
|
353
360
|
* Represents an error that occurs when there is an internal server error.
|
|
@@ -370,14 +377,16 @@ declare class NetworkError extends Error {
|
|
|
370
377
|
* @param msg - An optional error message.
|
|
371
378
|
*/
|
|
372
379
|
declare class NotFoundError extends Error {
|
|
373
|
-
|
|
380
|
+
code?: number;
|
|
381
|
+
constructor(msg?: string, code?: number);
|
|
374
382
|
}
|
|
375
383
|
/**
|
|
376
384
|
* Represents an error that occurs when a request is invalid or cannot be otherwise served.
|
|
377
385
|
* @param msg - An optional error message.
|
|
378
386
|
*/
|
|
379
387
|
declare class BadRequestError extends Error {
|
|
380
|
-
|
|
388
|
+
code?: number;
|
|
389
|
+
constructor(msg?: string, code?: number);
|
|
381
390
|
}
|
|
382
391
|
//#endregion
|
|
383
392
|
//#region src/logger.d.ts
|
|
@@ -759,6 +768,7 @@ interface WebsocketConnection {
|
|
|
759
768
|
}>;
|
|
760
769
|
pendingSubscriptions?: string[];
|
|
761
770
|
ws?: WebSocketClient;
|
|
771
|
+
urlPath?: string;
|
|
762
772
|
isSessionLoggedOn?: boolean;
|
|
763
773
|
sessionLogonReq?: {
|
|
764
774
|
method: string;
|
|
@@ -793,18 +803,20 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
|
|
|
793
803
|
* In 'single' mode, returns the first connection in the pool.
|
|
794
804
|
* In 'pool' mode, filters and returns connections that are ready for use.
|
|
795
805
|
* @param allowNonEstablishedWebsockets - Optional flag to include non-established WebSocket connections.
|
|
806
|
+
* @param urlPath - Optional URL path to filter connections.
|
|
796
807
|
* @returns An array of available WebSocket connections.
|
|
797
808
|
*/
|
|
798
|
-
protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean): WebsocketConnection[];
|
|
809
|
+
protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection[];
|
|
799
810
|
/**
|
|
800
811
|
* Gets a WebSocket connection from the pool or single connection.
|
|
801
812
|
* If the connection mode is 'single', it returns the first connection in the pool.
|
|
802
813
|
* If the connection mode is 'pool', it returns an available connection from the pool,
|
|
803
814
|
* using a round-robin selection strategy. If no available connections are found, it throws an error.
|
|
804
815
|
* @param allowNonEstablishedWebsockets - A boolean indicating whether to allow connections that are not established.
|
|
816
|
+
* @param urlPath - An optional URL path to filter connections.
|
|
805
817
|
* @returns {WebsocketConnection} The selected WebSocket connection.
|
|
806
818
|
*/
|
|
807
|
-
protected getConnection(allowNonEstablishedWebsockets?: boolean): WebsocketConnection;
|
|
819
|
+
protected getConnection(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection;
|
|
808
820
|
/**
|
|
809
821
|
* Checks if the provided WebSocket connection is ready for use.
|
|
810
822
|
* A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
|
|
@@ -899,9 +911,10 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
|
|
|
899
911
|
/**
|
|
900
912
|
* Connects all WebSocket connections in the pool
|
|
901
913
|
* @param url - The Websocket server URL.
|
|
914
|
+
* @param connections - An optional array of WebSocket connections to connect. If not provided, all connections in the pool are connected.
|
|
902
915
|
* @returns A promise that resolves when all connections are established.
|
|
903
916
|
*/
|
|
904
|
-
protected connectPool(url: string): Promise<void>;
|
|
917
|
+
protected connectPool(url: string, connections?: WebsocketConnection[]): Promise<void>;
|
|
905
918
|
/**
|
|
906
919
|
* Creates a new WebSocket client instance.
|
|
907
920
|
* @param url - The URL to connect to.
|
|
@@ -993,15 +1006,31 @@ declare class WebsocketAPIBase extends WebsocketCommon {
|
|
|
993
1006
|
}
|
|
994
1007
|
declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
995
1008
|
private streamConnectionMap;
|
|
1009
|
+
protected urlPaths: string[];
|
|
996
1010
|
protected configuration: ConfigurationWebsocketStreams;
|
|
997
1011
|
protected wsURL: string;
|
|
998
1012
|
streamIdIsStrictlyNumber?: boolean;
|
|
999
1013
|
streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
|
|
1000
1014
|
logger: Logger;
|
|
1001
|
-
constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
|
|
1015
|
+
constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[], urlPaths?: string[]);
|
|
1016
|
+
/**
|
|
1017
|
+
* Ensures the connection pool has the required size based on the configured mode and number of URL paths.
|
|
1018
|
+
*
|
|
1019
|
+
* If no URL paths are configured, the method returns early without modifications.
|
|
1020
|
+
* In 'pool' mode, the pool size is multiplied by the number of URL paths.
|
|
1021
|
+
* In 'single' mode, only one connection per URL path is maintained.
|
|
1022
|
+
*
|
|
1023
|
+
* New connections are initialized with unique IDs and default state flags when the pool
|
|
1024
|
+
* size is less than the expected size.
|
|
1025
|
+
*
|
|
1026
|
+
* @private
|
|
1027
|
+
* @returns {void}
|
|
1028
|
+
*/
|
|
1029
|
+
private ensurePoolSizeForUrlPaths;
|
|
1002
1030
|
/**
|
|
1003
1031
|
* Formats the WebSocket URL for a given stream or streams.
|
|
1004
1032
|
* @param streams - Array of stream names to include in the URL.
|
|
1033
|
+
* @param urlPath - Optional URL path to include in the WebSocket URL.
|
|
1005
1034
|
* @returns The formatted WebSocket URL with the provided streams.
|
|
1006
1035
|
*/
|
|
1007
1036
|
private prepareURL;
|
|
@@ -1015,6 +1044,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1015
1044
|
/**
|
|
1016
1045
|
* Handles subscription to streams and assigns them to specific connections
|
|
1017
1046
|
* @param streams Array of stream names to subscribe to
|
|
1047
|
+
* @param urlPath Optional URL path for the streams
|
|
1018
1048
|
* @returns Map of connections to streams
|
|
1019
1049
|
*/
|
|
1020
1050
|
private handleStreamAssignment;
|
|
@@ -1048,6 +1078,13 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1048
1078
|
* @param oldConnection The previous WebSocket connection, if any.
|
|
1049
1079
|
*/
|
|
1050
1080
|
protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
|
|
1081
|
+
/**
|
|
1082
|
+
* Generates a stream key by combining a stream name with an optional URL path.
|
|
1083
|
+
* @param stream - The stream name to use as the key or suffix.
|
|
1084
|
+
* @param urlPath - Optional URL path to prepend to the stream name.
|
|
1085
|
+
* @returns A stream key in the format `urlPath::stream` if urlPath is provided, otherwise just the stream name.
|
|
1086
|
+
*/
|
|
1087
|
+
streamKey(stream: string, urlPath?: string): string;
|
|
1051
1088
|
/**
|
|
1052
1089
|
* Connects to the WebSocket server and subscribes to the specified streams.
|
|
1053
1090
|
* This method returns a Promise that resolves when the connection is established,
|
|
@@ -1066,17 +1103,19 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1066
1103
|
* Handles both single and pool modes
|
|
1067
1104
|
* @param stream Single stream name or array of stream names to subscribe to
|
|
1068
1105
|
* @param id Optional subscription ID
|
|
1106
|
+
* @param urlPath Optional URL path for the streams
|
|
1069
1107
|
* @returns void
|
|
1070
1108
|
*/
|
|
1071
|
-
subscribe(stream: string | string[], id?: number | string): void;
|
|
1109
|
+
subscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
|
|
1072
1110
|
/**
|
|
1073
1111
|
* Unsubscribes from one or multiple WebSocket streams
|
|
1074
1112
|
* Handles both single and pool modes
|
|
1075
1113
|
* @param stream Single stream name or array of stream names to unsubscribe from
|
|
1076
1114
|
* @param id Optional unsubscription ID
|
|
1115
|
+
* @param urlPath Optional URL path for the streams
|
|
1077
1116
|
* @returns void
|
|
1078
1117
|
*/
|
|
1079
|
-
unsubscribe(stream: string | string[], id?: number | string): void;
|
|
1118
|
+
unsubscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
|
|
1080
1119
|
/**
|
|
1081
1120
|
* Checks if the specified stream is currently subscribed.
|
|
1082
1121
|
* @param stream - The name of the stream to check.
|
|
@@ -1103,9 +1142,10 @@ interface WebsocketStream<T> {
|
|
|
1103
1142
|
* @param {WebsocketAPIBase | WebsocketStreamsBase} websocketBase The WebSocket base instance
|
|
1104
1143
|
* @param {string} streamOrId The stream identifier
|
|
1105
1144
|
* @param {string} [id] Optional additional identifier
|
|
1145
|
+
* @param {string} [urlPath] Optional URL path for the stream
|
|
1106
1146
|
* @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
|
|
1107
1147
|
*/
|
|
1108
|
-
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string): WebsocketStream<T>;
|
|
1148
|
+
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string, urlPath?: string): WebsocketStream<T>;
|
|
1109
1149
|
//#endregion
|
|
1110
|
-
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, normalizeStreamId, parseCustomHeaders, parseRateLimitHeaders, randomInteger, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sanitizeHeaderValue, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
|
1150
|
+
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 };
|
|
1111
1151
|
//# 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
|
|
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";
|
|
@@ -310,7 +312,8 @@ declare class ConfigurationWebsocketStreams {
|
|
|
310
312
|
* @param msg - An optional error message.
|
|
311
313
|
*/
|
|
312
314
|
declare class ConnectorClientError extends Error {
|
|
313
|
-
|
|
315
|
+
code?: number;
|
|
316
|
+
constructor(msg?: string, code?: number);
|
|
314
317
|
}
|
|
315
318
|
/**
|
|
316
319
|
* Represents an error that occurs when a required parameter is missing or undefined.
|
|
@@ -326,28 +329,32 @@ declare class RequiredError extends Error {
|
|
|
326
329
|
* @param msg - An optional error message.
|
|
327
330
|
*/
|
|
328
331
|
declare class UnauthorizedError extends Error {
|
|
329
|
-
|
|
332
|
+
code?: number;
|
|
333
|
+
constructor(msg?: string, code?: number);
|
|
330
334
|
}
|
|
331
335
|
/**
|
|
332
336
|
* Represents an error that occurs when a resource is forbidden to the client.
|
|
333
337
|
* @param msg - An optional error message.
|
|
334
338
|
*/
|
|
335
339
|
declare class ForbiddenError extends Error {
|
|
336
|
-
|
|
340
|
+
code?: number;
|
|
341
|
+
constructor(msg?: string, code?: number);
|
|
337
342
|
}
|
|
338
343
|
/**
|
|
339
344
|
* Represents an error that occurs when client is doing too many requests.
|
|
340
345
|
* @param msg - An optional error message.
|
|
341
346
|
*/
|
|
342
347
|
declare class TooManyRequestsError extends Error {
|
|
343
|
-
|
|
348
|
+
code?: number;
|
|
349
|
+
constructor(msg?: string, code?: number);
|
|
344
350
|
}
|
|
345
351
|
/**
|
|
346
352
|
* Represents an error that occurs when client's IP has been banned.
|
|
347
353
|
* @param msg - An optional error message.
|
|
348
354
|
*/
|
|
349
355
|
declare class RateLimitBanError extends Error {
|
|
350
|
-
|
|
356
|
+
code?: number;
|
|
357
|
+
constructor(msg?: string, code?: number);
|
|
351
358
|
}
|
|
352
359
|
/**
|
|
353
360
|
* Represents an error that occurs when there is an internal server error.
|
|
@@ -370,14 +377,16 @@ declare class NetworkError extends Error {
|
|
|
370
377
|
* @param msg - An optional error message.
|
|
371
378
|
*/
|
|
372
379
|
declare class NotFoundError extends Error {
|
|
373
|
-
|
|
380
|
+
code?: number;
|
|
381
|
+
constructor(msg?: string, code?: number);
|
|
374
382
|
}
|
|
375
383
|
/**
|
|
376
384
|
* Represents an error that occurs when a request is invalid or cannot be otherwise served.
|
|
377
385
|
* @param msg - An optional error message.
|
|
378
386
|
*/
|
|
379
387
|
declare class BadRequestError extends Error {
|
|
380
|
-
|
|
388
|
+
code?: number;
|
|
389
|
+
constructor(msg?: string, code?: number);
|
|
381
390
|
}
|
|
382
391
|
//#endregion
|
|
383
392
|
//#region src/logger.d.ts
|
|
@@ -759,6 +768,7 @@ interface WebsocketConnection {
|
|
|
759
768
|
}>;
|
|
760
769
|
pendingSubscriptions?: string[];
|
|
761
770
|
ws?: WebSocketClient;
|
|
771
|
+
urlPath?: string;
|
|
762
772
|
isSessionLoggedOn?: boolean;
|
|
763
773
|
sessionLogonReq?: {
|
|
764
774
|
method: string;
|
|
@@ -793,18 +803,20 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
|
|
|
793
803
|
* In 'single' mode, returns the first connection in the pool.
|
|
794
804
|
* In 'pool' mode, filters and returns connections that are ready for use.
|
|
795
805
|
* @param allowNonEstablishedWebsockets - Optional flag to include non-established WebSocket connections.
|
|
806
|
+
* @param urlPath - Optional URL path to filter connections.
|
|
796
807
|
* @returns An array of available WebSocket connections.
|
|
797
808
|
*/
|
|
798
|
-
protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean): WebsocketConnection[];
|
|
809
|
+
protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection[];
|
|
799
810
|
/**
|
|
800
811
|
* Gets a WebSocket connection from the pool or single connection.
|
|
801
812
|
* If the connection mode is 'single', it returns the first connection in the pool.
|
|
802
813
|
* If the connection mode is 'pool', it returns an available connection from the pool,
|
|
803
814
|
* using a round-robin selection strategy. If no available connections are found, it throws an error.
|
|
804
815
|
* @param allowNonEstablishedWebsockets - A boolean indicating whether to allow connections that are not established.
|
|
816
|
+
* @param urlPath - An optional URL path to filter connections.
|
|
805
817
|
* @returns {WebsocketConnection} The selected WebSocket connection.
|
|
806
818
|
*/
|
|
807
|
-
protected getConnection(allowNonEstablishedWebsockets?: boolean): WebsocketConnection;
|
|
819
|
+
protected getConnection(allowNonEstablishedWebsockets?: boolean, urlPath?: string): WebsocketConnection;
|
|
808
820
|
/**
|
|
809
821
|
* Checks if the provided WebSocket connection is ready for use.
|
|
810
822
|
* A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
|
|
@@ -899,9 +911,10 @@ declare class WebsocketCommon extends WebsocketEventEmitter {
|
|
|
899
911
|
/**
|
|
900
912
|
* Connects all WebSocket connections in the pool
|
|
901
913
|
* @param url - The Websocket server URL.
|
|
914
|
+
* @param connections - An optional array of WebSocket connections to connect. If not provided, all connections in the pool are connected.
|
|
902
915
|
* @returns A promise that resolves when all connections are established.
|
|
903
916
|
*/
|
|
904
|
-
protected connectPool(url: string): Promise<void>;
|
|
917
|
+
protected connectPool(url: string, connections?: WebsocketConnection[]): Promise<void>;
|
|
905
918
|
/**
|
|
906
919
|
* Creates a new WebSocket client instance.
|
|
907
920
|
* @param url - The URL to connect to.
|
|
@@ -993,15 +1006,31 @@ declare class WebsocketAPIBase extends WebsocketCommon {
|
|
|
993
1006
|
}
|
|
994
1007
|
declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
995
1008
|
private streamConnectionMap;
|
|
1009
|
+
protected urlPaths: string[];
|
|
996
1010
|
protected configuration: ConfigurationWebsocketStreams;
|
|
997
1011
|
protected wsURL: string;
|
|
998
1012
|
streamIdIsStrictlyNumber?: boolean;
|
|
999
1013
|
streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
|
|
1000
1014
|
logger: Logger;
|
|
1001
|
-
constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
|
|
1015
|
+
constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[], urlPaths?: string[]);
|
|
1016
|
+
/**
|
|
1017
|
+
* Ensures the connection pool has the required size based on the configured mode and number of URL paths.
|
|
1018
|
+
*
|
|
1019
|
+
* If no URL paths are configured, the method returns early without modifications.
|
|
1020
|
+
* In 'pool' mode, the pool size is multiplied by the number of URL paths.
|
|
1021
|
+
* In 'single' mode, only one connection per URL path is maintained.
|
|
1022
|
+
*
|
|
1023
|
+
* New connections are initialized with unique IDs and default state flags when the pool
|
|
1024
|
+
* size is less than the expected size.
|
|
1025
|
+
*
|
|
1026
|
+
* @private
|
|
1027
|
+
* @returns {void}
|
|
1028
|
+
*/
|
|
1029
|
+
private ensurePoolSizeForUrlPaths;
|
|
1002
1030
|
/**
|
|
1003
1031
|
* Formats the WebSocket URL for a given stream or streams.
|
|
1004
1032
|
* @param streams - Array of stream names to include in the URL.
|
|
1033
|
+
* @param urlPath - Optional URL path to include in the WebSocket URL.
|
|
1005
1034
|
* @returns The formatted WebSocket URL with the provided streams.
|
|
1006
1035
|
*/
|
|
1007
1036
|
private prepareURL;
|
|
@@ -1015,6 +1044,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1015
1044
|
/**
|
|
1016
1045
|
* Handles subscription to streams and assigns them to specific connections
|
|
1017
1046
|
* @param streams Array of stream names to subscribe to
|
|
1047
|
+
* @param urlPath Optional URL path for the streams
|
|
1018
1048
|
* @returns Map of connections to streams
|
|
1019
1049
|
*/
|
|
1020
1050
|
private handleStreamAssignment;
|
|
@@ -1048,6 +1078,13 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1048
1078
|
* @param oldConnection The previous WebSocket connection, if any.
|
|
1049
1079
|
*/
|
|
1050
1080
|
protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
|
|
1081
|
+
/**
|
|
1082
|
+
* Generates a stream key by combining a stream name with an optional URL path.
|
|
1083
|
+
* @param stream - The stream name to use as the key or suffix.
|
|
1084
|
+
* @param urlPath - Optional URL path to prepend to the stream name.
|
|
1085
|
+
* @returns A stream key in the format `urlPath::stream` if urlPath is provided, otherwise just the stream name.
|
|
1086
|
+
*/
|
|
1087
|
+
streamKey(stream: string, urlPath?: string): string;
|
|
1051
1088
|
/**
|
|
1052
1089
|
* Connects to the WebSocket server and subscribes to the specified streams.
|
|
1053
1090
|
* This method returns a Promise that resolves when the connection is established,
|
|
@@ -1066,17 +1103,19 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1066
1103
|
* Handles both single and pool modes
|
|
1067
1104
|
* @param stream Single stream name or array of stream names to subscribe to
|
|
1068
1105
|
* @param id Optional subscription ID
|
|
1106
|
+
* @param urlPath Optional URL path for the streams
|
|
1069
1107
|
* @returns void
|
|
1070
1108
|
*/
|
|
1071
|
-
subscribe(stream: string | string[], id?: number | string): void;
|
|
1109
|
+
subscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
|
|
1072
1110
|
/**
|
|
1073
1111
|
* Unsubscribes from one or multiple WebSocket streams
|
|
1074
1112
|
* Handles both single and pool modes
|
|
1075
1113
|
* @param stream Single stream name or array of stream names to unsubscribe from
|
|
1076
1114
|
* @param id Optional unsubscription ID
|
|
1115
|
+
* @param urlPath Optional URL path for the streams
|
|
1077
1116
|
* @returns void
|
|
1078
1117
|
*/
|
|
1079
|
-
unsubscribe(stream: string | string[], id?: number | string): void;
|
|
1118
|
+
unsubscribe(stream: string | string[], id?: number | string, urlPath?: string): void;
|
|
1080
1119
|
/**
|
|
1081
1120
|
* Checks if the specified stream is currently subscribed.
|
|
1082
1121
|
* @param stream - The name of the stream to check.
|
|
@@ -1103,9 +1142,10 @@ interface WebsocketStream<T> {
|
|
|
1103
1142
|
* @param {WebsocketAPIBase | WebsocketStreamsBase} websocketBase The WebSocket base instance
|
|
1104
1143
|
* @param {string} streamOrId The stream identifier
|
|
1105
1144
|
* @param {string} [id] Optional additional identifier
|
|
1145
|
+
* @param {string} [urlPath] Optional URL path for the stream
|
|
1106
1146
|
* @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
|
|
1107
1147
|
*/
|
|
1108
|
-
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string): WebsocketStream<T>;
|
|
1148
|
+
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string, urlPath?: string): WebsocketStream<T>;
|
|
1109
1149
|
//#endregion
|
|
1110
|
-
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, normalizeStreamId, parseCustomHeaders, parseRateLimitHeaders, randomInteger, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sanitizeHeaderValue, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
|
1150
|
+
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 };
|
|
1111
1151
|
//# sourceMappingURL=index.d.ts.map
|