@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.mts +661 -655
- package/dist/index.d.ts +661 -655
- package/dist/index.js +1661 -1682
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1549 -1561
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Agent } from
|
|
2
|
-
import {
|
|
3
|
-
import WebSocketClient from
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
|
|
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
|
-
|
|
319
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
356
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
380
|
+
constructor(msg?: string);
|
|
378
381
|
}
|
|
379
|
-
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/logger.d.ts
|
|
380
384
|
declare enum LogLevel {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
385
|
+
NONE = "",
|
|
386
|
+
DEBUG = "debug",
|
|
387
|
+
INFO = "info",
|
|
388
|
+
WARN = "warn",
|
|
389
|
+
ERROR = "error",
|
|
386
390
|
}
|
|
387
391
|
declare class Logger {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|
-
|
|
462
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
484
|
-
|
|
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
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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
|
-
|
|
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
|
-
|
|
685
|
-
|
|
686
|
-
|
|
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
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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
|
-
|
|
715
|
-
|
|
719
|
+
timer?: NodeJS.Timeout;
|
|
720
|
+
type: 'timeout' | 'interval';
|
|
716
721
|
}
|
|
717
722
|
interface WebsocketConnection {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
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
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
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
|
-
|
|
921
|
-
|
|
925
|
+
id?: string;
|
|
926
|
+
[key: string]: string | number | boolean | object | undefined;
|
|
922
927
|
}
|
|
923
928
|
interface WebsocketSendMsgConfig {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
929
|
+
withApiKey?: boolean;
|
|
930
|
+
isSigned?: boolean;
|
|
931
|
+
isSessionLogon?: boolean;
|
|
932
|
+
isSessionLogout?: boolean;
|
|
928
933
|
}
|
|
929
934
|
declare class WebsocketAPIBase extends WebsocketCommon {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
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
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
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
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
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,
|
|
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
|