@binance/common 2.0.1 → 2.1.1
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 +38 -8
- package/dist/index.d.ts +38 -8
- package/dist/index.js +62 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/index.d.mts
CHANGED
|
@@ -492,13 +492,15 @@ interface AxiosRequestArgs {
|
|
|
492
492
|
* Represents the arguments for a request.
|
|
493
493
|
* @property {string} endpoint - The endpoint for the request.
|
|
494
494
|
* @property {'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH'} method - The HTTP method for the request.
|
|
495
|
-
* @property {Record<string, unknown>}
|
|
495
|
+
* @property {Record<string, unknown>} queryParams - The query parameters for the request.
|
|
496
|
+
* @property {Record<string, unknown>} bodyParams - The body parameters for the request.
|
|
496
497
|
* @property {TimeUnit} [timeUnit] - The optional time unit for the request.
|
|
497
498
|
*/
|
|
498
499
|
interface RequestArgs {
|
|
499
500
|
endpoint: string;
|
|
500
501
|
method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
|
|
501
|
-
|
|
502
|
+
queryParams: Record<string, unknown>;
|
|
503
|
+
bodyParams: Record<string, unknown>;
|
|
502
504
|
timeUnit?: TimeUnit;
|
|
503
505
|
}
|
|
504
506
|
//#endregion
|
|
@@ -527,6 +529,33 @@ declare function buildQueryString(params: Record<string, unknown>): string;
|
|
|
527
529
|
* @returns A random string of 16 hexadecimal characters.
|
|
528
530
|
*/
|
|
529
531
|
declare function randomString(): string;
|
|
532
|
+
/**
|
|
533
|
+
* Generates a cryptographically secure random 32-bit unsigned integer.
|
|
534
|
+
*
|
|
535
|
+
* Uses the Web Crypto API to generate a random value between 0 and 4,294,967,295 (2^32 - 1).
|
|
536
|
+
*
|
|
537
|
+
* @returns A random 32-bit unsigned integer.
|
|
538
|
+
*/
|
|
539
|
+
declare function randomInteger(): number;
|
|
540
|
+
/**
|
|
541
|
+
* Normalizes a stream ID to ensure it is valid, generating a random ID if needed.
|
|
542
|
+
*
|
|
543
|
+
* For string inputs:
|
|
544
|
+
* - Returns the input if it's a valid 32-character hexadecimal string (case-insensitive)
|
|
545
|
+
* - Otherwise, generates a new random hexadecimal string using `randomString()`
|
|
546
|
+
*
|
|
547
|
+
* For number inputs:
|
|
548
|
+
* - Returns the input if it's a finite, non-negative integer within the safe integer range
|
|
549
|
+
* - Otherwise, generates a new random integer using `randomInteger()`
|
|
550
|
+
*
|
|
551
|
+
* For null or undefined inputs:
|
|
552
|
+
* - Generates a new random hexadecimal string using `randomString()`
|
|
553
|
+
*
|
|
554
|
+
* @param id - The stream ID to normalize (string, number, null, or undefined).
|
|
555
|
+
* @param streamIdIsStrictlyNumber - Boolean forcing an id to be a number or not.
|
|
556
|
+
* @returns A valid stream ID as either a 32-character hexadecimal string or a safe integer.
|
|
557
|
+
*/
|
|
558
|
+
declare function normalizeStreamId(id: string | number | null | undefined, streamIdIsStrictlyNumber?: boolean): string | number;
|
|
530
559
|
/**
|
|
531
560
|
* Validates the provided time unit string and returns it if it is either 'MILLISECOND' or 'MICROSECOND'.
|
|
532
561
|
*
|
|
@@ -559,7 +588,7 @@ declare const getSignature: (configuration: {
|
|
|
559
588
|
apiSecret?: string;
|
|
560
589
|
privateKey?: string | Buffer;
|
|
561
590
|
privateKeyPassphrase?: string;
|
|
562
|
-
}, queryParams: Record<string, unknown>) => string;
|
|
591
|
+
}, queryParams: Record<string, unknown>, bodyParams?: Record<string, unknown>) => string;
|
|
563
592
|
/**
|
|
564
593
|
* Asserts that a function parameter exists and is not null or undefined.
|
|
565
594
|
*
|
|
@@ -641,7 +670,7 @@ declare const parseRateLimitHeaders: (headers: RawAxiosResponseHeaders | AxiosRe
|
|
|
641
670
|
* @param options - Additional request options (isSigned).
|
|
642
671
|
* @returns A promise resolving to the response data object.
|
|
643
672
|
*/
|
|
644
|
-
declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH",
|
|
673
|
+
declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH", queryParams?: Record<string, unknown>, bodyParams?: Record<string, unknown>, timeUnit?: TimeUnit, options?: {
|
|
645
674
|
isSigned?: boolean;
|
|
646
675
|
}) => Promise<RestApiResponse<T>>;
|
|
647
676
|
/**
|
|
@@ -966,6 +995,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
966
995
|
private streamConnectionMap;
|
|
967
996
|
protected configuration: ConfigurationWebsocketStreams;
|
|
968
997
|
protected wsURL: string;
|
|
998
|
+
streamIdIsStrictlyNumber?: boolean;
|
|
969
999
|
streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
|
|
970
1000
|
logger: Logger;
|
|
971
1001
|
constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
|
|
@@ -1038,7 +1068,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1038
1068
|
* @param id Optional subscription ID
|
|
1039
1069
|
* @returns void
|
|
1040
1070
|
*/
|
|
1041
|
-
subscribe(stream: string | string[], id?: string): void;
|
|
1071
|
+
subscribe(stream: string | string[], id?: number | string): void;
|
|
1042
1072
|
/**
|
|
1043
1073
|
* Unsubscribes from one or multiple WebSocket streams
|
|
1044
1074
|
* Handles both single and pool modes
|
|
@@ -1046,7 +1076,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1046
1076
|
* @param id Optional unsubscription ID
|
|
1047
1077
|
* @returns void
|
|
1048
1078
|
*/
|
|
1049
|
-
unsubscribe(stream: string | string[], id?: string): void;
|
|
1079
|
+
unsubscribe(stream: string | string[], id?: number | string): void;
|
|
1050
1080
|
/**
|
|
1051
1081
|
* Checks if the specified stream is currently subscribed.
|
|
1052
1082
|
* @param stream - The name of the stream to check.
|
|
@@ -1075,7 +1105,7 @@ interface WebsocketStream<T> {
|
|
|
1075
1105
|
* @param {string} [id] Optional additional identifier
|
|
1076
1106
|
* @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
|
|
1077
1107
|
*/
|
|
1078
|
-
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
|
|
1108
|
+
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string): WebsocketStream<T>;
|
|
1079
1109
|
//#endregion
|
|
1080
|
-
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 };
|
|
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 };
|
|
1081
1111
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -492,13 +492,15 @@ interface AxiosRequestArgs {
|
|
|
492
492
|
* Represents the arguments for a request.
|
|
493
493
|
* @property {string} endpoint - The endpoint for the request.
|
|
494
494
|
* @property {'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH'} method - The HTTP method for the request.
|
|
495
|
-
* @property {Record<string, unknown>}
|
|
495
|
+
* @property {Record<string, unknown>} queryParams - The query parameters for the request.
|
|
496
|
+
* @property {Record<string, unknown>} bodyParams - The body parameters for the request.
|
|
496
497
|
* @property {TimeUnit} [timeUnit] - The optional time unit for the request.
|
|
497
498
|
*/
|
|
498
499
|
interface RequestArgs {
|
|
499
500
|
endpoint: string;
|
|
500
501
|
method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
|
|
501
|
-
|
|
502
|
+
queryParams: Record<string, unknown>;
|
|
503
|
+
bodyParams: Record<string, unknown>;
|
|
502
504
|
timeUnit?: TimeUnit;
|
|
503
505
|
}
|
|
504
506
|
//#endregion
|
|
@@ -527,6 +529,33 @@ declare function buildQueryString(params: Record<string, unknown>): string;
|
|
|
527
529
|
* @returns A random string of 16 hexadecimal characters.
|
|
528
530
|
*/
|
|
529
531
|
declare function randomString(): string;
|
|
532
|
+
/**
|
|
533
|
+
* Generates a cryptographically secure random 32-bit unsigned integer.
|
|
534
|
+
*
|
|
535
|
+
* Uses the Web Crypto API to generate a random value between 0 and 4,294,967,295 (2^32 - 1).
|
|
536
|
+
*
|
|
537
|
+
* @returns A random 32-bit unsigned integer.
|
|
538
|
+
*/
|
|
539
|
+
declare function randomInteger(): number;
|
|
540
|
+
/**
|
|
541
|
+
* Normalizes a stream ID to ensure it is valid, generating a random ID if needed.
|
|
542
|
+
*
|
|
543
|
+
* For string inputs:
|
|
544
|
+
* - Returns the input if it's a valid 32-character hexadecimal string (case-insensitive)
|
|
545
|
+
* - Otherwise, generates a new random hexadecimal string using `randomString()`
|
|
546
|
+
*
|
|
547
|
+
* For number inputs:
|
|
548
|
+
* - Returns the input if it's a finite, non-negative integer within the safe integer range
|
|
549
|
+
* - Otherwise, generates a new random integer using `randomInteger()`
|
|
550
|
+
*
|
|
551
|
+
* For null or undefined inputs:
|
|
552
|
+
* - Generates a new random hexadecimal string using `randomString()`
|
|
553
|
+
*
|
|
554
|
+
* @param id - The stream ID to normalize (string, number, null, or undefined).
|
|
555
|
+
* @param streamIdIsStrictlyNumber - Boolean forcing an id to be a number or not.
|
|
556
|
+
* @returns A valid stream ID as either a 32-character hexadecimal string or a safe integer.
|
|
557
|
+
*/
|
|
558
|
+
declare function normalizeStreamId(id: string | number | null | undefined, streamIdIsStrictlyNumber?: boolean): string | number;
|
|
530
559
|
/**
|
|
531
560
|
* Validates the provided time unit string and returns it if it is either 'MILLISECOND' or 'MICROSECOND'.
|
|
532
561
|
*
|
|
@@ -559,7 +588,7 @@ declare const getSignature: (configuration: {
|
|
|
559
588
|
apiSecret?: string;
|
|
560
589
|
privateKey?: string | Buffer;
|
|
561
590
|
privateKeyPassphrase?: string;
|
|
562
|
-
}, queryParams: Record<string, unknown>) => string;
|
|
591
|
+
}, queryParams: Record<string, unknown>, bodyParams?: Record<string, unknown>) => string;
|
|
563
592
|
/**
|
|
564
593
|
* Asserts that a function parameter exists and is not null or undefined.
|
|
565
594
|
*
|
|
@@ -641,7 +670,7 @@ declare const parseRateLimitHeaders: (headers: RawAxiosResponseHeaders | AxiosRe
|
|
|
641
670
|
* @param options - Additional request options (isSigned).
|
|
642
671
|
* @returns A promise resolving to the response data object.
|
|
643
672
|
*/
|
|
644
|
-
declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH",
|
|
673
|
+
declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH", queryParams?: Record<string, unknown>, bodyParams?: Record<string, unknown>, timeUnit?: TimeUnit, options?: {
|
|
645
674
|
isSigned?: boolean;
|
|
646
675
|
}) => Promise<RestApiResponse<T>>;
|
|
647
676
|
/**
|
|
@@ -966,6 +995,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
966
995
|
private streamConnectionMap;
|
|
967
996
|
protected configuration: ConfigurationWebsocketStreams;
|
|
968
997
|
protected wsURL: string;
|
|
998
|
+
streamIdIsStrictlyNumber?: boolean;
|
|
969
999
|
streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
|
|
970
1000
|
logger: Logger;
|
|
971
1001
|
constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
|
|
@@ -1038,7 +1068,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1038
1068
|
* @param id Optional subscription ID
|
|
1039
1069
|
* @returns void
|
|
1040
1070
|
*/
|
|
1041
|
-
subscribe(stream: string | string[], id?: string): void;
|
|
1071
|
+
subscribe(stream: string | string[], id?: number | string): void;
|
|
1042
1072
|
/**
|
|
1043
1073
|
* Unsubscribes from one or multiple WebSocket streams
|
|
1044
1074
|
* Handles both single and pool modes
|
|
@@ -1046,7 +1076,7 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
1046
1076
|
* @param id Optional unsubscription ID
|
|
1047
1077
|
* @returns void
|
|
1048
1078
|
*/
|
|
1049
|
-
unsubscribe(stream: string | string[], id?: string): void;
|
|
1079
|
+
unsubscribe(stream: string | string[], id?: number | string): void;
|
|
1050
1080
|
/**
|
|
1051
1081
|
* Checks if the specified stream is currently subscribed.
|
|
1052
1082
|
* @param stream - The name of the stream to check.
|
|
@@ -1075,7 +1105,7 @@ interface WebsocketStream<T> {
|
|
|
1075
1105
|
* @param {string} [id] Optional additional identifier
|
|
1076
1106
|
* @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
|
|
1077
1107
|
*/
|
|
1078
|
-
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
|
|
1108
|
+
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: number | string): WebsocketStream<T>;
|
|
1079
1109
|
//#endregion
|
|
1080
|
-
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 };
|
|
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 };
|
|
1081
1111
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -74,8 +74,8 @@ var RequestSigner = class {
|
|
|
74
74
|
}
|
|
75
75
|
throw new Error("Either 'apiSecret' or 'privateKey' must be provided for signed requests.");
|
|
76
76
|
}
|
|
77
|
-
sign(queryParams) {
|
|
78
|
-
const params = buildQueryString(queryParams);
|
|
77
|
+
sign(queryParams, bodyParams) {
|
|
78
|
+
const params = buildQueryString(queryParams) + (bodyParams ? buildQueryString(bodyParams) : "");
|
|
79
79
|
if (this.apiSecret) return crypto.default.createHmac("sha256", this.apiSecret).update(params).digest("hex");
|
|
80
80
|
if (this.keyObject && this.keyType) {
|
|
81
81
|
const data = Buffer.from(params);
|
|
@@ -140,6 +140,42 @@ function randomString() {
|
|
|
140
140
|
return crypto.default.randomBytes(16).toString("hex");
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
|
+
* Generates a cryptographically secure random 32-bit unsigned integer.
|
|
144
|
+
*
|
|
145
|
+
* Uses the Web Crypto API to generate a random value between 0 and 4,294,967,295 (2^32 - 1).
|
|
146
|
+
*
|
|
147
|
+
* @returns A random 32-bit unsigned integer.
|
|
148
|
+
*/
|
|
149
|
+
function randomInteger() {
|
|
150
|
+
const array = new Uint32Array(1);
|
|
151
|
+
crypto.default.getRandomValues(array);
|
|
152
|
+
return array[0];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Normalizes a stream ID to ensure it is valid, generating a random ID if needed.
|
|
156
|
+
*
|
|
157
|
+
* For string inputs:
|
|
158
|
+
* - Returns the input if it's a valid 32-character hexadecimal string (case-insensitive)
|
|
159
|
+
* - Otherwise, generates a new random hexadecimal string using `randomString()`
|
|
160
|
+
*
|
|
161
|
+
* For number inputs:
|
|
162
|
+
* - Returns the input if it's a finite, non-negative integer within the safe integer range
|
|
163
|
+
* - Otherwise, generates a new random integer using `randomInteger()`
|
|
164
|
+
*
|
|
165
|
+
* For null or undefined inputs:
|
|
166
|
+
* - Generates a new random hexadecimal string using `randomString()`
|
|
167
|
+
*
|
|
168
|
+
* @param id - The stream ID to normalize (string, number, null, or undefined).
|
|
169
|
+
* @param streamIdIsStrictlyNumber - Boolean forcing an id to be a number or not.
|
|
170
|
+
* @returns A valid stream ID as either a 32-character hexadecimal string or a safe integer.
|
|
171
|
+
*/
|
|
172
|
+
function normalizeStreamId(id, streamIdIsStrictlyNumber) {
|
|
173
|
+
const isValidNumber = typeof id === "number" && Number.isFinite(id) && Number.isInteger(id) && id >= 0 && id <= Number.MAX_SAFE_INTEGER;
|
|
174
|
+
if (streamIdIsStrictlyNumber || typeof id === "number") return isValidNumber ? id : randomInteger();
|
|
175
|
+
if (typeof id === "string") return id && /^[0-9a-f]{32}$/i.test(id) ? id : randomString();
|
|
176
|
+
return randomString();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
143
179
|
* Validates the provided time unit string and returns it if it is either 'MILLISECOND' or 'MICROSECOND'.
|
|
144
180
|
*
|
|
145
181
|
* @param timeUnit - The time unit string to be validated.
|
|
@@ -175,13 +211,13 @@ function getTimestamp() {
|
|
|
175
211
|
* @param queryParams - The query parameters to be signed.
|
|
176
212
|
* @returns A string representing the generated signature.
|
|
177
213
|
*/
|
|
178
|
-
const getSignature = function(configuration, queryParams) {
|
|
214
|
+
const getSignature = function(configuration, queryParams, bodyParams) {
|
|
179
215
|
let signer = signerCache.get(configuration);
|
|
180
216
|
if (!signer) {
|
|
181
217
|
signer = new RequestSigner(configuration);
|
|
182
218
|
signerCache.set(configuration, signer);
|
|
183
219
|
}
|
|
184
|
-
return signer.sign(queryParams);
|
|
220
|
+
return signer.sign(queryParams, bodyParams);
|
|
185
221
|
};
|
|
186
222
|
/**
|
|
187
223
|
* Asserts that a function parameter exists and is not null or undefined.
|
|
@@ -425,19 +461,33 @@ const parseRateLimitHeaders = function(headers) {
|
|
|
425
461
|
* @param options - Additional request options (isSigned).
|
|
426
462
|
* @returns A promise resolving to the response data object.
|
|
427
463
|
*/
|
|
428
|
-
const sendRequest = function(configuration, endpoint, method,
|
|
464
|
+
const sendRequest = function(configuration, endpoint, method, queryParams = {}, bodyParams = {}, timeUnit, options = {}) {
|
|
429
465
|
const localVarUrlObj = new URL(endpoint, configuration?.basePath);
|
|
430
466
|
const localVarRequestOptions = {
|
|
431
467
|
method,
|
|
432
468
|
...configuration?.baseOptions
|
|
433
469
|
};
|
|
434
|
-
const localVarQueryParameter = { ...normalizeScientificNumbers(
|
|
470
|
+
const localVarQueryParameter = { ...normalizeScientificNumbers(queryParams) };
|
|
471
|
+
const localVarBodyParameter = { ...normalizeScientificNumbers(bodyParams) };
|
|
435
472
|
if (options.isSigned) {
|
|
436
473
|
localVarQueryParameter["timestamp"] = getTimestamp();
|
|
437
|
-
const signature = getSignature(configuration, localVarQueryParameter);
|
|
474
|
+
const signature = getSignature(configuration, localVarQueryParameter, localVarBodyParameter);
|
|
438
475
|
if (signature) localVarQueryParameter["signature"] = signature;
|
|
439
476
|
}
|
|
440
477
|
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
|
478
|
+
if (Object.keys(localVarBodyParameter).length > 0) {
|
|
479
|
+
const searchParams = new URLSearchParams();
|
|
480
|
+
for (const [key, value] of Object.entries(localVarBodyParameter)) {
|
|
481
|
+
if (value === null || value === void 0) continue;
|
|
482
|
+
const serializedValue = serializeValue(value);
|
|
483
|
+
searchParams.append(key, serializedValue);
|
|
484
|
+
}
|
|
485
|
+
localVarRequestOptions.data = searchParams.toString();
|
|
486
|
+
localVarRequestOptions.headers = {
|
|
487
|
+
...localVarRequestOptions.headers || {},
|
|
488
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
489
|
+
};
|
|
490
|
+
}
|
|
441
491
|
if (timeUnit && localVarRequestOptions.headers) {
|
|
442
492
|
const _timeUnit = validateTimeUnit(timeUnit);
|
|
443
493
|
localVarRequestOptions.headers = {
|
|
@@ -1432,6 +1482,7 @@ var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
|
1432
1482
|
constructor(configuration, connectionPool = []) {
|
|
1433
1483
|
super(configuration, connectionPool);
|
|
1434
1484
|
this.streamConnectionMap = /* @__PURE__ */ new Map();
|
|
1485
|
+
this.streamIdIsStrictlyNumber = false;
|
|
1435
1486
|
this.streamCallbackMap = /* @__PURE__ */ new Map();
|
|
1436
1487
|
this.logger = Logger.getInstance();
|
|
1437
1488
|
this.configuration = configuration;
|
|
@@ -1491,7 +1542,7 @@ var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
|
1491
1542
|
const payload = {
|
|
1492
1543
|
method: "SUBSCRIBE",
|
|
1493
1544
|
params: streams,
|
|
1494
|
-
id:
|
|
1545
|
+
id: normalizeStreamId(id, this.streamIdIsStrictlyNumber)
|
|
1495
1546
|
};
|
|
1496
1547
|
this.logger.debug("SUBSCRIBE", payload);
|
|
1497
1548
|
this.send(JSON.stringify(payload), void 0, false, 0, connection);
|
|
@@ -1598,7 +1649,7 @@ var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
|
1598
1649
|
const payload = {
|
|
1599
1650
|
method: "UNSUBSCRIBE",
|
|
1600
1651
|
params: [stream$1],
|
|
1601
|
-
id:
|
|
1652
|
+
id: normalizeStreamId(id, this.streamIdIsStrictlyNumber)
|
|
1602
1653
|
};
|
|
1603
1654
|
this.logger.debug("UNSUBSCRIBE", payload);
|
|
1604
1655
|
this.send(JSON.stringify(payload), void 0, false, 0, connection);
|
|
@@ -1728,8 +1779,10 @@ exports.getSignature = getSignature;
|
|
|
1728
1779
|
exports.getTimestamp = getTimestamp;
|
|
1729
1780
|
exports.httpRequestFunction = httpRequestFunction;
|
|
1730
1781
|
exports.normalizeScientificNumbers = normalizeScientificNumbers;
|
|
1782
|
+
exports.normalizeStreamId = normalizeStreamId;
|
|
1731
1783
|
exports.parseCustomHeaders = parseCustomHeaders;
|
|
1732
1784
|
exports.parseRateLimitHeaders = parseRateLimitHeaders;
|
|
1785
|
+
exports.randomInteger = randomInteger;
|
|
1733
1786
|
exports.randomString = randomString;
|
|
1734
1787
|
exports.removeEmptyValue = removeEmptyValue;
|
|
1735
1788
|
exports.replaceWebsocketStreamsPlaceholders = replaceWebsocketStreamsPlaceholders;
|