@binance/common 1.0.3 → 1.0.4
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 +23 -21
- package/dist/index.d.ts +23 -21
- package/dist/index.js +27 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -614,15 +614,6 @@ declare function sortObject(obj: ObjectType): ObjectType;
|
|
|
614
614
|
* @returns {string} - The resulting string with placeholders replaced by their corresponding values.
|
|
615
615
|
*/
|
|
616
616
|
declare function replaceWebsocketStreamsPlaceholders(str: string, variables: Record<string, unknown>): string;
|
|
617
|
-
/**
|
|
618
|
-
* Creates a WebsocketStream instance that subscribes to the specified stream and provides a callback for handling incoming messages.
|
|
619
|
-
*
|
|
620
|
-
* @param websocketBase - The WebsocketStreamsBase instance to use for subscribing and unsubscribing from the stream.
|
|
621
|
-
* @param stream - The name of the stream to subscribe to.
|
|
622
|
-
* @param id - An optional identifier for the stream.
|
|
623
|
-
* @returns A WebsocketStream instance that can be used to handle incoming messages and unsubscribe from the stream.
|
|
624
|
-
*/
|
|
625
|
-
declare function createStreamHandler<T>(websocketBase: WebsocketStreamsBase, stream: string, id?: string): WebsocketStream<T>;
|
|
626
617
|
|
|
627
618
|
declare class WebsocketEventEmitter {
|
|
628
619
|
private eventEmitter;
|
|
@@ -819,6 +810,7 @@ interface WebsocketSendMsgOptions {
|
|
|
819
810
|
}
|
|
820
811
|
declare class WebsocketAPIBase extends WebsocketCommon {
|
|
821
812
|
private isConnecting;
|
|
813
|
+
streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
|
|
822
814
|
configuration: ConfigurationWebsocketAPI;
|
|
823
815
|
logger: Logger;
|
|
824
816
|
constructor(configuration: ConfigurationWebsocketAPI, connectionPool?: WebsocketConnection[]);
|
|
@@ -853,18 +845,6 @@ declare class WebsocketAPIBase extends WebsocketCommon {
|
|
|
853
845
|
isSigned?: boolean;
|
|
854
846
|
}): Promise<WebsocketApiResponse<T>>;
|
|
855
847
|
}
|
|
856
|
-
interface WebsocketStream<T> {
|
|
857
|
-
/**
|
|
858
|
-
* Attach a listener for the stream.
|
|
859
|
-
* @param event - Event name (currently supports "message").
|
|
860
|
-
* @param callback - Callback function to handle incoming data.
|
|
861
|
-
*/
|
|
862
|
-
on(event: 'message', callback: (data: T) => void): void;
|
|
863
|
-
/**
|
|
864
|
-
* Unsubscribe from the stream and clean up resources.
|
|
865
|
-
*/
|
|
866
|
-
unsubscribe(): void;
|
|
867
|
-
}
|
|
868
848
|
declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
869
849
|
private streamConnectionMap;
|
|
870
850
|
protected configuration: ConfigurationWebsocketStreams;
|
|
@@ -958,5 +938,27 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
958
938
|
*/
|
|
959
939
|
isSubscribed(stream: string): boolean;
|
|
960
940
|
}
|
|
941
|
+
interface WebsocketStream<T> {
|
|
942
|
+
/**
|
|
943
|
+
* Attach a listener for the stream.
|
|
944
|
+
* @param event - Event name (currently supports "message").
|
|
945
|
+
* @param callback - Callback function to handle incoming data.
|
|
946
|
+
*/
|
|
947
|
+
on(event: 'message', callback: (data: T) => void): void;
|
|
948
|
+
/**
|
|
949
|
+
* Unsubscribe from the stream and clean up resources.
|
|
950
|
+
*/
|
|
951
|
+
unsubscribe(): void;
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Creates a WebSocket stream handler for managing stream subscriptions and callbacks.
|
|
955
|
+
*
|
|
956
|
+
* @template T The type of data expected in the stream messages
|
|
957
|
+
* @param {WebsocketAPIBase | WebsocketStreamsBase} websocketBase The WebSocket base instance
|
|
958
|
+
* @param {string} streamOrId The stream identifier
|
|
959
|
+
* @param {string} [id] Optional additional identifier
|
|
960
|
+
* @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
|
|
961
|
+
*/
|
|
962
|
+
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
|
|
961
963
|
|
|
962
964
|
export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
package/dist/index.d.ts
CHANGED
|
@@ -614,15 +614,6 @@ declare function sortObject(obj: ObjectType): ObjectType;
|
|
|
614
614
|
* @returns {string} - The resulting string with placeholders replaced by their corresponding values.
|
|
615
615
|
*/
|
|
616
616
|
declare function replaceWebsocketStreamsPlaceholders(str: string, variables: Record<string, unknown>): string;
|
|
617
|
-
/**
|
|
618
|
-
* Creates a WebsocketStream instance that subscribes to the specified stream and provides a callback for handling incoming messages.
|
|
619
|
-
*
|
|
620
|
-
* @param websocketBase - The WebsocketStreamsBase instance to use for subscribing and unsubscribing from the stream.
|
|
621
|
-
* @param stream - The name of the stream to subscribe to.
|
|
622
|
-
* @param id - An optional identifier for the stream.
|
|
623
|
-
* @returns A WebsocketStream instance that can be used to handle incoming messages and unsubscribe from the stream.
|
|
624
|
-
*/
|
|
625
|
-
declare function createStreamHandler<T>(websocketBase: WebsocketStreamsBase, stream: string, id?: string): WebsocketStream<T>;
|
|
626
617
|
|
|
627
618
|
declare class WebsocketEventEmitter {
|
|
628
619
|
private eventEmitter;
|
|
@@ -819,6 +810,7 @@ interface WebsocketSendMsgOptions {
|
|
|
819
810
|
}
|
|
820
811
|
declare class WebsocketAPIBase extends WebsocketCommon {
|
|
821
812
|
private isConnecting;
|
|
813
|
+
streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
|
|
822
814
|
configuration: ConfigurationWebsocketAPI;
|
|
823
815
|
logger: Logger;
|
|
824
816
|
constructor(configuration: ConfigurationWebsocketAPI, connectionPool?: WebsocketConnection[]);
|
|
@@ -853,18 +845,6 @@ declare class WebsocketAPIBase extends WebsocketCommon {
|
|
|
853
845
|
isSigned?: boolean;
|
|
854
846
|
}): Promise<WebsocketApiResponse<T>>;
|
|
855
847
|
}
|
|
856
|
-
interface WebsocketStream<T> {
|
|
857
|
-
/**
|
|
858
|
-
* Attach a listener for the stream.
|
|
859
|
-
* @param event - Event name (currently supports "message").
|
|
860
|
-
* @param callback - Callback function to handle incoming data.
|
|
861
|
-
*/
|
|
862
|
-
on(event: 'message', callback: (data: T) => void): void;
|
|
863
|
-
/**
|
|
864
|
-
* Unsubscribe from the stream and clean up resources.
|
|
865
|
-
*/
|
|
866
|
-
unsubscribe(): void;
|
|
867
|
-
}
|
|
868
848
|
declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
869
849
|
private streamConnectionMap;
|
|
870
850
|
protected configuration: ConfigurationWebsocketStreams;
|
|
@@ -958,5 +938,27 @@ declare class WebsocketStreamsBase extends WebsocketCommon {
|
|
|
958
938
|
*/
|
|
959
939
|
isSubscribed(stream: string): boolean;
|
|
960
940
|
}
|
|
941
|
+
interface WebsocketStream<T> {
|
|
942
|
+
/**
|
|
943
|
+
* Attach a listener for the stream.
|
|
944
|
+
* @param event - Event name (currently supports "message").
|
|
945
|
+
* @param callback - Callback function to handle incoming data.
|
|
946
|
+
*/
|
|
947
|
+
on(event: 'message', callback: (data: T) => void): void;
|
|
948
|
+
/**
|
|
949
|
+
* Unsubscribe from the stream and clean up resources.
|
|
950
|
+
*/
|
|
951
|
+
unsubscribe(): void;
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Creates a WebSocket stream handler for managing stream subscriptions and callbacks.
|
|
955
|
+
*
|
|
956
|
+
* @template T The type of data expected in the stream messages
|
|
957
|
+
* @param {WebsocketAPIBase | WebsocketStreamsBase} websocketBase The WebSocket base instance
|
|
958
|
+
* @param {string} streamOrId The stream identifier
|
|
959
|
+
* @param {string} [id] Optional additional identifier
|
|
960
|
+
* @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
|
|
961
|
+
*/
|
|
962
|
+
declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
|
|
961
963
|
|
|
962
964
|
export { ALGO_REST_API_PROD_URL, AUTO_INVEST_REST_API_PROD_URL, type AxiosRequestArgs, BadRequestError, C2C_REST_API_PROD_URL, CONVERT_REST_API_PROD_URL, COPY_TRADING_REST_API_PROD_URL, CRYPTO_LOAN_REST_API_PROD_URL, ConfigurationRestAPI, ConfigurationWebsocketAPI, ConfigurationWebsocketStreams, ConnectorClientError, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_COIN_FUTURES_WS_STREAMS_TESTNET_URL, DERIVATIVES_TRADING_OPTIONS_REST_API_PROD_URL, DERIVATIVES_TRADING_OPTIONS_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_PRO_REST_API_TESTNET_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL, DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_REST_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_API_TESTNET_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_TESTNET_URL, DUAL_INVESTMENT_REST_API_PROD_URL, FIAT_REST_API_PROD_URL, ForbiddenError, GIFT_CARD_REST_API_PROD_URL, LogLevel, Logger, MARGIN_TRADING_REST_API_PROD_URL, MINING_REST_API_PROD_URL, NFT_REST_API_PROD_URL, NetworkError, NotFoundError, type ObjectType, PAY_REST_API_PROD_URL, REBATE_REST_API_PROD_URL, RateLimitBanError, type RequestArgs, RequiredError, type RestApiRateLimit, type RestApiResponse, SIMPLE_EARN_REST_API_PROD_URL, SPOT_REST_API_MARKET_URL, SPOT_REST_API_PROD_URL, SPOT_REST_API_TESTNET_URL, SPOT_WS_API_PROD_URL, SPOT_WS_API_TESTNET_URL, SPOT_WS_STREAMS_MARKET_URL, SPOT_WS_STREAMS_PROD_URL, SPOT_WS_STREAMS_TESTNET_URL, STAKING_REST_API_PROD_URL, SUB_ACCOUNT_REST_API_PROD_URL, type SendMessageOptions, ServerError, TimeUnit, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgOptions, type WebsocketStream, WebsocketStreamsBase, assertParamExists, buildQueryString, createStreamHandler, delay, getSignature, getTimestamp, httpRequestFunction, parseRateLimitHeaders, randomString, removeEmptyValue, replaceWebsocketStreamsPlaceholders, sendRequest, setSearchParams, shouldRetryRequest, sortObject, toPathString, validateTimeUnit };
|
package/dist/index.js
CHANGED
|
@@ -94,7 +94,7 @@ __export(index_exports, {
|
|
|
94
94
|
WebsocketAPIBase: () => WebsocketAPIBase,
|
|
95
95
|
WebsocketCommon: () => WebsocketCommon,
|
|
96
96
|
WebsocketEventEmitter: () => WebsocketEventEmitter,
|
|
97
|
-
WebsocketStreamsBase: () =>
|
|
97
|
+
WebsocketStreamsBase: () => WebsocketStreamsBase,
|
|
98
98
|
assertParamExists: () => assertParamExists,
|
|
99
99
|
buildQueryString: () => buildQueryString,
|
|
100
100
|
createStreamHandler: () => createStreamHandler,
|
|
@@ -686,25 +686,6 @@ function replaceWebsocketStreamsPlaceholders(str, variables) {
|
|
|
686
686
|
return "";
|
|
687
687
|
});
|
|
688
688
|
}
|
|
689
|
-
function createStreamHandler(websocketBase, stream, id) {
|
|
690
|
-
websocketBase.subscribe(stream, id);
|
|
691
|
-
let registeredCallback;
|
|
692
|
-
return {
|
|
693
|
-
on: (event, callback) => {
|
|
694
|
-
if (event === "message") {
|
|
695
|
-
registeredCallback = (data) => callback(data);
|
|
696
|
-
const callbackSet = websocketBase.streamCallbackMap.get(stream) ?? /* @__PURE__ */ new Set();
|
|
697
|
-
callbackSet.add(registeredCallback);
|
|
698
|
-
websocketBase.streamCallbackMap.set(stream, callbackSet);
|
|
699
|
-
}
|
|
700
|
-
},
|
|
701
|
-
unsubscribe: () => {
|
|
702
|
-
if (registeredCallback)
|
|
703
|
-
websocketBase.streamCallbackMap.get(stream)?.delete(registeredCallback);
|
|
704
|
-
websocketBase.unsubscribe(stream, id);
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
689
|
|
|
709
690
|
// src/websocket.ts
|
|
710
691
|
var import_events = require("events");
|
|
@@ -1164,6 +1145,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1164
1145
|
constructor(configuration, connectionPool = []) {
|
|
1165
1146
|
super(configuration, connectionPool);
|
|
1166
1147
|
this.isConnecting = false;
|
|
1148
|
+
this.streamCallbackMap = /* @__PURE__ */ new Map();
|
|
1167
1149
|
this.logger = Logger.getInstance();
|
|
1168
1150
|
this.configuration = configuration;
|
|
1169
1151
|
}
|
|
@@ -1204,6 +1186,10 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1204
1186
|
};
|
|
1205
1187
|
request?.resolve(response);
|
|
1206
1188
|
}
|
|
1189
|
+
} else if ("event" in message && "e" in message["event"] && this.streamCallbackMap.size > 0) {
|
|
1190
|
+
this.streamCallbackMap.forEach(
|
|
1191
|
+
(callbacks) => callbacks.forEach((callback) => callback(message["event"]))
|
|
1192
|
+
);
|
|
1207
1193
|
} else {
|
|
1208
1194
|
this.logger.warn("Received response for unknown or timed-out request:", message);
|
|
1209
1195
|
}
|
|
@@ -1273,7 +1259,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
|
|
|
1273
1259
|
return this.send(JSON.stringify(data), id, true, this.configuration?.timeout);
|
|
1274
1260
|
}
|
|
1275
1261
|
};
|
|
1276
|
-
var
|
|
1262
|
+
var WebsocketStreamsBase = class extends WebsocketCommon {
|
|
1277
1263
|
constructor(configuration, connectionPool = []) {
|
|
1278
1264
|
super(configuration, connectionPool);
|
|
1279
1265
|
this.streamConnectionMap = /* @__PURE__ */ new Map();
|
|
@@ -1479,6 +1465,26 @@ var WebsocketStreamsBase2 = class extends WebsocketCommon {
|
|
|
1479
1465
|
return this.streamConnectionMap.has(stream);
|
|
1480
1466
|
}
|
|
1481
1467
|
};
|
|
1468
|
+
function createStreamHandler(websocketBase, streamOrId, id) {
|
|
1469
|
+
if (websocketBase instanceof WebsocketStreamsBase) websocketBase.subscribe(streamOrId, id);
|
|
1470
|
+
let registeredCallback;
|
|
1471
|
+
return {
|
|
1472
|
+
on: (event, callback) => {
|
|
1473
|
+
if (event === "message") {
|
|
1474
|
+
registeredCallback = (data) => callback(data);
|
|
1475
|
+
const callbackSet = websocketBase.streamCallbackMap.get(streamOrId) ?? /* @__PURE__ */ new Set();
|
|
1476
|
+
callbackSet.add(registeredCallback);
|
|
1477
|
+
websocketBase.streamCallbackMap.set(streamOrId, callbackSet);
|
|
1478
|
+
}
|
|
1479
|
+
},
|
|
1480
|
+
unsubscribe: () => {
|
|
1481
|
+
if (registeredCallback)
|
|
1482
|
+
websocketBase.streamCallbackMap.get(streamOrId)?.delete(registeredCallback);
|
|
1483
|
+
if (websocketBase instanceof WebsocketStreamsBase)
|
|
1484
|
+
websocketBase.unsubscribe(streamOrId, id);
|
|
1485
|
+
}
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1482
1488
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1483
1489
|
0 && (module.exports = {
|
|
1484
1490
|
ALGO_REST_API_PROD_URL,
|