binance 2.15.14 → 3.0.0-beta.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.
Files changed (100) hide show
  1. package/README.md +5 -2
  2. package/lib/coinm-client.js.map +1 -1
  3. package/lib/index.d.ts +10 -4
  4. package/lib/index.js +10 -4
  5. package/lib/index.js.map +1 -1
  6. package/lib/main-client.d.ts +13 -2
  7. package/lib/main-client.js +15 -1
  8. package/lib/main-client.js.map +1 -1
  9. package/lib/portfolio-client.js.map +1 -1
  10. package/lib/types/futures.d.ts +1 -0
  11. package/lib/types/futures.js +3 -3
  12. package/lib/types/futures.js.map +1 -1
  13. package/lib/types/spot.js +4 -4
  14. package/lib/types/spot.js.map +1 -1
  15. package/lib/types/websockets/ws-api-requests.d.ts +7 -0
  16. package/lib/types/websockets/ws-api-requests.js +3 -0
  17. package/lib/types/websockets/ws-api-requests.js.map +1 -0
  18. package/lib/types/websockets/ws-api-responses.d.ts +8 -0
  19. package/lib/types/websockets/ws-api-responses.js +3 -0
  20. package/lib/types/websockets/ws-api-responses.js.map +1 -0
  21. package/lib/types/websockets/ws-api.d.ts +201 -0
  22. package/lib/types/websockets/ws-api.js +29 -0
  23. package/lib/types/websockets/ws-api.js.map +1 -0
  24. package/lib/types/{websockets.d.ts → websockets/ws-events-formatted.d.ts} +4 -410
  25. package/lib/types/websockets/ws-events-formatted.js +3 -0
  26. package/lib/types/websockets/ws-events-formatted.js.map +1 -0
  27. package/lib/types/websockets/ws-events-raw.d.ts +401 -0
  28. package/lib/types/{websockets.js → websockets/ws-events-raw.js} +1 -1
  29. package/lib/types/websockets/ws-events-raw.js.map +1 -0
  30. package/lib/types/websockets/ws-general.d.ts +98 -0
  31. package/lib/types/websockets/ws-general.js +11 -0
  32. package/lib/types/websockets/ws-general.js.map +1 -0
  33. package/lib/usdm-client.js.map +1 -1
  34. package/lib/util/BaseRestClient.d.ts +1 -1
  35. package/lib/util/BaseRestClient.js +1 -1
  36. package/lib/util/BaseRestClient.js.map +1 -1
  37. package/lib/util/BaseWSClient.d.ts +225 -0
  38. package/lib/util/BaseWSClient.js +729 -0
  39. package/lib/util/BaseWSClient.js.map +1 -0
  40. package/lib/util/beautifier-maps.d.ts +151 -0
  41. package/lib/util/beautifier-maps.js +198 -37
  42. package/lib/util/beautifier-maps.js.map +1 -1
  43. package/lib/util/beautifier.d.ts +7 -3
  44. package/lib/util/beautifier.js +40 -11
  45. package/lib/util/beautifier.js.map +1 -1
  46. package/lib/util/browser-support.d.ts +2 -1
  47. package/lib/util/browser-support.js +46 -28
  48. package/lib/util/browser-support.js.map +1 -1
  49. package/lib/util/logger.d.ts +8 -0
  50. package/lib/util/logger.js +17 -0
  51. package/lib/util/logger.js.map +1 -0
  52. package/lib/util/node-support.d.ts +2 -1
  53. package/lib/util/node-support.js +35 -15
  54. package/lib/util/node-support.js.map +1 -1
  55. package/lib/util/requestUtils.d.ts +19 -19
  56. package/lib/util/requestUtils.js +119 -38
  57. package/lib/util/requestUtils.js.map +1 -1
  58. package/lib/util/typeGuards.d.ts +9 -1
  59. package/lib/util/typeGuards.js +59 -34
  60. package/lib/util/typeGuards.js.map +1 -1
  61. package/lib/util/usdm/exchangeInfo.js +2 -3
  62. package/lib/util/usdm/exchangeInfo.js.map +1 -1
  63. package/lib/util/webCryptoAPI.d.ts +14 -0
  64. package/lib/util/webCryptoAPI.js +120 -0
  65. package/lib/util/webCryptoAPI.js.map +1 -0
  66. package/lib/util/websockets/WsStore.d.ts +74 -0
  67. package/lib/util/websockets/WsStore.js +279 -0
  68. package/lib/util/websockets/WsStore.js.map +1 -0
  69. package/lib/util/websockets/WsStore.types.d.ts +53 -0
  70. package/lib/util/websockets/WsStore.types.js +14 -0
  71. package/lib/util/websockets/WsStore.types.js.map +1 -0
  72. package/lib/util/websockets/listen-key-state-cache.d.ts +21 -0
  73. package/lib/util/websockets/listen-key-state-cache.js +80 -0
  74. package/lib/util/websockets/listen-key-state-cache.js.map +1 -0
  75. package/lib/util/websockets/rest-client-cache.d.ts +13 -0
  76. package/lib/util/websockets/rest-client-cache.js +56 -0
  77. package/lib/util/websockets/rest-client-cache.js.map +1 -0
  78. package/lib/util/websockets/user-data-stream-manager.d.ts +54 -0
  79. package/lib/util/websockets/user-data-stream-manager.js +256 -0
  80. package/lib/util/websockets/user-data-stream-manager.js.map +1 -0
  81. package/lib/util/websockets/websocket-util.d.ts +124 -0
  82. package/lib/util/websockets/websocket-util.js +481 -0
  83. package/lib/util/websockets/websocket-util.js.map +1 -0
  84. package/lib/websocket-client-legacy.d.ts +288 -0
  85. package/lib/websocket-client-legacy.js +1113 -0
  86. package/lib/websocket-client-legacy.js.map +1 -0
  87. package/lib/websocket-client.d.ts +228 -168
  88. package/lib/websocket-client.js +927 -834
  89. package/lib/websocket-client.js.map +1 -1
  90. package/package.json +5 -5
  91. package/lib/logger.d.ts +0 -9
  92. package/lib/logger.js +0 -23
  93. package/lib/logger.js.map +0 -1
  94. package/lib/types/websockets.js.map +0 -1
  95. package/lib/util/WsStore.d.ts +0 -57
  96. package/lib/util/WsStore.js +0 -101
  97. package/lib/util/WsStore.js.map +0 -1
  98. package/lib/util/ws-utils.d.ts +0 -7
  99. package/lib/util/ws-utils.js +0 -16
  100. package/lib/util/ws-utils.js.map +0 -1
@@ -0,0 +1,288 @@
1
+ import { EventEmitter } from 'events';
2
+ import WebSocket from 'isomorphic-ws';
3
+ import { KlineInterval } from './types/shared';
4
+ import { WSClientConfigurableOptions, WsResponse } from './types/websockets/ws-general';
5
+ import { DefaultLogger } from './util/logger';
6
+ import { WsKey } from './util/websockets/websocket-util';
7
+ import { WsFormattedMessage, WsUserDataEvents } from './types/websockets/ws-events-formatted';
8
+ import { WsRawMessage } from './types/websockets/ws-events-raw';
9
+ export declare interface WebsocketClientV1 {
10
+ on(event: 'reply', listener: (event: WsResponse) => void): this;
11
+ on(event: 'message', listener: (event: WsRawMessage) => void): this;
12
+ on(event: 'formattedMessage', listener: (event: WsFormattedMessage) => void): this;
13
+ on(event: 'formattedUserDataMessage', listener: (event: WsUserDataEvents) => void): this;
14
+ on(event: 'error', listener: (event: {
15
+ wsKey: WsKey;
16
+ error: any;
17
+ rawEvent?: string;
18
+ }) => void): this;
19
+ on(event: 'open' | 'reconnected' | 'reconnecting' | 'close', listener: (event: {
20
+ wsKey: WsKey;
21
+ ws: WebSocket;
22
+ event?: any;
23
+ }) => void): this;
24
+ }
25
+ /**
26
+ * This legacy websocket client creates one websocket connection per topic.
27
+ *
28
+ * If subscribing to a lot of topics, consider using the new multiplex `WebsocketClient`.
29
+ */
30
+ export declare class WebsocketClientV1 extends EventEmitter {
31
+ private logger;
32
+ private options;
33
+ private wsStore;
34
+ private beautifier;
35
+ private restClientCache;
36
+ private listenKeyStateCache;
37
+ private wsUrlKeyMap;
38
+ constructor(options: WSClientConfigurableOptions, logger?: typeof DefaultLogger);
39
+ private getRestClientOptions;
40
+ connectToWsUrl(url: string, wsKey?: WsKey | string, forceNewConnection?: boolean): WebSocket;
41
+ tryWsSend(wsKey: WsKey | string, wsMessage: string): void;
42
+ tryWsPing(wsKey: WsKey | string): void;
43
+ private onWsOpen;
44
+ private onWsClose;
45
+ private onWsMessage;
46
+ private sendPing;
47
+ private onWsPing;
48
+ private onWsPong;
49
+ /**
50
+ * Closes a connection, if it's even open. If open, this will trigger a reconnect asynchronously.
51
+ * If closed, trigger a reconnect immediately
52
+ */
53
+ private executeReconnectableClose;
54
+ close(wsKey: WsKey | string, shouldReconnectAfterClose?: boolean): void;
55
+ closeAll(shouldReconnectAfterClose?: boolean): void;
56
+ closeWs(ws: WebSocket, shouldReconnectAfterClose?: boolean): void;
57
+ private parseWsError;
58
+ private reconnectWithDelay;
59
+ private clearTimers;
60
+ private clearPingTimer;
61
+ private clearPongTimer;
62
+ private clearReconnectTimer;
63
+ private getWsBaseUrl;
64
+ getWs(wsKey: WsKey | string): WebSocket | undefined;
65
+ private setWsState;
66
+ /**
67
+ * Send WS message to subscribe to topics. Use subscribe() to call this.
68
+ */
69
+ private requestSubscribeTopics;
70
+ /**
71
+ * Send WS message to unsubscribe from topics. Use unsubscribe() to call this.
72
+ */
73
+ private requestUnsubscribeTopics;
74
+ /**
75
+ * Send WS message to unsubscribe from topics.
76
+ */
77
+ requestListSubscriptions(wsKey: WsKey, requestId: number): void;
78
+ /**
79
+ * Send WS message to set property state
80
+ */
81
+ requestSetProperty(wsKey: WsKey, property: 'combined' | string, value: any, requestId: number): void;
82
+ /**
83
+ * Send WS message to get property state
84
+ */
85
+ requestGetProperty(wsKey: WsKey, property: 'combined' | string, requestId: number): void;
86
+ /**
87
+ * --------------------------
88
+ * User data listen key tracking & persistence
89
+ * --------------------------
90
+ **/
91
+ private setKeepAliveListenKeyTimer;
92
+ private sendKeepAliveForMarket;
93
+ private checkKeepAliveListenKey;
94
+ private teardownUserDataListenKey;
95
+ private respawnUserDataStream;
96
+ /**
97
+ * --------------------------
98
+ * Universal market websocket streams (may apply to one or more API markets)
99
+ * --------------------------
100
+ **/
101
+ /**
102
+ * Subscribe to a universal market websocket stream
103
+ */
104
+ subscribeEndpoint(endpoint: string, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
105
+ /**
106
+ * Subscribe to aggregate trades for a symbol in a market category
107
+ */
108
+ subscribeAggregateTrades(symbol: string, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
109
+ /**
110
+ * Subscribe to trades for a symbol in a market category
111
+ * IMPORTANT: This topic for usdm and coinm is not listed in the api docs and might stop working without warning
112
+ */
113
+ subscribeTrades(symbol: string, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
114
+ /**
115
+ * Subscribe to coin index for a symbol in COINM Futures markets
116
+ */
117
+ subscribeCoinIndexPrice(symbol: string, updateSpeedMs?: 1000 | 3000, forceNewConnection?: boolean): WebSocket;
118
+ /**
119
+ * Subscribe to mark price for a symbol in a market category
120
+ */
121
+ subscribeMarkPrice(symbol: string, market: 'usdm' | 'coinm', updateSpeedMs?: 1000 | 3000, forceNewConnection?: boolean): WebSocket;
122
+ /**
123
+ * Subscribe to mark price for all symbols in a market category
124
+ */
125
+ subscribeAllMarketMarkPrice(market: 'usdm' | 'coinm', updateSpeedMs?: 1000 | 3000, forceNewConnection?: boolean): WebSocket;
126
+ /**
127
+ * Subscribe to klines(candles) for a symbol in a market category
128
+ */
129
+ subscribeKlines(symbol: string, interval: KlineInterval, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
130
+ /**
131
+ * Subscribe to continuous contract klines(candles) for a symbol futures
132
+ */
133
+ subscribeContinuousContractKlines(symbol: string, contractType: 'perpetual' | 'current_quarter' | 'next_quarter', interval: KlineInterval, market: 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
134
+ /**
135
+ * Subscribe to index klines(candles) for a symbol in a coinm futures
136
+ */
137
+ subscribeIndexKlines(symbol: string, interval: KlineInterval, forceNewConnection?: boolean): WebSocket;
138
+ /**
139
+ * Subscribe to index klines(candles) for a symbol in a coinm futures
140
+ */
141
+ subscribeMarkPriceKlines(symbol: string, interval: KlineInterval, forceNewConnection?: boolean): WebSocket;
142
+ /**
143
+ * Subscribe to mini 24hr ticker for a symbol in market category.
144
+ */
145
+ subscribeSymbolMini24hrTicker(symbol: string, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
146
+ /**
147
+ * Subscribe to mini 24hr mini ticker in market category.
148
+ */
149
+ subscribeAllMini24hrTickers(market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
150
+ /**
151
+ * Subscribe to 24hr ticker for a symbol in any market.
152
+ */
153
+ subscribeSymbol24hrTicker(symbol: string, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
154
+ /**
155
+ * Subscribe to 24hr ticker in any market.
156
+ */
157
+ subscribeAll24hrTickers(market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
158
+ /**
159
+ * Subscribe to rolling window ticker statistics for all market symbols,
160
+ * computed over multiple windows. Note that only tickers that have
161
+ * changed will be present in the array.
162
+ *
163
+ * Notes:
164
+ * - Supported window sizes: 1h,4h,1d.
165
+ * - Supported markets: spot
166
+ */
167
+ subscribeAllRollingWindowTickers(market: 'spot', windowSize: '1h' | '4h' | '1d', forceNewConnection?: boolean): WebSocket;
168
+ /**
169
+ * Subscribe to best bid/ask for symbol in spot markets.
170
+ */
171
+ subscribeSymbolBookTicker(symbol: string, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
172
+ /**
173
+ * Subscribe to best bid/ask for all symbols in spot markets.
174
+ */
175
+ subscribeAllBookTickers(market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
176
+ /**
177
+ * Subscribe to best bid/ask for symbol in spot markets.
178
+ */
179
+ subscribeSymbolLiquidationOrders(symbol: string, market: 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
180
+ /**
181
+ * Subscribe to best bid/ask for all symbols in spot markets.
182
+ */
183
+ subscribeAllLiquidationOrders(market: 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
184
+ /**
185
+ * Subscribe to partial book depths (snapshots).
186
+ *
187
+ * Note:
188
+ * - spot only supports 1000ms or 100ms for updateMs
189
+ * - futures only support 100, 250 or 500ms for updateMs
190
+ *
191
+ * Use getContextFromWsKey(data.wsKey) to extract symbol from events
192
+ */
193
+ subscribePartialBookDepths(symbol: string, levels: 5 | 10 | 20, updateMs: 100 | 250 | 500 | 1000, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
194
+ /**
195
+ * Subscribe to orderbook depth updates to locally manage an order book.
196
+ *
197
+ * Note that the updatems parameter depends on which market you're trading
198
+ *
199
+ * - Spot: https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream
200
+ * - USDM Futures: https://binance-docs.github.io/apidocs/futures/en/#diff-book-depth-streams
201
+ *
202
+ * Use getContextFromWsKey(data.wsKey) to extract symbol from events
203
+ */
204
+ subscribeDiffBookDepth(symbol: string, updateMs: 100 | 250 | 500 | 1000 | undefined, market: 'spot' | 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
205
+ /**
206
+ * Subscribe to best bid/ask for all symbols in spot markets.
207
+ */
208
+ subscribeContractInfoStream(market: 'usdm' | 'coinm', forceNewConnection?: boolean): WebSocket;
209
+ /**
210
+ * --------------------------
211
+ * SPOT market websocket streams
212
+ * --------------------------
213
+ **/
214
+ /**
215
+ * Subscribe to aggregate trades for a symbol in spot markets.
216
+ */
217
+ subscribeSpotAggregateTrades(symbol: string, forceNewConnection?: boolean): WebSocket;
218
+ /**
219
+ * Subscribe to trades for a symbol in spot markets.
220
+ */
221
+ subscribeSpotTrades(symbol: string, forceNewConnection?: boolean): WebSocket;
222
+ /**
223
+ * Subscribe to candles for a symbol in spot markets.
224
+ */
225
+ subscribeSpotKline(symbol: string, interval: KlineInterval, forceNewConnection?: boolean): WebSocket;
226
+ /**
227
+ * Subscribe to mini 24hr ticker for a symbol in spot markets.
228
+ */
229
+ subscribeSpotSymbolMini24hrTicker(symbol: string, forceNewConnection?: boolean): WebSocket;
230
+ /**
231
+ * Subscribe to mini 24hr mini ticker in spot markets.
232
+ */
233
+ subscribeSpotAllMini24hrTickers(forceNewConnection?: boolean): WebSocket;
234
+ /**
235
+ * Subscribe to 24hr ticker for a symbol in spot markets.
236
+ */
237
+ subscribeSpotSymbol24hrTicker(symbol: string, forceNewConnection?: boolean): WebSocket;
238
+ /**
239
+ * Subscribe to 24hr ticker in spot markets.
240
+ */
241
+ subscribeSpotAll24hrTickers(forceNewConnection?: boolean): WebSocket;
242
+ /**
243
+ * Subscribe to best bid/ask for symbol in spot markets.
244
+ */
245
+ subscribeSpotSymbolBookTicker(symbol: string, forceNewConnection?: boolean): WebSocket;
246
+ /**
247
+ * Subscribe to best bid/ask for all symbols in spot markets.
248
+ */
249
+ subscribeSpotAllBookTickers(forceNewConnection?: boolean): WebSocket;
250
+ /**
251
+ * Subscribe to top bid/ask levels for symbol in spot markets.
252
+ */
253
+ subscribeSpotPartialBookDepth(symbol: string, levels: 5 | 10 | 20, updateMs?: 1000 | 100, forceNewConnection?: boolean): WebSocket;
254
+ /**
255
+ * Subscribe to spot orderbook depth updates to locally manage an order book.
256
+ */
257
+ subscribeSpotDiffBookDepth(symbol: string, updateMs?: 1000 | 100, forceNewConnection?: boolean): WebSocket;
258
+ /**
259
+ * Subscribe to a spot user data stream. Use REST client to generate and persist listen key.
260
+ * Supports spot, margin & isolated margin listen keys.
261
+ */
262
+ subscribeSpotUserDataStreamWithListenKey(listenKey: string, forceNewConnection?: boolean, isReconnecting?: boolean): WebSocket | undefined;
263
+ /**
264
+ * Subscribe to spot user data stream - listen key is automaticallyr generated. Calling multiple times only opens one connection.
265
+ */
266
+ subscribeSpotUserDataStream(forceNewConnection?: boolean, isReconnecting?: boolean): Promise<WebSocket | undefined>;
267
+ /**
268
+ * Subscribe to margin user data stream - listen key is automatically generated.
269
+ */
270
+ subscribeMarginUserDataStream(forceNewConnection?: boolean, isReconnecting?: boolean): Promise<WebSocket>;
271
+ /**
272
+ * Subscribe to isolated margin user data stream - listen key is automatically generated.
273
+ */
274
+ subscribeIsolatedMarginUserDataStream(symbol: string, forceNewConnection?: boolean, isReconnecting?: boolean): Promise<WebSocket>;
275
+ /**
276
+ * --------------------------
277
+ * End of SPOT market websocket streams
278
+ * --------------------------
279
+ **/
280
+ /**
281
+ * Subscribe to USD-M Futures user data stream - listen key is automatically generated.
282
+ */
283
+ subscribeUsdFuturesUserDataStream(isTestnet?: boolean, forceNewConnection?: boolean, isReconnecting?: boolean): Promise<WebSocket>;
284
+ /**
285
+ * Subscribe to COIN-M Futures user data stream - listen key is automatically generated.
286
+ */
287
+ subscribeCoinFuturesUserDataStream(isTestnet?: boolean, forceNewConnection?: boolean, isReconnecting?: boolean): Promise<WebSocket>;
288
+ }