@binance/common 1.2.6 → 2.0.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.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { Agent } from 'https';
2
- import { RawAxiosRequestConfig, AxiosError, RawAxiosResponseHeaders, AxiosResponseHeaders } from 'axios';
3
- import WebSocketClient from 'ws';
1
+ import { Agent } from "https";
2
+ import { AxiosError, AxiosResponseHeaders, RawAxiosRequestConfig, RawAxiosResponseHeaders } from "axios";
3
+ import WebSocketClient from "ws";
4
4
 
5
+ //#region src/constants.d.ts
5
6
  declare const TimeUnit: {
6
- readonly MILLISECOND: "MILLISECOND";
7
- readonly millisecond: "millisecond";
8
- readonly MICROSECOND: "MICROSECOND";
9
- readonly microsecond: "microsecond";
7
+ readonly MILLISECOND: "MILLISECOND";
8
+ readonly millisecond: "millisecond";
9
+ readonly MICROSECOND: "MICROSECOND";
10
+ readonly microsecond: "microsecond";
10
11
  };
11
12
  type TimeUnit = (typeof TimeUnit)[keyof typeof TimeUnit];
12
13
  declare const ALGO_REST_API_PROD_URL = "https://api.binance.com";
@@ -57,257 +58,259 @@ declare const STAKING_REST_API_PROD_URL = "https://api.binance.com";
57
58
  declare const SUB_ACCOUNT_REST_API_PROD_URL = "https://api.binance.com";
58
59
  declare const VIP_LOAN_REST_API_PROD_URL = "https://api.binance.com";
59
60
  declare const WALLET_REST_API_PROD_URL = "https://api.binance.com";
60
-
61
+ //#endregion
62
+ //#region src/configuration.d.ts
61
63
  declare class ConfigurationRestAPI {
62
- /**
63
- * The API key used for authentication.
64
- * @memberof ConfigurationRestAPI
65
- */
66
- apiKey: string;
67
- /**
68
- * The API secret used for authentication.
69
- * @memberof ConfigurationRestAPI
70
- */
71
- apiSecret?: string;
72
- /**
73
- * override base path
74
- * @type {string}
75
- * @memberof ConfigurationRestAPI
76
- */
77
- basePath?: string;
78
- /**
79
- * set a timeout (in milliseconds) for the request
80
- * @default 1000
81
- * @type {number}
82
- * @memberof ConfigurationRestAPI
83
- */
84
- timeout?: number;
85
- /**
86
- * HTTP/HTTPS proxy configuration
87
- * @default false
88
- * @type {object}
89
- * @property {string} host - Proxy server hostname
90
- * @property {number} port - Proxy server port number
91
- * @property {string} protocol - Proxy server protocol
92
- * @property {object} [auth] - Proxy authentication credentials
93
- * @property {string} auth.username - Proxy authentication username
94
- * @property {string} auth.password - Proxy authentication password
95
- * @memberof ConfigurationRestAPI
96
- */
97
- proxy?: {
98
- host: string;
99
- port: number;
100
- protocol?: string;
101
- auth?: {
102
- username: string;
103
- password: string;
104
- };
64
+ /**
65
+ * The API key used for authentication.
66
+ * @memberof ConfigurationRestAPI
67
+ */
68
+ apiKey: string;
69
+ /**
70
+ * The API secret used for authentication.
71
+ * @memberof ConfigurationRestAPI
72
+ */
73
+ apiSecret?: string;
74
+ /**
75
+ * override base path
76
+ * @type {string}
77
+ * @memberof ConfigurationRestAPI
78
+ */
79
+ basePath?: string;
80
+ /**
81
+ * set a timeout (in milliseconds) for the request
82
+ * @default 1000
83
+ * @type {number}
84
+ * @memberof ConfigurationRestAPI
85
+ */
86
+ timeout?: number;
87
+ /**
88
+ * HTTP/HTTPS proxy configuration
89
+ * @default false
90
+ * @type {object}
91
+ * @property {string} host - Proxy server hostname
92
+ * @property {number} port - Proxy server port number
93
+ * @property {string} protocol - Proxy server protocol
94
+ * @property {object} [auth] - Proxy authentication credentials
95
+ * @property {string} auth.username - Proxy authentication username
96
+ * @property {string} auth.password - Proxy authentication password
97
+ * @memberof ConfigurationRestAPI
98
+ */
99
+ proxy?: {
100
+ host: string;
101
+ port: number;
102
+ protocol?: string;
103
+ auth?: {
104
+ username: string;
105
+ password: string;
105
106
  };
106
- /**
107
- * Optional custom headers to be sent with the request
108
- * @default {}
109
- * @type {Record<string, string | string[]>}
110
- * @memberof ConfigurationRestAPI
111
- */
112
- customHeaders?: Record<string, string | string[]>;
113
- /**
114
- * enables keep-alive functionality for the connection (if httpsAgent is set then we use httpsAgent.keepAlive instead)
115
- * @default true
116
- * @type {boolean}
117
- * @memberof ConfigurationRestAPI
118
- */
119
- keepAlive?: boolean;
120
- /**
121
- * enables response compression
122
- * @default true
123
- * @type {boolean}
124
- * @memberof ConfigurationRestAPI
125
- */
126
- compression?: boolean;
127
- /**
128
- * number of retry attempts for failed requests
129
- * @default 3
130
- * @type {number}
131
- * @memberof ConfigurationRestAPI
132
- */
133
- retries?: number;
134
- /**
135
- * delay between retry attempts in milliseconds
136
- * @default 1000
137
- * @type {number}
138
- * @memberof ConfigurationRestAPI
139
- */
140
- backoff?: number;
141
- /**
142
- * https agent
143
- * @default false
144
- * @type {boolean | Agent}
145
- * @memberof ConfigurationRestAPI
146
- */
147
- httpsAgent?: boolean | Agent;
148
- /**
149
- * private key
150
- * @type {string | Buffer}
151
- * @memberof ConfigurationRestAPI
152
- */
153
- privateKey?: string | Buffer;
154
- /**
155
- * private key passphrase
156
- * @type {string}
157
- * @memberof ConfigurationRestAPI
158
- */
159
- privateKeyPassphrase?: string;
160
- /**
161
- * timeUnit (used only on SPOT API)
162
- * @type {TimeUnit}
163
- * @memberof ConfigurationRestAPI
164
- */
165
- timeUnit?: TimeUnit;
166
- constructor(param?: ConfigurationRestAPI);
107
+ };
108
+ /**
109
+ * Optional custom headers to be sent with the request
110
+ * @default {}
111
+ * @type {Record<string, string | string[]>}
112
+ * @memberof ConfigurationRestAPI
113
+ */
114
+ customHeaders?: Record<string, string | string[]>;
115
+ /**
116
+ * enables keep-alive functionality for the connection (if httpsAgent is set then we use httpsAgent.keepAlive instead)
117
+ * @default true
118
+ * @type {boolean}
119
+ * @memberof ConfigurationRestAPI
120
+ */
121
+ keepAlive?: boolean;
122
+ /**
123
+ * enables response compression
124
+ * @default true
125
+ * @type {boolean}
126
+ * @memberof ConfigurationRestAPI
127
+ */
128
+ compression?: boolean;
129
+ /**
130
+ * number of retry attempts for failed requests
131
+ * @default 3
132
+ * @type {number}
133
+ * @memberof ConfigurationRestAPI
134
+ */
135
+ retries?: number;
136
+ /**
137
+ * delay between retry attempts in milliseconds
138
+ * @default 1000
139
+ * @type {number}
140
+ * @memberof ConfigurationRestAPI
141
+ */
142
+ backoff?: number;
143
+ /**
144
+ * https agent
145
+ * @default false
146
+ * @type {boolean | Agent}
147
+ * @memberof ConfigurationRestAPI
148
+ */
149
+ httpsAgent?: boolean | Agent;
150
+ /**
151
+ * private key
152
+ * @type {string | Buffer}
153
+ * @memberof ConfigurationRestAPI
154
+ */
155
+ privateKey?: string | Buffer;
156
+ /**
157
+ * private key passphrase
158
+ * @type {string}
159
+ * @memberof ConfigurationRestAPI
160
+ */
161
+ privateKeyPassphrase?: string;
162
+ /**
163
+ * timeUnit (used only on SPOT API)
164
+ * @type {TimeUnit}
165
+ * @memberof ConfigurationRestAPI
166
+ */
167
+ timeUnit?: TimeUnit;
168
+ constructor(param?: ConfigurationRestAPI);
167
169
  }
168
170
  declare class ConfigurationWebsocketAPI {
169
- /**
170
- * The API key used for authentication.
171
- * @memberof ConfigurationWebsocketAPI
172
- */
173
- apiKey: string;
174
- /**
175
- * The API secret used for authentication.
176
- * @memberof ConfigurationWebsocketAPI
177
- */
178
- apiSecret?: string;
179
- /**
180
- * override websocket url
181
- * @type {string}
182
- * @memberof ConfigurationWebsocketAPI
183
- */
184
- wsURL?: string;
185
- /**
186
- * set a timeout (in milliseconds) for the request
187
- * @default 5000
188
- * @type {number}
189
- * @memberof ConfigurationWebsocketAPI
190
- */
191
- timeout?: number;
192
- /**
193
- * reconnction delay
194
- * @default 5000
195
- * @type {number}
196
- * @memberof ConfigurationWebsocketAPI
197
- */
198
- reconnectDelay?: number;
199
- /**
200
- * use compression for websocket messages
201
- * @default true
202
- * @type {boolean}
203
- * @memberof ConfigurationWebsocketAPI
204
- */
205
- compression?: boolean;
206
- /**
207
- * websocket agent
208
- * @default false
209
- * @type {boolean | Agent}
210
- * @memberof ConfigurationWebsocketAPI
211
- */
212
- agent?: boolean | Agent;
213
- /**
214
- * the mode of the connection, either 'single' or 'pool'.
215
- * @default 'single'
216
- * @type {'single' | 'pool'}
217
- * @memberof ConfigurationWebsocketAPI
218
- */
219
- mode?: 'single' | 'pool';
220
- /**
221
- * the size of the connection pool, if the mode is set to 'pool'.
222
- * @default 1
223
- * @type {number}
224
- * @memberof ConfigurationWebsocketAPI
225
- */
226
- poolSize?: number;
227
- /**
228
- * private key
229
- * @type {string | Buffer}
230
- * @memberof ConfigurationWebsocketAPI
231
- */
232
- privateKey?: string | Buffer;
233
- /**
234
- * private key passphrase
235
- * @type {string}
236
- * @memberof ConfigurationWebsocketAPI
237
- */
238
- privateKeyPassphrase?: string;
239
- /**
240
- * timeUnit (used only on SPOT API)
241
- * @type {TimeUnit}
242
- * @memberof ConfigurationWebsocketAPI
243
- */
244
- timeUnit?: TimeUnit;
245
- /**
246
- * auto session re-logon on reconnects/renewals
247
- * @default true
248
- * @type {boolean}
249
- * @memberof ConfigurationWebsocketAPI
250
- */
251
- autoSessionReLogon?: boolean;
252
- constructor(param?: ConfigurationWebsocketAPI);
171
+ /**
172
+ * The API key used for authentication.
173
+ * @memberof ConfigurationWebsocketAPI
174
+ */
175
+ apiKey: string;
176
+ /**
177
+ * The API secret used for authentication.
178
+ * @memberof ConfigurationWebsocketAPI
179
+ */
180
+ apiSecret?: string;
181
+ /**
182
+ * override websocket url
183
+ * @type {string}
184
+ * @memberof ConfigurationWebsocketAPI
185
+ */
186
+ wsURL?: string;
187
+ /**
188
+ * set a timeout (in milliseconds) for the request
189
+ * @default 5000
190
+ * @type {number}
191
+ * @memberof ConfigurationWebsocketAPI
192
+ */
193
+ timeout?: number;
194
+ /**
195
+ * reconnction delay
196
+ * @default 5000
197
+ * @type {number}
198
+ * @memberof ConfigurationWebsocketAPI
199
+ */
200
+ reconnectDelay?: number;
201
+ /**
202
+ * use compression for websocket messages
203
+ * @default true
204
+ * @type {boolean}
205
+ * @memberof ConfigurationWebsocketAPI
206
+ */
207
+ compression?: boolean;
208
+ /**
209
+ * websocket agent
210
+ * @default false
211
+ * @type {boolean | Agent}
212
+ * @memberof ConfigurationWebsocketAPI
213
+ */
214
+ agent?: boolean | Agent;
215
+ /**
216
+ * the mode of the connection, either 'single' or 'pool'.
217
+ * @default 'single'
218
+ * @type {'single' | 'pool'}
219
+ * @memberof ConfigurationWebsocketAPI
220
+ */
221
+ mode?: 'single' | 'pool';
222
+ /**
223
+ * the size of the connection pool, if the mode is set to 'pool'.
224
+ * @default 1
225
+ * @type {number}
226
+ * @memberof ConfigurationWebsocketAPI
227
+ */
228
+ poolSize?: number;
229
+ /**
230
+ * private key
231
+ * @type {string | Buffer}
232
+ * @memberof ConfigurationWebsocketAPI
233
+ */
234
+ privateKey?: string | Buffer;
235
+ /**
236
+ * private key passphrase
237
+ * @type {string}
238
+ * @memberof ConfigurationWebsocketAPI
239
+ */
240
+ privateKeyPassphrase?: string;
241
+ /**
242
+ * timeUnit (used only on SPOT API)
243
+ * @type {TimeUnit}
244
+ * @memberof ConfigurationWebsocketAPI
245
+ */
246
+ timeUnit?: TimeUnit;
247
+ /**
248
+ * auto session re-logon on reconnects/renewals
249
+ * @default true
250
+ * @type {boolean}
251
+ * @memberof ConfigurationWebsocketAPI
252
+ */
253
+ autoSessionReLogon?: boolean;
254
+ constructor(param?: ConfigurationWebsocketAPI);
253
255
  }
254
256
  declare class ConfigurationWebsocketStreams {
255
- /**
256
- * override websocket url
257
- * @type {string}
258
- * @memberof ConfigurationWebsocketStreams
259
- */
260
- wsURL?: string;
261
- /**
262
- * reconnction delay
263
- * @default 5000
264
- * @type {number}
265
- * @memberof ConfigurationWebsocketStreams
266
- */
267
- reconnectDelay?: number;
268
- /**
269
- * use compression for websocket messages
270
- * @default true
271
- * @type {boolean}
272
- * @memberof ConfigurationWebsocketAPI
273
- */
274
- compression?: boolean;
275
- /**
276
- * websocket agent
277
- * @default false
278
- * @type {boolean | Agent}
279
- * @memberof ConfigurationWebsocketStreams
280
- */
281
- agent?: boolean | Agent;
282
- /**
283
- * the mode of the connection, either 'single' or 'pool'.
284
- * @default single
285
- * @type {'single' | 'pool'}
286
- * @memberof ConfigurationWebsocketStreams
287
- */
288
- mode?: 'single' | 'pool';
289
- /**
290
- * the size of the connection pool, if the mode is set to 'pool'.
291
- * @default 1
292
- * @type {number}
293
- * @memberof ConfigurationWebsocketStreams
294
- */
295
- poolSize?: number;
296
- /**
297
- * timeUnit (used only on SPOT API)
298
- * @type {TimeUnit}
299
- * @memberof ConfigurationWebsocketStreams
300
- */
301
- timeUnit?: TimeUnit;
302
- constructor(param?: ConfigurationWebsocketStreams);
257
+ /**
258
+ * override websocket url
259
+ * @type {string}
260
+ * @memberof ConfigurationWebsocketStreams
261
+ */
262
+ wsURL?: string;
263
+ /**
264
+ * reconnction delay
265
+ * @default 5000
266
+ * @type {number}
267
+ * @memberof ConfigurationWebsocketStreams
268
+ */
269
+ reconnectDelay?: number;
270
+ /**
271
+ * use compression for websocket messages
272
+ * @default true
273
+ * @type {boolean}
274
+ * @memberof ConfigurationWebsocketAPI
275
+ */
276
+ compression?: boolean;
277
+ /**
278
+ * websocket agent
279
+ * @default false
280
+ * @type {boolean | Agent}
281
+ * @memberof ConfigurationWebsocketStreams
282
+ */
283
+ agent?: boolean | Agent;
284
+ /**
285
+ * the mode of the connection, either 'single' or 'pool'.
286
+ * @default single
287
+ * @type {'single' | 'pool'}
288
+ * @memberof ConfigurationWebsocketStreams
289
+ */
290
+ mode?: 'single' | 'pool';
291
+ /**
292
+ * the size of the connection pool, if the mode is set to 'pool'.
293
+ * @default 1
294
+ * @type {number}
295
+ * @memberof ConfigurationWebsocketStreams
296
+ */
297
+ poolSize?: number;
298
+ /**
299
+ * timeUnit (used only on SPOT API)
300
+ * @type {TimeUnit}
301
+ * @memberof ConfigurationWebsocketStreams
302
+ */
303
+ timeUnit?: TimeUnit;
304
+ constructor(param?: ConfigurationWebsocketStreams);
303
305
  }
304
-
306
+ //#endregion
307
+ //#region src/errors.d.ts
305
308
  /**
306
309
  * Represents an error that occurred in the Connector client.
307
310
  * @param msg - An optional error message.
308
311
  */
309
312
  declare class ConnectorClientError extends Error {
310
- constructor(msg?: string);
313
+ constructor(msg?: string);
311
314
  }
312
315
  /**
313
316
  * Represents an error that occurs when a required parameter is missing or undefined.
@@ -315,36 +318,36 @@ declare class ConnectorClientError extends Error {
315
318
  * @param msg - An optional error message.
316
319
  */
317
320
  declare class RequiredError extends Error {
318
- field: string;
319
- constructor(field: string, msg?: string);
321
+ field: string;
322
+ constructor(field: string, msg?: string);
320
323
  }
321
324
  /**
322
325
  * Represents an error that occurs when a client is unauthorized to access a resource.
323
326
  * @param msg - An optional error message.
324
327
  */
325
328
  declare class UnauthorizedError extends Error {
326
- constructor(msg?: string);
329
+ constructor(msg?: string);
327
330
  }
328
331
  /**
329
332
  * Represents an error that occurs when a resource is forbidden to the client.
330
333
  * @param msg - An optional error message.
331
334
  */
332
335
  declare class ForbiddenError extends Error {
333
- constructor(msg?: string);
336
+ constructor(msg?: string);
334
337
  }
335
338
  /**
336
339
  * Represents an error that occurs when client is doing too many requests.
337
340
  * @param msg - An optional error message.
338
341
  */
339
342
  declare class TooManyRequestsError extends Error {
340
- constructor(msg?: string);
343
+ constructor(msg?: string);
341
344
  }
342
345
  /**
343
346
  * Represents an error that occurs when client's IP has been banned.
344
347
  * @param msg - An optional error message.
345
348
  */
346
349
  declare class RateLimitBanError extends Error {
347
- constructor(msg?: string);
350
+ constructor(msg?: string);
348
351
  }
349
352
  /**
350
353
  * Represents an error that occurs when there is an internal server error.
@@ -352,54 +355,56 @@ declare class RateLimitBanError extends Error {
352
355
  * @param statusCode - An optional HTTP status code associated with the error.
353
356
  */
354
357
  declare class ServerError extends Error {
355
- statusCode?: number | undefined;
356
- constructor(msg?: string, statusCode?: number | undefined);
358
+ statusCode?: number | undefined;
359
+ constructor(msg?: string, statusCode?: number | undefined);
357
360
  }
358
361
  /**
359
362
  * Represents an error that occurs when a network error occurs.
360
363
  * @param msg - An optional error message.
361
364
  */
362
365
  declare class NetworkError extends Error {
363
- constructor(msg?: string);
366
+ constructor(msg?: string);
364
367
  }
365
368
  /**
366
369
  * Represents an error that occurs when the requested resource was not found.
367
370
  * @param msg - An optional error message.
368
371
  */
369
372
  declare class NotFoundError extends Error {
370
- constructor(msg?: string);
373
+ constructor(msg?: string);
371
374
  }
372
375
  /**
373
376
  * Represents an error that occurs when a request is invalid or cannot be otherwise served.
374
377
  * @param msg - An optional error message.
375
378
  */
376
379
  declare class BadRequestError extends Error {
377
- constructor(msg?: string);
380
+ constructor(msg?: string);
378
381
  }
379
-
382
+ //#endregion
383
+ //#region src/logger.d.ts
380
384
  declare enum LogLevel {
381
- NONE = "",
382
- DEBUG = "debug",
383
- INFO = "info",
384
- WARN = "warn",
385
- ERROR = "error"
385
+ NONE = "",
386
+ DEBUG = "debug",
387
+ INFO = "info",
388
+ WARN = "warn",
389
+ ERROR = "error",
386
390
  }
387
391
  declare class Logger {
388
- private static instance;
389
- private minLogLevel;
390
- private readonly levelsOrder;
391
- constructor();
392
- static getInstance(): Logger;
393
- setMinLogLevel(level: LogLevel): void;
394
- private isValidLogLevel;
395
- private log;
396
- private allowLevelLog;
397
- debug(...message: unknown[]): void;
398
- info(...message: unknown[]): void;
399
- warn(...message: unknown[]): void;
400
- error(...message: unknown[]): void;
392
+ private static instance;
393
+ private minLogLevel;
394
+ private readonly levelsOrder;
395
+ constructor();
396
+ static getInstance(): Logger;
397
+ setMinLogLevel(level: LogLevel): void;
398
+ private isValidLogLevel;
399
+ private log;
400
+ private allowLevelLog;
401
+ debug(...message: unknown[]): void;
402
+ info(...message: unknown[]): void;
403
+ warn(...message: unknown[]): void;
404
+ error(...message: unknown[]): void;
401
405
  }
402
-
406
+ //#endregion
407
+ //#region src/types.d.ts
403
408
  /**
404
409
  * Represents the rate limit information for a REST API response.
405
410
  * @property {string} rateLimitType - The type of rate limit, either 'REQUEST_WEIGHT' or 'ORDERS'.
@@ -409,11 +414,11 @@ declare class Logger {
409
414
  * @property {number} [retryAfter] - The number of seconds to wait before retrying the request.
410
415
  */
411
416
  interface RestApiRateLimit {
412
- rateLimitType: 'REQUEST_WEIGHT' | 'ORDERS';
413
- interval: 'SECOND' | 'MINUTE' | 'HOUR' | 'DAY';
414
- intervalNum: number;
415
- count: number;
416
- retryAfter?: number;
417
+ rateLimitType: 'REQUEST_WEIGHT' | 'ORDERS';
418
+ interval: 'SECOND' | 'MINUTE' | 'HOUR' | 'DAY';
419
+ intervalNum: number;
420
+ count: number;
421
+ retryAfter?: number;
417
422
  }
418
423
  /**
419
424
  * Represents the response from a REST API request.
@@ -424,10 +429,10 @@ interface RestApiRateLimit {
424
429
  * @property {RestApiRateLimit[]} [rateLimits] - An optional array of rate limit information for the response.
425
430
  */
426
431
  type RestApiResponse<T> = {
427
- data: () => Promise<T>;
428
- status: number;
429
- headers: Record<string, string>;
430
- rateLimits?: RestApiRateLimit[];
432
+ data: () => Promise<T>;
433
+ status: number;
434
+ headers: Record<string, string>;
435
+ rateLimits?: RestApiRateLimit[];
431
436
  };
432
437
  /**
433
438
  * Represents the rate limit information for a WebSocket API response.
@@ -438,11 +443,11 @@ type RestApiResponse<T> = {
438
443
  * @property {number} count - The current count of requests or orders for the rate limit.
439
444
  */
440
445
  interface WebsocketApiRateLimit {
441
- rateLimitType: 'REQUEST_WEIGHT' | 'ORDERS';
442
- interval: 'SECOND' | 'MINUTE' | 'HOUR' | 'DAY';
443
- intervalNum: number;
444
- limit: number;
445
- count: number;
446
+ rateLimitType: 'REQUEST_WEIGHT' | 'ORDERS';
447
+ interval: 'SECOND' | 'MINUTE' | 'HOUR' | 'DAY';
448
+ intervalNum: number;
449
+ limit: number;
450
+ count: number;
446
451
  }
447
452
  /**
448
453
  * Extracts the result or response from a WebSocket API response type.
@@ -458,21 +463,21 @@ type ExtractWebsocketApiResponse<T> = 'result' extends keyof T ? T['result'] : '
458
463
  * @property {WebsocketApiRateLimit[]} [rateLimits] - An optional array of rate limit information for the response.
459
464
  */
460
465
  type WebsocketApiResponse<T> = {
461
- data: NonNullable<ExtractWebsocketApiResponse<T>>;
462
- rateLimits?: WebsocketApiRateLimit[];
466
+ data: NonNullable<ExtractWebsocketApiResponse<T>>;
467
+ rateLimits?: WebsocketApiRateLimit[];
463
468
  };
464
469
  /**
465
470
  * Represents the options for sending a message.
466
471
  * The object can have any number of properties, where the keys are strings and the values can be strings, numbers, booleans, objects, or undefined.
467
472
  */
468
473
  interface SendMessageOptions {
469
- [key: string]: string | number | boolean | object | undefined;
474
+ [key: string]: string | number | boolean | object | undefined;
470
475
  }
471
476
  /**
472
477
  * Represents an object type where the keys are strings and the values can be strings, numbers, booleans, or objects.
473
478
  */
474
479
  interface ObjectType {
475
- [key: string]: string | number | boolean | object;
480
+ [key: string]: string | number | boolean | object;
476
481
  }
477
482
  /**
478
483
  * Represents the arguments for an Axios request.
@@ -480,8 +485,8 @@ interface ObjectType {
480
485
  * @property {RawAxiosRequestConfig} options - The options for the Axios request.
481
486
  */
482
487
  interface AxiosRequestArgs {
483
- url: string;
484
- options: RawAxiosRequestConfig;
488
+ url: string;
489
+ options: RawAxiosRequestConfig;
485
490
  }
486
491
  /**
487
492
  * Represents the arguments for a request.
@@ -491,12 +496,13 @@ interface AxiosRequestArgs {
491
496
  * @property {TimeUnit} [timeUnit] - The optional time unit for the request.
492
497
  */
493
498
  interface RequestArgs {
494
- endpoint: string;
495
- method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
496
- params: Record<string, unknown>;
497
- timeUnit?: TimeUnit;
499
+ endpoint: string;
500
+ method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';
501
+ params: Record<string, unknown>;
502
+ timeUnit?: TimeUnit;
498
503
  }
499
-
504
+ //#endregion
505
+ //#region src/utils.d.ts
500
506
  /**
501
507
  * Resets the signer cache to a new empty WeakMap.
502
508
  *
@@ -550,9 +556,9 @@ declare function getTimestamp(): number;
550
556
  * @returns A string representing the generated signature.
551
557
  */
552
558
  declare const getSignature: (configuration: {
553
- apiSecret?: string;
554
- privateKey?: string | Buffer;
555
- privateKeyPassphrase?: string;
559
+ apiSecret?: string;
560
+ privateKey?: string | Buffer;
561
+ privateKeyPassphrase?: string;
556
562
  }, queryParams: Record<string, unknown>) => string;
557
563
  /**
558
564
  * Asserts that a function parameter exists and is not null or undefined.
@@ -586,9 +592,7 @@ declare const toPathString: (url: URL) => string;
586
592
  * @template T The input type to be transformed
587
593
  * @returns A type where numbers potentially become strings, maintaining the original type's structure
588
594
  */
589
- type ScientificToString<T> = T extends number ? string | number : T extends Array<infer U> ? Array<ScientificToString<U>> : T extends object ? {
590
- [K in keyof T]: ScientificToString<T[K]>;
591
- } : T;
595
+ type ScientificToString<T> = T extends number ? string | number : T extends Array<infer U> ? Array<ScientificToString<U>> : T extends object ? { [K in keyof T]: ScientificToString<T[K]> } : T;
592
596
  /**
593
597
  * Normalizes scientific notation numbers in an object or array to a fixed number of decimal places.
594
598
  *
@@ -638,7 +642,7 @@ declare const parseRateLimitHeaders: (headers: RawAxiosResponseHeaders | AxiosRe
638
642
  * @returns A promise resolving to the response data object.
639
643
  */
640
644
  declare const sendRequest: <T>(configuration: ConfigurationRestAPI, endpoint: string, method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH", params?: Record<string, unknown>, timeUnit?: TimeUnit, options?: {
641
- isSigned?: boolean;
645
+ isSigned?: boolean;
642
646
  }) => Promise<RestApiResponse<T>>;
643
647
  /**
644
648
  * Removes any null, undefined, or empty string values from the provided object.
@@ -681,9 +685,9 @@ declare function buildUserAgent(packageName: string, packageVersion: string): st
681
685
  * @returns {Object} A structured WebSocket message with id, method, and params.
682
686
  */
683
687
  declare function buildWebsocketAPIMessage(configuration: ConfigurationWebsocketAPI, method: string, payload: WebsocketSendMsgOptions, options: WebsocketSendMsgConfig, skipAuth?: boolean): {
684
- id: string;
685
- method: string;
686
- params: Record<string, unknown>;
688
+ id: string;
689
+ method: string;
690
+ params: Record<string, unknown>;
687
691
  };
688
692
  /**
689
693
  * Sanitizes a header value by checking for and preventing carriage return and line feed characters.
@@ -702,364 +706,365 @@ declare function sanitizeHeaderValue(value: string | string[]): string | string[
702
706
  * and sanitizes remaining header values to prevent injection of carriage return or line feed characters.
703
707
  */
704
708
  declare function parseCustomHeaders(headers: Record<string, string | string[]>): Record<string, string | string[]>;
705
-
709
+ //#endregion
710
+ //#region src/websocket.d.ts
706
711
  declare class WebsocketEventEmitter {
707
- private eventEmitter;
708
- constructor();
709
- on(event: 'open' | 'message' | 'error' | 'close' | 'ping' | 'pong', listener: (...args: any[]) => void): void;
710
- off(event: 'open' | 'message' | 'error' | 'close' | 'ping' | 'pong', listener: (...args: any[]) => void): void;
711
- protected emit(event: 'open' | 'message' | 'error' | 'close' | 'ping' | 'pong', ...args: any[]): void;
712
+ private eventEmitter;
713
+ constructor();
714
+ on(event: 'open' | 'message' | 'error' | 'close' | 'ping' | 'pong', listener: (...args: any[]) => void): void;
715
+ off(event: 'open' | 'message' | 'error' | 'close' | 'ping' | 'pong', listener: (...args: any[]) => void): void;
716
+ protected emit(event: 'open' | 'message' | 'error' | 'close' | 'ping' | 'pong', ...args: any[]): void;
712
717
  }
713
718
  interface TimerRecord {
714
- timer?: NodeJS.Timeout;
715
- type: 'timeout' | 'interval';
719
+ timer?: NodeJS.Timeout;
720
+ type: 'timeout' | 'interval';
716
721
  }
717
722
  interface WebsocketConnection {
718
- id: string;
719
- reconnectionPending: boolean;
720
- renewalPending: boolean;
721
- closeInitiated: boolean;
722
- pendingRequests: Map<string, {
723
- resolve: (value: any) => void;
724
- reject: (reason?: unknown) => void;
725
- }>;
726
- pendingSubscriptions?: string[];
727
- ws?: WebSocketClient;
728
- isSessionLoggedOn?: boolean;
729
- sessionLogonReq?: {
730
- method: string;
731
- payload: WebsocketSendMsgOptions;
732
- options: WebsocketSendMsgConfig;
733
- };
723
+ id: string;
724
+ reconnectionPending: boolean;
725
+ renewalPending: boolean;
726
+ closeInitiated: boolean;
727
+ pendingRequests: Map<string, {
728
+ resolve: (value: any) => void;
729
+ reject: (reason?: unknown) => void;
730
+ }>;
731
+ pendingSubscriptions?: string[];
732
+ ws?: WebSocketClient;
733
+ isSessionLoggedOn?: boolean;
734
+ sessionLogonReq?: {
735
+ method: string;
736
+ payload: WebsocketSendMsgOptions;
737
+ options: WebsocketSendMsgConfig;
738
+ };
734
739
  }
735
740
  declare class WebsocketCommon extends WebsocketEventEmitter {
736
- protected configuration: ConfigurationWebsocketAPI | ConfigurationWebsocketStreams;
737
- private static readonly MAX_CONNECTION_DURATION;
738
- private readonly connectionQueue;
739
- private queueProcessing;
740
- protected connectionTimers: Map<WebSocketClient, Set<TimerRecord>>;
741
- private mode;
742
- private poolSize;
743
- private roundRobinIndex;
744
- connectionPool: WebsocketConnection[];
745
- logger: Logger;
746
- constructor(configuration: ConfigurationWebsocketAPI | ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
747
- /**
748
- * Initializes the WebSocket connection pool by creating a specified number of connection objects
749
- * and adding them to the `connectionPool` array. Each connection object has the following properties:
750
- * - `closeInitiated`: a boolean indicating whether the connection has been closed
751
- * - `reconnectionPending`: a boolean indicating whether a reconnection is pending
752
- * - `pendingRequests`: a Map that tracks pending requests for the connection
753
- * @param size - The number of connection objects to create and add to the pool.
754
- * @returns void
755
- */
756
- private initializePool;
757
- /**
758
- * Retrieves available WebSocket connections based on the connection mode and readiness.
759
- * In 'single' mode, returns the first connection in the pool.
760
- * In 'pool' mode, filters and returns connections that are ready for use.
761
- * @param allowNonEstablishedWebsockets - Optional flag to include non-established WebSocket connections.
762
- * @returns An array of available WebSocket connections.
763
- */
764
- protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean): WebsocketConnection[];
765
- /**
766
- * Gets a WebSocket connection from the pool or single connection.
767
- * If the connection mode is 'single', it returns the first connection in the pool.
768
- * If the connection mode is 'pool', it returns an available connection from the pool,
769
- * using a round-robin selection strategy. If no available connections are found, it throws an error.
770
- * @param allowNonEstablishedWebsockets - A boolean indicating whether to allow connections that are not established.
771
- * @returns {WebsocketConnection} The selected WebSocket connection.
772
- */
773
- protected getConnection(allowNonEstablishedWebsockets?: boolean): WebsocketConnection;
774
- /**
775
- * Checks if the provided WebSocket connection is ready for use.
776
- * A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
777
- * @param connection - The WebSocket connection to check.
778
- * @param allowNonEstablishedWebsockets - An optional flag to allow non-established WebSocket connections.
779
- * @returns `true` if the connection is ready, `false` otherwise.
780
- */
781
- protected isConnectionReady(connection: WebsocketConnection, allowNonEstablishedWebsockets?: boolean): boolean;
782
- /**
783
- * Schedules a timer for a WebSocket connection and tracks it
784
- * @param connection WebSocket client instance
785
- * @param callback Function to execute when timer triggers
786
- * @param delay Time in milliseconds before callback execution
787
- * @param type Timer type ('timeout' or 'interval')
788
- * @returns Timer handle
789
- */
790
- protected scheduleTimer(connection: WebSocketClient, callback: () => void, delay: number, type?: 'timeout' | 'interval'): NodeJS.Timeout;
791
- /**
792
- * Clears all timers associated with a WebSocket connection.
793
- * @param connection - The WebSocket client instance to clear timers for.
794
- * @returns void
795
- */
796
- protected clearTimers(connection: WebSocketClient): void;
797
- /**
798
- * Processes the connection queue, reconnecting or renewing connections as needed.
799
- * This method is responsible for iterating through the connection queue and initiating
800
- * the reconnection or renewal process for each connection in the queue. It throttles
801
- * the queue processing to avoid overwhelming the server with too many connection
802
- * requests at once.
803
- * @param throttleRate - The time in milliseconds to wait between processing each
804
- * connection in the queue.
805
- * @returns A Promise that resolves when the queue has been fully processed.
806
- */
807
- private processQueue;
808
- /**
809
- * Enqueues a reconnection or renewal for a WebSocket connection.
810
- * This method adds the connection, URL, and renewal flag to the connection queue,
811
- * and then calls the `processQueue` method to initiate the reconnection or renewal
812
- * process.
813
- * @param connection - The WebSocket connection to reconnect or renew.
814
- * @param url - The URL to use for the reconnection or renewal.
815
- * @param isRenewal - A flag indicating whether this is a renewal (true) or a reconnection (false).
816
- */
817
- private enqueueReconnection;
818
- /**
819
- * Gracefully closes a WebSocket connection after pending requests complete.
820
- * This method waits for any pending requests to complete before closing the connection.
821
- * It sets up a timeout to force-close the connection after 30 seconds if the pending requests
822
- * do not complete. Once all pending requests are completed, the connection is closed.
823
- * @param connectionToClose - The WebSocket client instance to close.
824
- * @param WebsocketConnectionToClose - The WebSocket connection to close.
825
- * @param connection - The WebSocket connection to close.
826
- * @returns Promise that resolves when the connection is closed.
827
- */
828
- private closeConnectionGracefully;
829
- /**
830
- * Attempts to re-establish a session for a WebSocket connection.
831
- * If a session logon request exists and the connection is not already logged on,
832
- * it sends an authentication request and updates the connection's logged-on status.
833
- * @param connection - The WebSocket connection to re-authenticate.
834
- * @private
835
- */
836
- private sessionReLogon;
837
- /**
838
- * Cleans up WebSocket connection resources.
839
- * Removes all listeners and clears any associated timers for the provided WebSocket client.
840
- * @param ws - The WebSocket client to clean up.
841
- * @returns void
842
- */
843
- protected cleanup(ws: WebSocketClient): void;
844
- /**
845
- * Handles incoming WebSocket messages
846
- * @param data Raw message data received
847
- * @param connection Websocket connection
848
- */
849
- protected onMessage(data: string, connection: WebsocketConnection): void;
850
- /**
851
- * Handles the opening of a WebSocket connection.
852
- * @param url - The URL of the WebSocket server.
853
- * @param targetConnection - The WebSocket connection being opened.
854
- * @param oldWSConnection - The WebSocket client instance associated with the old connection.
855
- */
856
- protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
857
- /**
858
- * Returns the URL to use when reconnecting.
859
- * Derived classes should override this to provide dynamic URLs.
860
- * @param defaultURL The URL originally passed during the first connection.
861
- * @param targetConnection The WebSocket connection being connected.
862
- * @returns The URL to reconnect to.
863
- */
864
- protected getReconnectURL(defaultURL: string, targetConnection: WebsocketConnection): string;
865
- /**
866
- * Connects all WebSocket connections in the pool
867
- * @param url - The Websocket server URL.
868
- * @returns A promise that resolves when all connections are established.
869
- */
870
- protected connectPool(url: string): Promise<void>;
871
- /**
872
- * Creates a new WebSocket client instance.
873
- * @param url - The URL to connect to.
874
- * @returns A new WebSocket client instance.
875
- */
876
- protected createWebSocket(url: string): WebSocketClient;
877
- /**
878
- * Initializes a WebSocket connection.
879
- * @param url - The Websocket server URL.
880
- * @param isRenewal - Whether this is a connection renewal.
881
- * @param connection - An optional WebSocket connection to use.
882
- * @returns The WebSocket connection.
883
- */
884
- protected initConnect(url: string, isRenewal?: boolean, connection?: WebsocketConnection): WebsocketConnection | undefined;
885
- /**
886
- * Checks if the WebSocket connection is currently open.
887
- * @param connection - An optional WebSocket connection to check. If not provided, the entire connection pool is checked.
888
- * @returns `true` if the connection is open, `false` otherwise.
889
- */
890
- isConnected(connection?: WebsocketConnection): boolean;
891
- /**
892
- * Disconnects from the WebSocket server.
893
- * If there is no active connection, a warning is logged.
894
- * Otherwise, all connections in the connection pool are closed gracefully,
895
- * and a message is logged indicating that the connection has been disconnected.
896
- * @returns A Promise that resolves when all connections have been closed.
897
- * @throws Error if the WebSocket client is not set.
898
- */
899
- disconnect(): Promise<void>;
900
- /**
901
- * Sends a ping message to all connected Websocket servers in the pool.
902
- * If no connections are ready, a warning is logged.
903
- * For each active connection, the ping message is sent, and debug logs provide details.
904
- * @throws Error if a Websocket client is not set for a connection.
905
- */
906
- pingServer(): void;
907
- /**
908
- * Sends a payload through the WebSocket connection.
909
- * @param payload - Message to send.
910
- * @param id - Optional request identifier.
911
- * @param promiseBased - Whether to return a promise.
912
- * @param timeout - Timeout duration in milliseconds.
913
- * @param connection - The WebSocket connection to use.
914
- * @returns A promise if `promiseBased` is true, void otherwise.
915
- * @throws Error if not connected or WebSocket client is not set.
916
- */
917
- protected send<T = unknown>(payload: string, id?: string, promiseBased?: boolean, timeout?: number, connection?: WebsocketConnection): Promise<WebsocketApiResponse<T>> | void;
741
+ protected configuration: ConfigurationWebsocketAPI | ConfigurationWebsocketStreams;
742
+ private static readonly MAX_CONNECTION_DURATION;
743
+ private readonly connectionQueue;
744
+ private queueProcessing;
745
+ protected connectionTimers: Map<WebSocketClient, Set<TimerRecord>>;
746
+ private mode;
747
+ private poolSize;
748
+ private roundRobinIndex;
749
+ connectionPool: WebsocketConnection[];
750
+ logger: Logger;
751
+ constructor(configuration: ConfigurationWebsocketAPI | ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
752
+ /**
753
+ * Initializes the WebSocket connection pool by creating a specified number of connection objects
754
+ * and adding them to the `connectionPool` array. Each connection object has the following properties:
755
+ * - `closeInitiated`: a boolean indicating whether the connection has been closed
756
+ * - `reconnectionPending`: a boolean indicating whether a reconnection is pending
757
+ * - `pendingRequests`: a Map that tracks pending requests for the connection
758
+ * @param size - The number of connection objects to create and add to the pool.
759
+ * @returns void
760
+ */
761
+ private initializePool;
762
+ /**
763
+ * Retrieves available WebSocket connections based on the connection mode and readiness.
764
+ * In 'single' mode, returns the first connection in the pool.
765
+ * In 'pool' mode, filters and returns connections that are ready for use.
766
+ * @param allowNonEstablishedWebsockets - Optional flag to include non-established WebSocket connections.
767
+ * @returns An array of available WebSocket connections.
768
+ */
769
+ protected getAvailableConnections(allowNonEstablishedWebsockets?: boolean): WebsocketConnection[];
770
+ /**
771
+ * Gets a WebSocket connection from the pool or single connection.
772
+ * If the connection mode is 'single', it returns the first connection in the pool.
773
+ * If the connection mode is 'pool', it returns an available connection from the pool,
774
+ * using a round-robin selection strategy. If no available connections are found, it throws an error.
775
+ * @param allowNonEstablishedWebsockets - A boolean indicating whether to allow connections that are not established.
776
+ * @returns {WebsocketConnection} The selected WebSocket connection.
777
+ */
778
+ protected getConnection(allowNonEstablishedWebsockets?: boolean): WebsocketConnection;
779
+ /**
780
+ * Checks if the provided WebSocket connection is ready for use.
781
+ * A connection is considered ready if it is open, has no pending reconnection, and has not been closed.
782
+ * @param connection - The WebSocket connection to check.
783
+ * @param allowNonEstablishedWebsockets - An optional flag to allow non-established WebSocket connections.
784
+ * @returns `true` if the connection is ready, `false` otherwise.
785
+ */
786
+ protected isConnectionReady(connection: WebsocketConnection, allowNonEstablishedWebsockets?: boolean): boolean;
787
+ /**
788
+ * Schedules a timer for a WebSocket connection and tracks it
789
+ * @param connection WebSocket client instance
790
+ * @param callback Function to execute when timer triggers
791
+ * @param delay Time in milliseconds before callback execution
792
+ * @param type Timer type ('timeout' or 'interval')
793
+ * @returns Timer handle
794
+ */
795
+ protected scheduleTimer(connection: WebSocketClient, callback: () => void, delay: number, type?: 'timeout' | 'interval'): NodeJS.Timeout;
796
+ /**
797
+ * Clears all timers associated with a WebSocket connection.
798
+ * @param connection - The WebSocket client instance to clear timers for.
799
+ * @returns void
800
+ */
801
+ protected clearTimers(connection: WebSocketClient): void;
802
+ /**
803
+ * Processes the connection queue, reconnecting or renewing connections as needed.
804
+ * This method is responsible for iterating through the connection queue and initiating
805
+ * the reconnection or renewal process for each connection in the queue. It throttles
806
+ * the queue processing to avoid overwhelming the server with too many connection
807
+ * requests at once.
808
+ * @param throttleRate - The time in milliseconds to wait between processing each
809
+ * connection in the queue.
810
+ * @returns A Promise that resolves when the queue has been fully processed.
811
+ */
812
+ private processQueue;
813
+ /**
814
+ * Enqueues a reconnection or renewal for a WebSocket connection.
815
+ * This method adds the connection, URL, and renewal flag to the connection queue,
816
+ * and then calls the `processQueue` method to initiate the reconnection or renewal
817
+ * process.
818
+ * @param connection - The WebSocket connection to reconnect or renew.
819
+ * @param url - The URL to use for the reconnection or renewal.
820
+ * @param isRenewal - A flag indicating whether this is a renewal (true) or a reconnection (false).
821
+ */
822
+ private enqueueReconnection;
823
+ /**
824
+ * Gracefully closes a WebSocket connection after pending requests complete.
825
+ * This method waits for any pending requests to complete before closing the connection.
826
+ * It sets up a timeout to force-close the connection after 30 seconds if the pending requests
827
+ * do not complete. Once all pending requests are completed, the connection is closed.
828
+ * @param connectionToClose - The WebSocket client instance to close.
829
+ * @param WebsocketConnectionToClose - The WebSocket connection to close.
830
+ * @param connection - The WebSocket connection to close.
831
+ * @returns Promise that resolves when the connection is closed.
832
+ */
833
+ private closeConnectionGracefully;
834
+ /**
835
+ * Attempts to re-establish a session for a WebSocket connection.
836
+ * If a session logon request exists and the connection is not already logged on,
837
+ * it sends an authentication request and updates the connection's logged-on status.
838
+ * @param connection - The WebSocket connection to re-authenticate.
839
+ * @private
840
+ */
841
+ private sessionReLogon;
842
+ /**
843
+ * Cleans up WebSocket connection resources.
844
+ * Removes all listeners and clears any associated timers for the provided WebSocket client.
845
+ * @param ws - The WebSocket client to clean up.
846
+ * @returns void
847
+ */
848
+ protected cleanup(ws: WebSocketClient): void;
849
+ /**
850
+ * Handles incoming WebSocket messages
851
+ * @param data Raw message data received
852
+ * @param connection Websocket connection
853
+ */
854
+ protected onMessage(data: string, connection: WebsocketConnection): void;
855
+ /**
856
+ * Handles the opening of a WebSocket connection.
857
+ * @param url - The URL of the WebSocket server.
858
+ * @param targetConnection - The WebSocket connection being opened.
859
+ * @param oldWSConnection - The WebSocket client instance associated with the old connection.
860
+ */
861
+ protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
862
+ /**
863
+ * Returns the URL to use when reconnecting.
864
+ * Derived classes should override this to provide dynamic URLs.
865
+ * @param defaultURL The URL originally passed during the first connection.
866
+ * @param targetConnection The WebSocket connection being connected.
867
+ * @returns The URL to reconnect to.
868
+ */
869
+ protected getReconnectURL(defaultURL: string, targetConnection: WebsocketConnection): string;
870
+ /**
871
+ * Connects all WebSocket connections in the pool
872
+ * @param url - The Websocket server URL.
873
+ * @returns A promise that resolves when all connections are established.
874
+ */
875
+ protected connectPool(url: string): Promise<void>;
876
+ /**
877
+ * Creates a new WebSocket client instance.
878
+ * @param url - The URL to connect to.
879
+ * @returns A new WebSocket client instance.
880
+ */
881
+ protected createWebSocket(url: string): WebSocketClient;
882
+ /**
883
+ * Initializes a WebSocket connection.
884
+ * @param url - The Websocket server URL.
885
+ * @param isRenewal - Whether this is a connection renewal.
886
+ * @param connection - An optional WebSocket connection to use.
887
+ * @returns The WebSocket connection.
888
+ */
889
+ protected initConnect(url: string, isRenewal?: boolean, connection?: WebsocketConnection): WebsocketConnection | undefined;
890
+ /**
891
+ * Checks if the WebSocket connection is currently open.
892
+ * @param connection - An optional WebSocket connection to check. If not provided, the entire connection pool is checked.
893
+ * @returns `true` if the connection is open, `false` otherwise.
894
+ */
895
+ isConnected(connection?: WebsocketConnection): boolean;
896
+ /**
897
+ * Disconnects from the WebSocket server.
898
+ * If there is no active connection, a warning is logged.
899
+ * Otherwise, all connections in the connection pool are closed gracefully,
900
+ * and a message is logged indicating that the connection has been disconnected.
901
+ * @returns A Promise that resolves when all connections have been closed.
902
+ * @throws Error if the WebSocket client is not set.
903
+ */
904
+ disconnect(): Promise<void>;
905
+ /**
906
+ * Sends a ping message to all connected Websocket servers in the pool.
907
+ * If no connections are ready, a warning is logged.
908
+ * For each active connection, the ping message is sent, and debug logs provide details.
909
+ * @throws Error if a Websocket client is not set for a connection.
910
+ */
911
+ pingServer(): void;
912
+ /**
913
+ * Sends a payload through the WebSocket connection.
914
+ * @param payload - Message to send.
915
+ * @param id - Optional request identifier.
916
+ * @param promiseBased - Whether to return a promise.
917
+ * @param timeout - Timeout duration in milliseconds.
918
+ * @param connection - The WebSocket connection to use.
919
+ * @returns A promise if `promiseBased` is true, void otherwise.
920
+ * @throws Error if not connected or WebSocket client is not set.
921
+ */
922
+ protected send<T = unknown>(payload: string, id?: string, promiseBased?: boolean, timeout?: number, connection?: WebsocketConnection): Promise<WebsocketApiResponse<T>> | void;
918
923
  }
919
924
  interface WebsocketSendMsgOptions {
920
- id?: string;
921
- [key: string]: string | number | boolean | object | undefined;
925
+ id?: string;
926
+ [key: string]: string | number | boolean | object | undefined;
922
927
  }
923
928
  interface WebsocketSendMsgConfig {
924
- withApiKey?: boolean;
925
- isSigned?: boolean;
926
- isSessionLogon?: boolean;
927
- isSessionLogout?: boolean;
929
+ withApiKey?: boolean;
930
+ isSigned?: boolean;
931
+ isSessionLogon?: boolean;
932
+ isSessionLogout?: boolean;
928
933
  }
929
934
  declare class WebsocketAPIBase extends WebsocketCommon {
930
- private isConnecting;
931
- streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
932
- configuration: ConfigurationWebsocketAPI;
933
- logger: Logger;
934
- constructor(configuration: ConfigurationWebsocketAPI, connectionPool?: WebsocketConnection[]);
935
- /**
936
- * Prepares the WebSocket URL by adding optional timeUnit parameter
937
- * @param wsUrl The base WebSocket URL
938
- * @returns The formatted WebSocket URL with parameters
939
- */
940
- private prepareURL;
941
- /**
942
- * Processes incoming WebSocket messages
943
- * @param data The raw message data received
944
- */
945
- protected onMessage<T>(data: string, connection: WebsocketConnection): void;
946
- /**
947
- * Establishes a WebSocket connection to Binance
948
- * @returns Promise that resolves when connection is established
949
- * @throws Error if connection times out
950
- */
951
- connect(): Promise<void>;
952
- sendMessage<T>(method: string, payload: WebsocketSendMsgOptions, options: WebsocketSendMsgConfig & {
953
- isSessionLogon: true;
954
- }): Promise<WebsocketApiResponse<T>[]>;
955
- sendMessage<T>(method: string, payload: WebsocketSendMsgOptions, options: WebsocketSendMsgConfig & {
956
- isSessionLogout: true;
957
- }): Promise<WebsocketApiResponse<T>[]>;
958
- sendMessage<T>(method: string, payload?: WebsocketSendMsgOptions, options?: WebsocketSendMsgConfig): Promise<WebsocketApiResponse<T>>;
935
+ private isConnecting;
936
+ streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
937
+ configuration: ConfigurationWebsocketAPI;
938
+ logger: Logger;
939
+ constructor(configuration: ConfigurationWebsocketAPI, connectionPool?: WebsocketConnection[]);
940
+ /**
941
+ * Prepares the WebSocket URL by adding optional timeUnit parameter
942
+ * @param wsUrl The base WebSocket URL
943
+ * @returns The formatted WebSocket URL with parameters
944
+ */
945
+ private prepareURL;
946
+ /**
947
+ * Processes incoming WebSocket messages
948
+ * @param data The raw message data received
949
+ */
950
+ protected onMessage<T>(data: string, connection: WebsocketConnection): void;
951
+ /**
952
+ * Establishes a WebSocket connection to Binance
953
+ * @returns Promise that resolves when connection is established
954
+ * @throws Error if connection times out
955
+ */
956
+ connect(): Promise<void>;
957
+ sendMessage<T>(method: string, payload: WebsocketSendMsgOptions, options: WebsocketSendMsgConfig & {
958
+ isSessionLogon: true;
959
+ }): Promise<WebsocketApiResponse<T>[]>;
960
+ sendMessage<T>(method: string, payload: WebsocketSendMsgOptions, options: WebsocketSendMsgConfig & {
961
+ isSessionLogout: true;
962
+ }): Promise<WebsocketApiResponse<T>[]>;
963
+ sendMessage<T>(method: string, payload?: WebsocketSendMsgOptions, options?: WebsocketSendMsgConfig): Promise<WebsocketApiResponse<T>>;
959
964
  }
960
965
  declare class WebsocketStreamsBase extends WebsocketCommon {
961
- private streamConnectionMap;
962
- protected configuration: ConfigurationWebsocketStreams;
963
- protected wsURL: string;
964
- streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
965
- logger: Logger;
966
- constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
967
- /**
968
- * Formats the WebSocket URL for a given stream or streams.
969
- * @param streams - Array of stream names to include in the URL.
970
- * @returns The formatted WebSocket URL with the provided streams.
971
- */
972
- private prepareURL;
973
- /**
974
- * Formats the WebSocket URL with stream and configuration parameters to be used for reconnection.
975
- * @param url - The base WebSocket URL.
976
- * @param targetConnection - The target WebSocket connection.
977
- * @returns The formatted WebSocket URL with streams and optional parameters.
978
- */
979
- protected getReconnectURL(url: string, targetConnection: WebsocketConnection): string;
980
- /**
981
- * Handles subscription to streams and assigns them to specific connections
982
- * @param streams Array of stream names to subscribe to
983
- * @returns Map of connections to streams
984
- */
985
- private handleStreamAssignment;
986
- /**
987
- * Sends a subscription payload for specified streams on a given connection.
988
- * @param connection The WebSocket connection to use for sending the subscription.
989
- * @param streams The streams to subscribe to.
990
- * @param id Optional ID for the subscription.
991
- */
992
- private sendSubscriptionPayload;
993
- /**
994
- * Processes pending subscriptions for a given connection.
995
- * Sends all queued subscriptions in a single payload.
996
- * @param connection The WebSocket connection to process.
997
- */
998
- private processPendingSubscriptions;
999
- /**
1000
- * Handles incoming WebSocket messages, parsing the data and invoking the appropriate callback function.
1001
- * If the message contains a stream name that is registered in the `streamCallbackMap`, the corresponding
1002
- * callback function is called with the message data.
1003
- * If the message cannot be parsed, an error is logged.
1004
- * @param data The raw WebSocket message data.
1005
- * @param connection The WebSocket connection that received the message.
1006
- */
1007
- protected onMessage(data: string, connection: WebsocketConnection): void;
1008
- /**
1009
- * Called when the WebSocket connection is opened.
1010
- * Processes any pending subscriptions for the target connection.
1011
- * @param url The URL of the WebSocket connection.
1012
- * @param targetConnection The WebSocket connection that was opened.
1013
- * @param oldConnection The previous WebSocket connection, if any.
1014
- */
1015
- protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
1016
- /**
1017
- * Connects to the WebSocket server and subscribes to the specified streams.
1018
- * This method returns a Promise that resolves when the connection is established,
1019
- * or rejects with an error if the connection fails to be established within 10 seconds.
1020
- * @param stream - A single stream name or an array of stream names to subscribe to.
1021
- * @returns A Promise that resolves when the connection is established.
1022
- */
1023
- connect(stream?: string | string[]): Promise<void>;
1024
- /**
1025
- * Disconnects the WebSocket connection and clears the stream callback map.
1026
- * This method is called to clean up the connection and associated resources.
1027
- */
1028
- disconnect(): Promise<void>;
1029
- /**
1030
- * Subscribes to one or multiple WebSocket streams
1031
- * Handles both single and pool modes
1032
- * @param stream Single stream name or array of stream names to subscribe to
1033
- * @param id Optional subscription ID
1034
- * @returns void
1035
- */
1036
- subscribe(stream: string | string[], id?: string): void;
1037
- /**
1038
- * Unsubscribes from one or multiple WebSocket streams
1039
- * Handles both single and pool modes
1040
- * @param stream Single stream name or array of stream names to unsubscribe from
1041
- * @param id Optional unsubscription ID
1042
- * @returns void
1043
- */
1044
- unsubscribe(stream: string | string[], id?: string): void;
1045
- /**
1046
- * Checks if the specified stream is currently subscribed.
1047
- * @param stream - The name of the stream to check.
1048
- * @returns `true` if the stream is currently subscribed, `false` otherwise.
1049
- */
1050
- isSubscribed(stream: string): boolean;
966
+ private streamConnectionMap;
967
+ protected configuration: ConfigurationWebsocketStreams;
968
+ protected wsURL: string;
969
+ streamCallbackMap: Map<string, Set<(data: unknown) => void>>;
970
+ logger: Logger;
971
+ constructor(configuration: ConfigurationWebsocketStreams, connectionPool?: WebsocketConnection[]);
972
+ /**
973
+ * Formats the WebSocket URL for a given stream or streams.
974
+ * @param streams - Array of stream names to include in the URL.
975
+ * @returns The formatted WebSocket URL with the provided streams.
976
+ */
977
+ private prepareURL;
978
+ /**
979
+ * Formats the WebSocket URL with stream and configuration parameters to be used for reconnection.
980
+ * @param url - The base WebSocket URL.
981
+ * @param targetConnection - The target WebSocket connection.
982
+ * @returns The formatted WebSocket URL with streams and optional parameters.
983
+ */
984
+ protected getReconnectURL(url: string, targetConnection: WebsocketConnection): string;
985
+ /**
986
+ * Handles subscription to streams and assigns them to specific connections
987
+ * @param streams Array of stream names to subscribe to
988
+ * @returns Map of connections to streams
989
+ */
990
+ private handleStreamAssignment;
991
+ /**
992
+ * Sends a subscription payload for specified streams on a given connection.
993
+ * @param connection The WebSocket connection to use for sending the subscription.
994
+ * @param streams The streams to subscribe to.
995
+ * @param id Optional ID for the subscription.
996
+ */
997
+ private sendSubscriptionPayload;
998
+ /**
999
+ * Processes pending subscriptions for a given connection.
1000
+ * Sends all queued subscriptions in a single payload.
1001
+ * @param connection The WebSocket connection to process.
1002
+ */
1003
+ private processPendingSubscriptions;
1004
+ /**
1005
+ * Handles incoming WebSocket messages, parsing the data and invoking the appropriate callback function.
1006
+ * If the message contains a stream name that is registered in the `streamCallbackMap`, the corresponding
1007
+ * callback function is called with the message data.
1008
+ * If the message cannot be parsed, an error is logged.
1009
+ * @param data The raw WebSocket message data.
1010
+ * @param connection The WebSocket connection that received the message.
1011
+ */
1012
+ protected onMessage(data: string, connection: WebsocketConnection): void;
1013
+ /**
1014
+ * Called when the WebSocket connection is opened.
1015
+ * Processes any pending subscriptions for the target connection.
1016
+ * @param url The URL of the WebSocket connection.
1017
+ * @param targetConnection The WebSocket connection that was opened.
1018
+ * @param oldConnection The previous WebSocket connection, if any.
1019
+ */
1020
+ protected onOpen(url: string, targetConnection: WebsocketConnection, oldWSConnection: WebSocketClient): void;
1021
+ /**
1022
+ * Connects to the WebSocket server and subscribes to the specified streams.
1023
+ * This method returns a Promise that resolves when the connection is established,
1024
+ * or rejects with an error if the connection fails to be established within 10 seconds.
1025
+ * @param stream - A single stream name or an array of stream names to subscribe to.
1026
+ * @returns A Promise that resolves when the connection is established.
1027
+ */
1028
+ connect(stream?: string | string[]): Promise<void>;
1029
+ /**
1030
+ * Disconnects the WebSocket connection and clears the stream callback map.
1031
+ * This method is called to clean up the connection and associated resources.
1032
+ */
1033
+ disconnect(): Promise<void>;
1034
+ /**
1035
+ * Subscribes to one or multiple WebSocket streams
1036
+ * Handles both single and pool modes
1037
+ * @param stream Single stream name or array of stream names to subscribe to
1038
+ * @param id Optional subscription ID
1039
+ * @returns void
1040
+ */
1041
+ subscribe(stream: string | string[], id?: string): void;
1042
+ /**
1043
+ * Unsubscribes from one or multiple WebSocket streams
1044
+ * Handles both single and pool modes
1045
+ * @param stream Single stream name or array of stream names to unsubscribe from
1046
+ * @param id Optional unsubscription ID
1047
+ * @returns void
1048
+ */
1049
+ unsubscribe(stream: string | string[], id?: string): void;
1050
+ /**
1051
+ * Checks if the specified stream is currently subscribed.
1052
+ * @param stream - The name of the stream to check.
1053
+ * @returns `true` if the stream is currently subscribed, `false` otherwise.
1054
+ */
1055
+ isSubscribed(stream: string): boolean;
1051
1056
  }
1052
1057
  interface WebsocketStream<T> {
1053
- /**
1054
- * Attach a listener for the stream.
1055
- * @param event - Event name (currently supports "message").
1056
- * @param callback - Callback function to handle incoming data.
1057
- */
1058
- on(event: 'message', callback: (data: T) => void | Promise<void>): void;
1059
- /**
1060
- * Unsubscribe from the stream and clean up resources.
1061
- */
1062
- unsubscribe(): void;
1058
+ /**
1059
+ * Attach a listener for the stream.
1060
+ * @param event - Event name (currently supports "message").
1061
+ * @param callback - Callback function to handle incoming data.
1062
+ */
1063
+ on(event: 'message', callback: (data: T) => void | Promise<void>): void;
1064
+ /**
1065
+ * Unsubscribe from the stream and clean up resources.
1066
+ */
1067
+ unsubscribe(): void;
1063
1068
  }
1064
1069
  /**
1065
1070
  * Creates a WebSocket stream handler for managing stream subscriptions and callbacks.
@@ -1071,5 +1076,6 @@ interface WebsocketStream<T> {
1071
1076
  * @returns {WebsocketStream<T>} A stream handler with methods to register callbacks and unsubscribe
1072
1077
  */
1073
1078
  declare function createStreamHandler<T>(websocketBase: WebsocketAPIBase | WebsocketStreamsBase, streamOrId: string, id?: string): WebsocketStream<T>;
1074
-
1075
- export { ALGO_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_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, 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, type TimerRecord, TooManyRequestsError, UnauthorizedError, VIP_LOAN_REST_API_PROD_URL, WALLET_REST_API_PROD_URL, WebsocketAPIBase, type WebsocketApiRateLimit, type WebsocketApiResponse, WebsocketCommon, type WebsocketConnection, WebsocketEventEmitter, type WebsocketSendMsgConfig, type WebsocketSendMsgOptions, type 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 };
1079
+ //#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 };
1081
+ //# sourceMappingURL=index.d.ts.map