@binance/common 1.1.0 → 1.1.2
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 +35 -12
- package/dist/index.d.ts +35 -12
- package/dist/index.js +86 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -58
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -100,7 +100,7 @@ declare class ConfigurationRestAPI {
|
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
102
|
/**
|
|
103
|
-
* enables keep-alive functionality for the connection
|
|
103
|
+
* enables keep-alive functionality for the connection (if httpsAgent is set then we use httpsAgent.keepAlive instead)
|
|
104
104
|
* @default true
|
|
105
105
|
* @type {boolean}
|
|
106
106
|
* @memberof ConfigurationRestAPI
|
|
@@ -152,12 +152,6 @@ declare class ConfigurationRestAPI {
|
|
|
152
152
|
* @memberof ConfigurationRestAPI
|
|
153
153
|
*/
|
|
154
154
|
timeUnit?: TimeUnit;
|
|
155
|
-
/**
|
|
156
|
-
* base options for axios calls
|
|
157
|
-
* @type {Record<string, unknown>}
|
|
158
|
-
* @memberof ConfigurationRestAPI
|
|
159
|
-
*/
|
|
160
|
-
baseOptions?: Record<string, unknown>;
|
|
161
155
|
constructor(param?: ConfigurationRestAPI);
|
|
162
156
|
}
|
|
163
157
|
declare class ConfigurationWebsocketAPI {
|
|
@@ -485,6 +479,13 @@ interface RequestArgs {
|
|
|
485
479
|
timeUnit?: TimeUnit;
|
|
486
480
|
}
|
|
487
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Resets the signer cache to a new empty WeakMap.
|
|
484
|
+
*
|
|
485
|
+
* This function clears the existing signer cache, creating a fresh WeakMap
|
|
486
|
+
* to store RequestSigner instances associated with configuration objects.
|
|
487
|
+
*/
|
|
488
|
+
declare const clearSignerCache: () => void;
|
|
488
489
|
/**
|
|
489
490
|
* Generates a query string from an object of parameters.
|
|
490
491
|
*
|
|
@@ -520,11 +521,11 @@ declare function delay(ms: number): Promise<void>;
|
|
|
520
521
|
*/
|
|
521
522
|
declare function getTimestamp(): number;
|
|
522
523
|
/**
|
|
523
|
-
* Generates a signature for
|
|
524
|
+
* Generates a signature for the given configuration and query parameters using a cached request signer.
|
|
524
525
|
*
|
|
525
|
-
* @param configuration -
|
|
526
|
-
* @param queryParams - The
|
|
527
|
-
* @returns
|
|
526
|
+
* @param configuration - Configuration object containing API secret, private key, and optional passphrase.
|
|
527
|
+
* @param queryParams - The query parameters to be signed.
|
|
528
|
+
* @returns A string representing the generated signature.
|
|
528
529
|
*/
|
|
529
530
|
declare const getSignature: (configuration: {
|
|
530
531
|
apiSecret?: string;
|
|
@@ -540,6 +541,20 @@ declare const getSignature: (configuration: {
|
|
|
540
541
|
* @throws {RequiredError} If the parameter is null or undefined.
|
|
541
542
|
*/
|
|
542
543
|
declare const assertParamExists: (functionName: string, paramName: string, paramValue: unknown) => void;
|
|
544
|
+
/**
|
|
545
|
+
* Recursively flattens an object or array into URL search parameters.
|
|
546
|
+
*
|
|
547
|
+
* This function handles nested objects and arrays by converting them into dot-notation query parameters.
|
|
548
|
+
* It supports different types of parameters:
|
|
549
|
+
* - Arrays can be stringified or recursively added
|
|
550
|
+
* - Objects are flattened with dot notation keys
|
|
551
|
+
* - Primitive values are converted to strings
|
|
552
|
+
*
|
|
553
|
+
* @param urlSearchParams The URLSearchParams object to modify
|
|
554
|
+
* @param parameter The parameter to flatten (can be an object, array, or primitive)
|
|
555
|
+
* @param key Optional key for nested parameters, used for creating dot-notation keys
|
|
556
|
+
*/
|
|
557
|
+
declare function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: unknown, key?: string): void;
|
|
543
558
|
/**
|
|
544
559
|
* Sets the search parameters of the provided URL by flattening the given objects into the URL's search parameters.
|
|
545
560
|
*
|
|
@@ -613,6 +628,14 @@ declare function sortObject(obj: ObjectType): ObjectType;
|
|
|
613
628
|
* @returns {string} - The resulting string with placeholders replaced by their corresponding values.
|
|
614
629
|
*/
|
|
615
630
|
declare function replaceWebsocketStreamsPlaceholders(str: string, variables: Record<string, unknown>): string;
|
|
631
|
+
/**
|
|
632
|
+
* Generates a standardized user agent string for the application.
|
|
633
|
+
*
|
|
634
|
+
* @param {string} packageName - The name of the package/application.
|
|
635
|
+
* @param {string} packageVersion - The version of the package/application.
|
|
636
|
+
* @returns {string} A formatted user agent string including package details, Node.js version, platform, and architecture.
|
|
637
|
+
*/
|
|
638
|
+
declare function buildUserAgent(packageName: string, packageVersion: string): string;
|
|
616
639
|
|
|
617
640
|
declare class WebsocketEventEmitter {
|
|
618
641
|
private eventEmitter;
|
|
@@ -960,4 +983,4 @@ interface WebsocketStream<T> {
|
|
|
960
983
|
*/
|
|
961
984
|
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
|
|
962
985
|
|
|
963
|
-
export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
|
986
|
+
export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, buildUserAgent, clearSignerCache, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setFlattenedQueryParams, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
package/dist/index.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ declare class ConfigurationRestAPI {
|
|
|
100
100
|
};
|
|
101
101
|
};
|
|
102
102
|
/**
|
|
103
|
-
* enables keep-alive functionality for the connection
|
|
103
|
+
* enables keep-alive functionality for the connection (if httpsAgent is set then we use httpsAgent.keepAlive instead)
|
|
104
104
|
* @default true
|
|
105
105
|
* @type {boolean}
|
|
106
106
|
* @memberof ConfigurationRestAPI
|
|
@@ -152,12 +152,6 @@ declare class ConfigurationRestAPI {
|
|
|
152
152
|
* @memberof ConfigurationRestAPI
|
|
153
153
|
*/
|
|
154
154
|
timeUnit?: TimeUnit;
|
|
155
|
-
/**
|
|
156
|
-
* base options for axios calls
|
|
157
|
-
* @type {Record<string, unknown>}
|
|
158
|
-
* @memberof ConfigurationRestAPI
|
|
159
|
-
*/
|
|
160
|
-
baseOptions?: Record<string, unknown>;
|
|
161
155
|
constructor(param?: ConfigurationRestAPI);
|
|
162
156
|
}
|
|
163
157
|
declare class ConfigurationWebsocketAPI {
|
|
@@ -485,6 +479,13 @@ interface RequestArgs {
|
|
|
485
479
|
timeUnit?: TimeUnit;
|
|
486
480
|
}
|
|
487
481
|
|
|
482
|
+
/**
|
|
483
|
+
* Resets the signer cache to a new empty WeakMap.
|
|
484
|
+
*
|
|
485
|
+
* This function clears the existing signer cache, creating a fresh WeakMap
|
|
486
|
+
* to store RequestSigner instances associated with configuration objects.
|
|
487
|
+
*/
|
|
488
|
+
declare const clearSignerCache: () => void;
|
|
488
489
|
/**
|
|
489
490
|
* Generates a query string from an object of parameters.
|
|
490
491
|
*
|
|
@@ -520,11 +521,11 @@ declare function delay(ms: number): Promise<void>;
|
|
|
520
521
|
*/
|
|
521
522
|
declare function getTimestamp(): number;
|
|
522
523
|
/**
|
|
523
|
-
* Generates a signature for
|
|
524
|
+
* Generates a signature for the given configuration and query parameters using a cached request signer.
|
|
524
525
|
*
|
|
525
|
-
* @param configuration -
|
|
526
|
-
* @param queryParams - The
|
|
527
|
-
* @returns
|
|
526
|
+
* @param configuration - Configuration object containing API secret, private key, and optional passphrase.
|
|
527
|
+
* @param queryParams - The query parameters to be signed.
|
|
528
|
+
* @returns A string representing the generated signature.
|
|
528
529
|
*/
|
|
529
530
|
declare const getSignature: (configuration: {
|
|
530
531
|
apiSecret?: string;
|
|
@@ -540,6 +541,20 @@ declare const getSignature: (configuration: {
|
|
|
540
541
|
* @throws {RequiredError} If the parameter is null or undefined.
|
|
541
542
|
*/
|
|
542
543
|
declare const assertParamExists: (functionName: string, paramName: string, paramValue: unknown) => void;
|
|
544
|
+
/**
|
|
545
|
+
* Recursively flattens an object or array into URL search parameters.
|
|
546
|
+
*
|
|
547
|
+
* This function handles nested objects and arrays by converting them into dot-notation query parameters.
|
|
548
|
+
* It supports different types of parameters:
|
|
549
|
+
* - Arrays can be stringified or recursively added
|
|
550
|
+
* - Objects are flattened with dot notation keys
|
|
551
|
+
* - Primitive values are converted to strings
|
|
552
|
+
*
|
|
553
|
+
* @param urlSearchParams The URLSearchParams object to modify
|
|
554
|
+
* @param parameter The parameter to flatten (can be an object, array, or primitive)
|
|
555
|
+
* @param key Optional key for nested parameters, used for creating dot-notation keys
|
|
556
|
+
*/
|
|
557
|
+
declare function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: unknown, key?: string): void;
|
|
543
558
|
/**
|
|
544
559
|
* Sets the search parameters of the provided URL by flattening the given objects into the URL's search parameters.
|
|
545
560
|
*
|
|
@@ -613,6 +628,14 @@ declare function sortObject(obj: ObjectType): ObjectType;
|
|
|
613
628
|
* @returns {string} - The resulting string with placeholders replaced by their corresponding values.
|
|
614
629
|
*/
|
|
615
630
|
declare function replaceWebsocketStreamsPlaceholders(str: string, variables: Record<string, unknown>): string;
|
|
631
|
+
/**
|
|
632
|
+
* Generates a standardized user agent string for the application.
|
|
633
|
+
*
|
|
634
|
+
* @param {string} packageName - The name of the package/application.
|
|
635
|
+
* @param {string} packageVersion - The version of the package/application.
|
|
636
|
+
* @returns {string} A formatted user agent string including package details, Node.js version, platform, and architecture.
|
|
637
|
+
*/
|
|
638
|
+
declare function buildUserAgent(packageName: string, packageVersion: string): string;
|
|
616
639
|
|
|
617
640
|
declare class WebsocketEventEmitter {
|
|
618
641
|
private eventEmitter;
|
|
@@ -960,4 +983,4 @@ interface WebsocketStream<T> {
|
|
|
960
983
|
*/
|
|
961
984
|
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
|
|
962
985
|
|
|
963
|
-
export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
|
986
|
+
export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, buildUserAgent, clearSignerCache, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setFlattenedQueryParams, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
package/dist/index.js
CHANGED
|
@@ -96,6 +96,8 @@ __export(index_exports, {
|
|
|
96
96
|
WebsocketStreamsBase: () => WebsocketStreamsBase,
|
|
97
97
|
assertParamExists: () => assertParamExists,
|
|
98
98
|
buildQueryString: () => buildQueryString,
|
|
99
|
+
buildUserAgent: () => buildUserAgent,
|
|
100
|
+
clearSignerCache: () => clearSignerCache,
|
|
99
101
|
createStreamHandler: () => createStreamHandler,
|
|
100
102
|
delay: () => delay,
|
|
101
103
|
getSignature: () => getSignature,
|
|
@@ -106,6 +108,7 @@ __export(index_exports, {
|
|
|
106
108
|
removeEmptyValue: () => removeEmptyValue,
|
|
107
109
|
replaceWebsocketStreamsPlaceholders: () => replaceWebsocketStreamsPlaceholders,
|
|
108
110
|
sendRequest: () => sendRequest,
|
|
111
|
+
setFlattenedQueryParams: () => setFlattenedQueryParams,
|
|
109
112
|
setSearchParams: () => setSearchParams,
|
|
110
113
|
shouldRetryRequest: () => shouldRetryRequest,
|
|
111
114
|
sortObject: () => sortObject,
|
|
@@ -364,7 +367,54 @@ var Logger = class _Logger {
|
|
|
364
367
|
var import_crypto = __toESM(require("crypto"));
|
|
365
368
|
var import_fs = __toESM(require("fs"));
|
|
366
369
|
var import_https = __toESM(require("https"));
|
|
370
|
+
var import_os = require("os");
|
|
367
371
|
var import_axios = __toESM(require("axios"));
|
|
372
|
+
var signerCache = /* @__PURE__ */ new WeakMap();
|
|
373
|
+
var RequestSigner = class {
|
|
374
|
+
constructor(configuration) {
|
|
375
|
+
if (configuration.apiSecret && !configuration.privateKey) {
|
|
376
|
+
this.apiSecret = configuration.apiSecret;
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (configuration.privateKey) {
|
|
380
|
+
let privateKey = configuration.privateKey;
|
|
381
|
+
if (typeof privateKey === "string" && import_fs.default.existsSync(privateKey)) {
|
|
382
|
+
privateKey = import_fs.default.readFileSync(privateKey, "utf-8");
|
|
383
|
+
}
|
|
384
|
+
const keyInput = { key: privateKey };
|
|
385
|
+
if (configuration.privateKeyPassphrase && typeof configuration.privateKeyPassphrase === "string") {
|
|
386
|
+
keyInput.passphrase = configuration.privateKeyPassphrase;
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
this.keyObject = import_crypto.default.createPrivateKey(keyInput);
|
|
390
|
+
this.keyType = this.keyObject.asymmetricKeyType;
|
|
391
|
+
} catch {
|
|
392
|
+
throw new Error(
|
|
393
|
+
"Invalid private key. Please provide a valid RSA or ED25519 private key."
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
throw new Error("Either 'apiSecret' or 'privateKey' must be provided for signed requests.");
|
|
399
|
+
}
|
|
400
|
+
sign(queryParams) {
|
|
401
|
+
const params = buildQueryString(queryParams);
|
|
402
|
+
if (this.apiSecret)
|
|
403
|
+
return import_crypto.default.createHmac("sha256", this.apiSecret).update(params).digest("hex");
|
|
404
|
+
if (this.keyObject && this.keyType) {
|
|
405
|
+
const data = Buffer.from(params);
|
|
406
|
+
if (this.keyType === "rsa")
|
|
407
|
+
return import_crypto.default.sign("RSA-SHA256", data, this.keyObject).toString("base64");
|
|
408
|
+
if (this.keyType === "ed25519")
|
|
409
|
+
return import_crypto.default.sign(null, data, this.keyObject).toString("base64");
|
|
410
|
+
throw new Error("Unsupported private key type. Must be RSA or ED25519.");
|
|
411
|
+
}
|
|
412
|
+
throw new Error("Signer is not properly initialized.");
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
var clearSignerCache = function() {
|
|
416
|
+
signerCache = /* @__PURE__ */ new WeakMap();
|
|
417
|
+
};
|
|
368
418
|
function buildQueryString(params) {
|
|
369
419
|
if (!params) return "";
|
|
370
420
|
return Object.entries(params).map(stringifyKeyValuePair).join("&");
|
|
@@ -391,39 +441,12 @@ function getTimestamp() {
|
|
|
391
441
|
return Date.now();
|
|
392
442
|
}
|
|
393
443
|
var getSignature = function(configuration, queryParams) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
} else if (configuration?.privateKey) {
|
|
399
|
-
let privateKey = configuration.privateKey;
|
|
400
|
-
if (typeof privateKey === "string" && import_fs.default.existsSync(privateKey)) {
|
|
401
|
-
privateKey = import_fs.default.readFileSync(privateKey, "utf-8");
|
|
402
|
-
}
|
|
403
|
-
let keyObject;
|
|
404
|
-
try {
|
|
405
|
-
const privateKeyObj = { key: privateKey };
|
|
406
|
-
if (configuration.privateKeyPassphrase && typeof configuration.privateKeyPassphrase === "string") {
|
|
407
|
-
privateKeyObj.passphrase = configuration.privateKeyPassphrase;
|
|
408
|
-
}
|
|
409
|
-
keyObject = import_crypto.default.createPrivateKey(privateKeyObj);
|
|
410
|
-
} catch {
|
|
411
|
-
throw new Error(
|
|
412
|
-
"Invalid private key. Please provide a valid RSA or ED25519 private key."
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
const keyType = keyObject.asymmetricKeyType;
|
|
416
|
-
if (keyType === "rsa") {
|
|
417
|
-
signature = import_crypto.default.sign("RSA-SHA256", Buffer.from(params), keyObject).toString("base64");
|
|
418
|
-
} else if (keyType === "ed25519") {
|
|
419
|
-
signature = import_crypto.default.sign(null, Buffer.from(params), keyObject).toString("base64");
|
|
420
|
-
} else {
|
|
421
|
-
throw new Error("Unsupported private key type. Must be RSA or ED25519.");
|
|
422
|
-
}
|
|
423
|
-
} else {
|
|
424
|
-
throw new Error("Either 'apiSecret' or 'privateKey' must be provided for signed requests.");
|
|
444
|
+
let signer = signerCache.get(configuration);
|
|
445
|
+
if (!signer) {
|
|
446
|
+
signer = new RequestSigner(configuration);
|
|
447
|
+
signerCache.set(configuration, signer);
|
|
425
448
|
}
|
|
426
|
-
return
|
|
449
|
+
return signer.sign(queryParams);
|
|
427
450
|
};
|
|
428
451
|
var assertParamExists = function(functionName, paramName, paramValue) {
|
|
429
452
|
if (paramValue === null || paramValue === void 0) {
|
|
@@ -435,25 +458,26 @@ var assertParamExists = function(functionName, paramName, paramValue) {
|
|
|
435
458
|
};
|
|
436
459
|
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
|
|
437
460
|
if (parameter == null) return;
|
|
461
|
+
if (Array.isArray(parameter)) {
|
|
462
|
+
if (key)
|
|
463
|
+
urlSearchParams.set(key, JSON.stringify(parameter));
|
|
464
|
+
else
|
|
465
|
+
for (const item of parameter) {
|
|
466
|
+
setFlattenedQueryParams(urlSearchParams, item, "");
|
|
467
|
+
}
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
438
470
|
if (typeof parameter === "object") {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
(currentKey) => setFlattenedQueryParams(
|
|
444
|
-
urlSearchParams,
|
|
445
|
-
parameter[currentKey],
|
|
446
|
-
`${key}${key !== "" ? "." : ""}${currentKey}`
|
|
447
|
-
)
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
} else {
|
|
451
|
-
if (urlSearchParams.has(key)) {
|
|
452
|
-
urlSearchParams.append(key, String(parameter));
|
|
453
|
-
} else {
|
|
454
|
-
urlSearchParams.set(key, String(parameter));
|
|
471
|
+
for (const subKey of Object.keys(parameter)) {
|
|
472
|
+
const subVal = parameter[subKey];
|
|
473
|
+
const newKey = key ? `${key}.${subKey}` : subKey;
|
|
474
|
+
setFlattenedQueryParams(urlSearchParams, subVal, newKey);
|
|
455
475
|
}
|
|
476
|
+
return;
|
|
456
477
|
}
|
|
478
|
+
const str = String(parameter);
|
|
479
|
+
if (urlSearchParams.has(key)) urlSearchParams.append(key, str);
|
|
480
|
+
else urlSearchParams.set(key, str);
|
|
457
481
|
}
|
|
458
482
|
var setSearchParams = function(url, ...objects) {
|
|
459
483
|
const searchParams = new URLSearchParams(url.search);
|
|
@@ -475,18 +499,13 @@ var httpRequestFunction = async function(axiosArgs, configuration) {
|
|
|
475
499
|
...axiosArgs.options,
|
|
476
500
|
url: (import_axios.default.defaults?.baseURL ? "" : configuration?.basePath ?? "") + axiosArgs.url
|
|
477
501
|
};
|
|
478
|
-
if (configuration?.keepAlive)
|
|
479
|
-
axiosRequestArgs.httpsAgent = new import_https.default.Agent({
|
|
480
|
-
|
|
481
|
-
keepAlive: true
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
if (configuration?.compression) {
|
|
502
|
+
if (configuration?.keepAlive && !configuration?.baseOptions?.httpsAgent)
|
|
503
|
+
axiosRequestArgs.httpsAgent = new import_https.default.Agent({ keepAlive: true });
|
|
504
|
+
if (configuration?.compression)
|
|
485
505
|
axiosRequestArgs.headers = {
|
|
486
506
|
...axiosRequestArgs.headers,
|
|
487
507
|
"Accept-Encoding": "gzip, deflate, br"
|
|
488
508
|
};
|
|
489
|
-
}
|
|
490
509
|
const retries = configuration?.retries ?? 0;
|
|
491
510
|
const backoff = configuration?.backoff ?? 0;
|
|
492
511
|
let attempt = 0;
|
|
@@ -694,6 +713,9 @@ function replaceWebsocketStreamsPlaceholders(str, variables) {
|
|
|
694
713
|
return "";
|
|
695
714
|
});
|
|
696
715
|
}
|
|
716
|
+
function buildUserAgent(packageName, packageVersion) {
|
|
717
|
+
return `${packageName}/${packageVersion} (Node.js/${process.version}; ${(0, import_os.platform)()}; ${(0, import_os.arch)()})`;
|
|
718
|
+
}
|
|
697
719
|
|
|
698
720
|
// src/websocket.ts
|
|
699
721
|
var import_events = require("events");
|
|
@@ -962,10 +984,13 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
|
|
|
962
984
|
* @returns A new WebSocket client instance.
|
|
963
985
|
*/
|
|
964
986
|
createWebSocket(url) {
|
|
965
|
-
|
|
987
|
+
const wsClientOptions = {
|
|
966
988
|
perMessageDeflate: this.configuration?.compression,
|
|
967
989
|
agent: this.configuration?.agent
|
|
968
|
-
}
|
|
990
|
+
};
|
|
991
|
+
if (this.configuration.userAgent)
|
|
992
|
+
wsClientOptions.headers = { "User-Agent": this.configuration.userAgent };
|
|
993
|
+
return new import_ws.default(url, wsClientOptions);
|
|
969
994
|
}
|
|
970
995
|
/**
|
|
971
996
|
* Initializes a WebSocket connection.
|
|
@@ -1565,6 +1590,8 @@ function createStreamHandler(websocketBase, streamOrId, id) {
|
|
|
1565
1590
|
WebsocketStreamsBase,
|
|
1566
1591
|
assertParamExists,
|
|
1567
1592
|
buildQueryString,
|
|
1593
|
+
buildUserAgent,
|
|
1594
|
+
clearSignerCache,
|
|
1568
1595
|
createStreamHandler,
|
|
1569
1596
|
delay,
|
|
1570
1597
|
getSignature,
|
|
@@ -1575,6 +1602,7 @@ function createStreamHandler(websocketBase, streamOrId, id) {
|
|
|
1575
1602
|
removeEmptyValue,
|
|
1576
1603
|
replaceWebsocketStreamsPlaceholders,
|
|
1577
1604
|
sendRequest,
|
|
1605
|
+
setFlattenedQueryParams,
|
|
1578
1606
|
setSearchParams,
|
|
1579
1607
|
shouldRetryRequest,
|
|
1580
1608
|
sortObject,
|