binance 3.0.0-beta.3 → 3.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/lib/coinm-client.d.ts +46 -16
- package/lib/coinm-client.js +4 -4
- package/lib/coinm-client.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/main-client.d.ts +64 -15
- package/lib/main-client.js +41 -13
- package/lib/main-client.js.map +1 -1
- package/lib/portfolio-client.js.map +1 -1
- package/lib/types/coin.d.ts +1 -0
- package/lib/types/futures.d.ts +5 -4
- package/lib/types/futures.js.map +1 -1
- package/lib/types/shared.d.ts +6 -12
- package/lib/types/spot.d.ts +126 -8
- package/lib/types/spot.js.map +1 -1
- package/lib/types/websockets/ws-api-requests.d.ts +429 -2
- package/lib/types/websockets/ws-api-responses.d.ts +564 -0
- package/lib/types/websockets/ws-api.d.ts +149 -55
- package/lib/types/websockets/ws-api.js +46 -3
- package/lib/types/websockets/ws-api.js.map +1 -1
- package/lib/types/websockets/ws-events-formatted.d.ts +2 -2
- package/lib/types/websockets/ws-events-raw.d.ts +2 -2
- package/lib/types/websockets/ws-general.d.ts +4 -19
- package/lib/usdm-client.d.ts +41 -18
- package/lib/usdm-client.js +5 -8
- package/lib/usdm-client.js.map +1 -1
- package/lib/util/BaseWSClient.d.ts +2 -2
- package/lib/util/BaseWSClient.js +19 -23
- package/lib/util/BaseWSClient.js.map +1 -1
- package/lib/util/beautifier-maps.d.ts +11 -0
- package/lib/util/beautifier-maps.js +20 -0
- package/lib/util/beautifier-maps.js.map +1 -1
- package/lib/util/beautifier.js +1 -1
- package/lib/util/beautifier.js.map +1 -1
- package/lib/util/browser-support.d.ts +1 -1
- package/lib/util/browser-support.js +1 -0
- package/lib/util/browser-support.js.map +1 -1
- package/lib/util/requestUtils.d.ts +2 -2
- package/lib/util/requestUtils.js +22 -22
- package/lib/util/requestUtils.js.map +1 -1
- package/lib/util/rounding.d.ts +8 -0
- package/lib/util/rounding.js +41 -0
- package/lib/util/rounding.js.map +1 -0
- package/lib/util/typeGuards.d.ts +4 -2
- package/lib/util/typeGuards.js +33 -0
- package/lib/util/typeGuards.js.map +1 -1
- package/lib/util/webCryptoAPI.js +1 -0
- package/lib/util/webCryptoAPI.js.map +1 -1
- package/lib/util/websockets/WsStore.js +1 -1
- package/lib/util/websockets/WsStore.js.map +1 -1
- package/lib/util/websockets/rest-client-cache.d.ts +2 -2
- package/lib/util/websockets/rest-client-cache.js +6 -6
- package/lib/util/websockets/rest-client-cache.js.map +1 -1
- package/lib/util/websockets/user-data-stream-manager.js +4 -4
- package/lib/util/websockets/user-data-stream-manager.js.map +1 -1
- package/lib/util/websockets/websocket-util.d.ts +10 -5
- package/lib/util/websockets/websocket-util.js +64 -40
- package/lib/util/websockets/websocket-util.js.map +1 -1
- package/lib/websocket-api-client.d.ts +324 -0
- package/lib/websocket-api-client.js +537 -0
- package/lib/websocket-api-client.js.map +1 -0
- package/lib/websocket-client-legacy.d.ts +2 -2
- package/lib/websocket-client-legacy.js +6 -6
- package/lib/websocket-client-legacy.js.map +1 -1
- package/lib/websocket-client.d.ts +2 -2
- package/lib/websocket-client.js +50 -35
- package/lib/websocket-client.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WebsocketAPIClient = void 0;
|
|
13
|
+
const typeGuards_1 = require("./util/typeGuards");
|
|
14
|
+
const websocket_util_1 = require("./util/websockets/websocket-util");
|
|
15
|
+
const websocket_client_1 = require("./websocket-client");
|
|
16
|
+
function getFuturesMarketWsKey(market) {
|
|
17
|
+
if (market === 'usdm') {
|
|
18
|
+
return websocket_util_1.WS_KEY_MAP.usdmWSAPI;
|
|
19
|
+
}
|
|
20
|
+
return websocket_util_1.WS_KEY_MAP.coinmWSAPI;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* This is a minimal Websocket API wrapper around the WebsocketClient.
|
|
24
|
+
*
|
|
25
|
+
* Some methods support passing in a custom "wsKey". This is a reference to which WS connection should
|
|
26
|
+
* be used to transmit that message. This is only useful if you wish to use an alternative wss
|
|
27
|
+
* domain that is supported by the SDK.
|
|
28
|
+
*
|
|
29
|
+
* Note: To use testnet, don't set the wsKey - use `testnet: true` in
|
|
30
|
+
* the constructor instead.
|
|
31
|
+
*
|
|
32
|
+
* Note: You can also directly use the sendWSAPIRequest() method to make WS API calls, but some
|
|
33
|
+
* may find the below methods slightly more intuitive.
|
|
34
|
+
*
|
|
35
|
+
* Refer to the WS API promises example for a more detailed example on using sendWSAPIRequest() directly:
|
|
36
|
+
* https://github.com/tiagosiebler/binance/blob/wsapi/examples/ws-api-promises.ts#L52-L61
|
|
37
|
+
*/
|
|
38
|
+
class WebsocketAPIClient extends websocket_client_1.WebsocketClient {
|
|
39
|
+
constructor(options, logger) {
|
|
40
|
+
super(options, logger);
|
|
41
|
+
/**
|
|
42
|
+
* Minimal state store around automating sticky "userDataStream.subscribe" sessions
|
|
43
|
+
*/
|
|
44
|
+
this.subscribedUserDataStreamState = {};
|
|
45
|
+
this.wsAPIClientOptions = Object.assign({ onReconnectResubscribeUserDataStream: false, resubscribeUserDataStreamDelaySeconds: 2 }, this.options);
|
|
46
|
+
this.on('reconnected', ({ wsKey }) => {
|
|
47
|
+
var _a;
|
|
48
|
+
// Delay existing timer, if exists
|
|
49
|
+
if (this.wsAPIClientOptions.onReconnectResubscribeUserDataStream &&
|
|
50
|
+
(0, typeGuards_1.isWSAPIWsKey)(wsKey) &&
|
|
51
|
+
this.subscribedUserDataStreamState[wsKey]) {
|
|
52
|
+
if ((_a = this.subscribedUserDataStreamState[wsKey]) === null || _a === void 0 ? void 0 : _a.respawnTimeout) {
|
|
53
|
+
clearTimeout(this.subscribedUserDataStreamState[wsKey].respawnTimeout);
|
|
54
|
+
delete this.subscribedUserDataStreamState[wsKey].respawnTimeout;
|
|
55
|
+
this.logger.error('tryResubscribeUserDataStream(): Respawn timer already active while trying to queue respawn...delaying existing timer further...', Object.assign(Object.assign({}, websocket_util_1.WS_LOGGER_CATEGORY), { wsKey }));
|
|
56
|
+
}
|
|
57
|
+
this.logger.error('tryResubscribeUserDataStream(): queued resubscribe for wsKey user data stream', Object.assign(Object.assign({}, websocket_util_1.WS_LOGGER_CATEGORY), { wsKey }));
|
|
58
|
+
// Queue resubscribe workflow
|
|
59
|
+
this.subscribedUserDataStreamState[wsKey].respawnTimeout = setTimeout(() => {
|
|
60
|
+
this.tryResubscribeUserDataStream(wsKey);
|
|
61
|
+
}, 1000 * this.wsAPIClientOptions.resubscribeUserDataStreamDelaySeconds);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
tryResubscribeUserDataStream(wsKey) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
var _a;
|
|
69
|
+
const subscribeState = this.getSubscribedUserDataStreamState(wsKey);
|
|
70
|
+
const respawnDelayInSeconds = this.wsAPIClientOptions.resubscribeUserDataStreamDelaySeconds;
|
|
71
|
+
this.logger.error('tryResubscribeUserDataStream(): resubscribing to user data stream....', Object.assign(Object.assign({}, websocket_util_1.WS_LOGGER_CATEGORY), { wsKey }));
|
|
72
|
+
try {
|
|
73
|
+
if ((_a = this.subscribedUserDataStreamState[wsKey]) === null || _a === void 0 ? void 0 : _a.respawnTimeout) {
|
|
74
|
+
clearTimeout(this.subscribedUserDataStreamState[wsKey].respawnTimeout);
|
|
75
|
+
delete this.subscribedUserDataStreamState[wsKey].respawnTimeout;
|
|
76
|
+
}
|
|
77
|
+
subscribeState.subscribeAttempt++;
|
|
78
|
+
yield this.requestSubscribeUserDataStream(wsKey);
|
|
79
|
+
this.subscribedUserDataStreamState[wsKey] = Object.assign(Object.assign({}, subscribeState), { subscribedAt: new Date(), subscribeAttempt: 0 });
|
|
80
|
+
this.logger.info('tryResubscribeUserDataStream()->ok', Object.assign(Object.assign(Object.assign({}, websocket_util_1.WS_LOGGER_CATEGORY), subscribeState), { wsKey }));
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
this.logger.error('tryResubscribeUserDataStream() exception - retry after timeout', Object.assign(Object.assign({}, websocket_util_1.WS_LOGGER_CATEGORY), { wsKey, exception: e, subscribeState }));
|
|
84
|
+
subscribeState.respawnTimeout = setTimeout(() => {
|
|
85
|
+
this.tryResubscribeUserDataStream(wsKey);
|
|
86
|
+
}, 1000 * respawnDelayInSeconds);
|
|
87
|
+
this.subscribedUserDataStreamState[wsKey] = Object.assign({}, subscribeState);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getSubscribedUserDataStreamState(wsKey) {
|
|
92
|
+
const subscribedState = this.subscribedUserDataStreamState[wsKey] || {
|
|
93
|
+
subscribedAt: new Date(),
|
|
94
|
+
subscribeAttempt: 0,
|
|
95
|
+
};
|
|
96
|
+
return subscribedState;
|
|
97
|
+
}
|
|
98
|
+
/*
|
|
99
|
+
*
|
|
100
|
+
* SPOT - General requests
|
|
101
|
+
*
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* Test connectivity to the WebSocket API
|
|
105
|
+
*/
|
|
106
|
+
testSpotConnectivity(wsKey) {
|
|
107
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'ping');
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Test connectivity to the WebSocket API and get the current server time
|
|
111
|
+
*/
|
|
112
|
+
getSpotServerTime(wsKey) {
|
|
113
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'time');
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Query current exchange trading rules, rate limits, and symbol information
|
|
117
|
+
*/
|
|
118
|
+
getSpotExchangeInfo(params, wsKey) {
|
|
119
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'exchangeInfo', params);
|
|
120
|
+
}
|
|
121
|
+
getSpotSessionStatus(wsKey) {
|
|
122
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'session.status');
|
|
123
|
+
}
|
|
124
|
+
/*
|
|
125
|
+
*
|
|
126
|
+
* SPOT - Market data requests
|
|
127
|
+
*
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Get current order book
|
|
131
|
+
* Note: If you need to continuously monitor order book updates, consider using WebSocket Streams
|
|
132
|
+
*/
|
|
133
|
+
getSpotOrderBook(params, wsKey) {
|
|
134
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'depth', params);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get recent trades
|
|
138
|
+
* Note: If you need access to real-time trading activity, consider using WebSocket Streams
|
|
139
|
+
*/
|
|
140
|
+
getSpotRecentTrades(params, wsKey) {
|
|
141
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'trades.recent', params);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get historical trades
|
|
145
|
+
* Note: If fromId is not specified, the most recent trades are returned
|
|
146
|
+
*/
|
|
147
|
+
getSpotHistoricalTrades(params, wsKey) {
|
|
148
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'trades.historical', params);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get aggregate trades
|
|
152
|
+
* Note: An aggregate trade represents one or more individual trades that fill at the same time
|
|
153
|
+
*/
|
|
154
|
+
getSpotAggregateTrades(params, wsKey) {
|
|
155
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'trades.aggregate', params);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get klines (candlestick bars)
|
|
159
|
+
* Note: If you need access to real-time kline updates, consider using WebSocket Streams
|
|
160
|
+
*/
|
|
161
|
+
getSpotKlines(params, wsKey) {
|
|
162
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'klines', params);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get klines (candlestick bars) optimized for presentation
|
|
166
|
+
* Note: This request is similar to klines, having the same parameters and response
|
|
167
|
+
*/
|
|
168
|
+
getSpotUIKlines(params, wsKey) {
|
|
169
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'uiKlines', params);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get current average price for a symbol
|
|
173
|
+
*/
|
|
174
|
+
getSpotAveragePrice(params, wsKey) {
|
|
175
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'avgPrice', params);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get 24-hour rolling window price change statistics
|
|
179
|
+
* Note: If you need to continuously monitor trading statistics, consider using WebSocket Streams
|
|
180
|
+
*/
|
|
181
|
+
getSpot24hrTicker(params, wsKey) {
|
|
182
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'ticker.24hr', params);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Get price change statistics for a trading day
|
|
186
|
+
*/
|
|
187
|
+
getSpotTradingDayTicker(params, wsKey) {
|
|
188
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'ticker.tradingDay', params);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get rolling window price change statistics with a custom window
|
|
192
|
+
* Note: Window size precision is limited to 1 minute
|
|
193
|
+
*/
|
|
194
|
+
getSpotTicker(params, wsKey) {
|
|
195
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'ticker', params);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get the latest market price for a symbol
|
|
199
|
+
* Note: If you need access to real-time price updates, consider using WebSocket Streams
|
|
200
|
+
*/
|
|
201
|
+
getSpotSymbolPriceTicker(params, wsKey) {
|
|
202
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'ticker.price', params);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get the current best price and quantity on the order book
|
|
206
|
+
* Note: If you need access to real-time order book ticker updates, consider using WebSocket Streams
|
|
207
|
+
*/
|
|
208
|
+
getSpotSymbolOrderBookTicker(params, wsKey) {
|
|
209
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'ticker.book', params);
|
|
210
|
+
}
|
|
211
|
+
/*
|
|
212
|
+
*
|
|
213
|
+
* SPOT - Trading requests
|
|
214
|
+
*
|
|
215
|
+
*/
|
|
216
|
+
/**
|
|
217
|
+
* Submit a spot order
|
|
218
|
+
*/
|
|
219
|
+
submitNewSpotOrder(params, wsKey) {
|
|
220
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'order.place', params);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Test order placement
|
|
224
|
+
* Note: Validates new order parameters and verifies your signature but does not send the order into the matching engine
|
|
225
|
+
*/
|
|
226
|
+
testSpotOrder(params, wsKey) {
|
|
227
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'order.test', params);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Check execution status of an order
|
|
231
|
+
* Note: If both orderId and origClientOrderId parameters are specified, only orderId is used
|
|
232
|
+
*/
|
|
233
|
+
getSpotOrderStatus(params, wsKey) {
|
|
234
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'order.status', params);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Cancel an active order
|
|
238
|
+
* Note: If both orderId and origClientOrderId parameters are specified, only orderId is used
|
|
239
|
+
*/
|
|
240
|
+
cancelSpotOrder(params, wsKey) {
|
|
241
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'order.cancel', params);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Cancel an existing order and immediately place a new order
|
|
245
|
+
* Note: If both cancelOrderId and cancelOrigClientOrderId parameters are specified, only cancelOrderId is used
|
|
246
|
+
*/
|
|
247
|
+
cancelReplaceSpotOrder(params, wsKey) {
|
|
248
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'order.cancelReplace', params);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Query execution status of all open orders
|
|
252
|
+
* Note: If you need to continuously monitor order status updates, consider using WebSocket Streams
|
|
253
|
+
*/
|
|
254
|
+
getSpotOpenOrders(params, wsKey) {
|
|
255
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'openOrders.status', params);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Cancel all open orders on a symbol
|
|
259
|
+
* Note: This includes orders that are part of an order list
|
|
260
|
+
*/
|
|
261
|
+
cancelAllSpotOpenOrders(params, wsKey) {
|
|
262
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'openOrders.cancelAll', params);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Place a new order list
|
|
266
|
+
* Note: This is a deprecated endpoint, consider using placeOCOOrderList instead
|
|
267
|
+
*/
|
|
268
|
+
placeSpotOrderList(params, wsKey) {
|
|
269
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'orderList.place', params);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Place a new OCO (One-Cancels-the-Other) order list
|
|
273
|
+
* Note: Activation of one order immediately cancels the other
|
|
274
|
+
*/
|
|
275
|
+
placeSpotOCOOrderList(params, wsKey) {
|
|
276
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'orderList.place.oco', params);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Place a new OTO (One-Triggers-the-Other) order list
|
|
280
|
+
* Note: The pending order is placed only when the working order is fully filled
|
|
281
|
+
*/
|
|
282
|
+
placeSpotOTOOrderList(params, wsKey) {
|
|
283
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'orderList.place.oto', params);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Place a new OTOCO (One-Triggers-One-Cancels-the-Other) order list
|
|
287
|
+
* Note: The pending orders are placed only when the working order is fully filled
|
|
288
|
+
*/
|
|
289
|
+
placeSpotOTOCOOrderList(params, wsKey) {
|
|
290
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'orderList.place.otoco', params);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Check execution status of an order list
|
|
294
|
+
* Note: If both origClientOrderId and orderListId parameters are specified, only origClientOrderId is used
|
|
295
|
+
*/
|
|
296
|
+
getSpotOrderListStatus(params, wsKey) {
|
|
297
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'orderList.status', params);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Cancel an active order list
|
|
301
|
+
* Note: If both orderListId and listClientOrderId parameters are specified, only orderListId is used
|
|
302
|
+
*/
|
|
303
|
+
cancelSpotOrderList(params, wsKey) {
|
|
304
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'orderList.cancel', params);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Query execution status of all open order lists
|
|
308
|
+
* Note: If you need to continuously monitor order status updates, consider using WebSocket Streams
|
|
309
|
+
*/
|
|
310
|
+
getSpotOpenOrderLists(params, wsKey) {
|
|
311
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'openOrderLists.status', params);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Place a new order using Smart Order Routing (SOR)
|
|
315
|
+
* Note: Only supports LIMIT and MARKET orders. quoteOrderQty is not supported
|
|
316
|
+
*/
|
|
317
|
+
placeSpotSOROrder(params, wsKey) {
|
|
318
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'sor.order.place', params);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Test new order creation and signature/recvWindow using Smart Order Routing (SOR)
|
|
322
|
+
* Note: Creates and validates a new order but does not send it into the matching engine
|
|
323
|
+
*/
|
|
324
|
+
testSpotSOROrder(params, wsKey) {
|
|
325
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'sor.order.test', params);
|
|
326
|
+
}
|
|
327
|
+
/*
|
|
328
|
+
*
|
|
329
|
+
* SPOT - Account requests
|
|
330
|
+
*
|
|
331
|
+
*/
|
|
332
|
+
/**
|
|
333
|
+
* Query information about your account
|
|
334
|
+
* Note: Weight: 20
|
|
335
|
+
*/
|
|
336
|
+
getSpotAccountStatus(params, wsKey) {
|
|
337
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'account.status', params);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Query your current unfilled order count for all intervals
|
|
341
|
+
* Note: Weight: 40
|
|
342
|
+
*/
|
|
343
|
+
getSpotOrderRateLimits(params, wsKey) {
|
|
344
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'account.rateLimits.orders', params);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Query information about all your orders – active, canceled, filled – filtered by time range
|
|
348
|
+
* Note: Weight: 20
|
|
349
|
+
*/
|
|
350
|
+
getSpotAllOrders(params, wsKey) {
|
|
351
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'allOrders', params);
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Query information about all your order lists, filtered by time range
|
|
355
|
+
* Note: Weight: 20
|
|
356
|
+
*/
|
|
357
|
+
getSpotAllOrderLists(params, wsKey) {
|
|
358
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'allOrderLists', params);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Query information about all your trades, filtered by time range
|
|
362
|
+
* Note: Weight: 20
|
|
363
|
+
*/
|
|
364
|
+
getSpotMyTrades(params, wsKey) {
|
|
365
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'myTrades', params);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Displays the list of orders that were expired due to STP
|
|
369
|
+
* Note: Weight varies based on query type (2-20)
|
|
370
|
+
*/
|
|
371
|
+
getSpotPreventedMatches(params, wsKey) {
|
|
372
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'myPreventedMatches', params);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Retrieves allocations resulting from SOR order placement
|
|
376
|
+
* Note: Weight: 20
|
|
377
|
+
*/
|
|
378
|
+
getSpotAllocations(params, wsKey) {
|
|
379
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'myAllocations', params);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Get current account commission rates
|
|
383
|
+
* Note: Weight: 20
|
|
384
|
+
*/
|
|
385
|
+
getSpotAccountCommission(params, wsKey) {
|
|
386
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'account.commission', params);
|
|
387
|
+
}
|
|
388
|
+
/*
|
|
389
|
+
*
|
|
390
|
+
* FUTURES - Market data requests
|
|
391
|
+
*
|
|
392
|
+
*/
|
|
393
|
+
/**
|
|
394
|
+
* Get current order book for futures
|
|
395
|
+
* Note: If you need to continuously monitor order book updates, consider using WebSocket Streams
|
|
396
|
+
*/
|
|
397
|
+
getFuturesOrderBook(params) {
|
|
398
|
+
return this.sendWSAPIRequest(websocket_util_1.WS_KEY_MAP.usdmWSAPI, 'depth', params);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Get latest price for a futures symbol or symbols
|
|
402
|
+
* Note: If symbol is not provided, prices for all symbols will be returned
|
|
403
|
+
*/
|
|
404
|
+
getFuturesSymbolPriceTicker(params) {
|
|
405
|
+
return this.sendWSAPIRequest(websocket_util_1.WS_KEY_MAP.usdmWSAPI, 'ticker.price', params);
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Get best price/qty on the order book for a futures symbol or symbols
|
|
409
|
+
* Note: If symbol is not provided, bookTickers for all symbols will be returned
|
|
410
|
+
*/
|
|
411
|
+
getFuturesSymbolOrderBookTicker(params) {
|
|
412
|
+
return this.sendWSAPIRequest(websocket_util_1.WS_KEY_MAP.usdmWSAPI, 'ticker.book', params);
|
|
413
|
+
}
|
|
414
|
+
/*
|
|
415
|
+
*
|
|
416
|
+
* FUTURES - Trading requests
|
|
417
|
+
*
|
|
418
|
+
*/
|
|
419
|
+
/**
|
|
420
|
+
* Submit a futures order
|
|
421
|
+
*
|
|
422
|
+
* This endpoint is used for both USDM and COINM futures.
|
|
423
|
+
*/
|
|
424
|
+
submitNewFuturesOrder(market, params) {
|
|
425
|
+
return this.sendWSAPIRequest(getFuturesMarketWsKey(market), 'order.place', params);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Modify an existing futures order
|
|
429
|
+
*
|
|
430
|
+
* This endpoint is used for both USDM and COINM futures.
|
|
431
|
+
*/
|
|
432
|
+
modifyFuturesOrder(market, params) {
|
|
433
|
+
return this.sendWSAPIRequest(getFuturesMarketWsKey(market), 'order.modify', params);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Cancel a futures order
|
|
437
|
+
*
|
|
438
|
+
* This endpoint is used for both USDM and COINM futures.
|
|
439
|
+
*/
|
|
440
|
+
cancelFuturesOrder(market, params) {
|
|
441
|
+
return this.sendWSAPIRequest(getFuturesMarketWsKey(market), 'order.cancel', params);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Query futures order status
|
|
445
|
+
*
|
|
446
|
+
* This endpoint is used for both USDM and COINM futures.
|
|
447
|
+
*/
|
|
448
|
+
getFuturesOrderStatus(market, params) {
|
|
449
|
+
return this.sendWSAPIRequest(getFuturesMarketWsKey(market), 'order.status', params);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Get current position information (V2)
|
|
453
|
+
* Note: Only symbols that have positions or open orders will be returned
|
|
454
|
+
*/
|
|
455
|
+
getFuturesPositionV2(params) {
|
|
456
|
+
return this.sendWSAPIRequest(websocket_util_1.WS_KEY_MAP.usdmWSAPI, 'v2/account.position', params);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Get current position information
|
|
460
|
+
* Note: Only symbols that have positions or open orders will be returned
|
|
461
|
+
*
|
|
462
|
+
* This endpoint is used for both USDM and COINM futures.
|
|
463
|
+
*/
|
|
464
|
+
getFuturesPosition(market, params) {
|
|
465
|
+
return this.sendWSAPIRequest(getFuturesMarketWsKey(market), 'account.position', params);
|
|
466
|
+
}
|
|
467
|
+
/*
|
|
468
|
+
*
|
|
469
|
+
* FUTURES - Account requests
|
|
470
|
+
*
|
|
471
|
+
*/
|
|
472
|
+
/**
|
|
473
|
+
* Get account balance information (V2)
|
|
474
|
+
* Note: Returns balance information for all assets
|
|
475
|
+
*/
|
|
476
|
+
getFuturesAccountBalanceV2(params) {
|
|
477
|
+
return this.sendWSAPIRequest(websocket_util_1.WS_KEY_MAP.usdmWSAPI, 'v2/account.balance', params);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Get account balance information
|
|
481
|
+
* Note: Returns balance information for all assets
|
|
482
|
+
*
|
|
483
|
+
* This endpoint is used for both USDM and COINM futures.
|
|
484
|
+
*/
|
|
485
|
+
getFuturesAccountBalance(market, params) {
|
|
486
|
+
return this.sendWSAPIRequest(getFuturesMarketWsKey(market), 'account.balance', params);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Get account information (V2)
|
|
490
|
+
* Note: Returns detailed account information including positions and assets
|
|
491
|
+
*/
|
|
492
|
+
getFuturesAccountStatusV2(params) {
|
|
493
|
+
return this.sendWSAPIRequest(websocket_util_1.WS_KEY_MAP.usdmWSAPI, 'v2/account.status', params);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Get account information
|
|
497
|
+
* Note: Returns detailed account information including positions and assets
|
|
498
|
+
*
|
|
499
|
+
* This endpoint is used for both USDM and COINM futures.
|
|
500
|
+
*/
|
|
501
|
+
getFuturesAccountStatus(market, params) {
|
|
502
|
+
return this.sendWSAPIRequest(getFuturesMarketWsKey(market), 'account.status', params);
|
|
503
|
+
}
|
|
504
|
+
/*
|
|
505
|
+
*
|
|
506
|
+
* User data stream requests
|
|
507
|
+
*
|
|
508
|
+
*/
|
|
509
|
+
startSpotUserDataStream(params, wsKey) {
|
|
510
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'userDataStream.start', params);
|
|
511
|
+
}
|
|
512
|
+
pingSpotUserDataStream(params, wsKey) {
|
|
513
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'userDataStream.ping', params);
|
|
514
|
+
}
|
|
515
|
+
stopSpotUserDataStream(params, wsKey) {
|
|
516
|
+
return this.sendWSAPIRequest(wsKey || websocket_util_1.WS_KEY_MAP.mainWSAPI, 'userDataStream.stop', params);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Request user data stream subscription on the currently authenticated connection
|
|
520
|
+
*/
|
|
521
|
+
requestSubscribeUserDataStream(wsKey) {
|
|
522
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
523
|
+
const res = yield this.sendWSAPIRequest(wsKey, 'userDataStream.subscribe');
|
|
524
|
+
this.subscribedUserDataStreamState[wsKey] = {
|
|
525
|
+
subscribedAt: new Date(),
|
|
526
|
+
subscribeAttempt: 0,
|
|
527
|
+
};
|
|
528
|
+
return res;
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
requestUnsubscribeUserDataStream(wsKey) {
|
|
532
|
+
delete this.subscribedUserDataStreamState[wsKey];
|
|
533
|
+
return this.sendWSAPIRequest(wsKey, 'userDataStream.unsubscribe');
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
exports.WebsocketAPIClient = WebsocketAPIClient;
|
|
537
|
+
//# sourceMappingURL=websocket-api-client.js.map
|
|
@@ -0,0 +1 @@
|
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sB;QAEtB,OAAO,IAAI,CAAC,gBAAgB,CAC1B,KAAK,IAAI,2BAAU,CAAC,SAAS,EAC7B,qBAAqB,EACrB,MAAM,CACP,CAAC;IACJ,CAAC;IAED,sBAAsB,CACpB,MAAqC,EACrC,KAAsB;QAEtB,OAAO,IAAI,CAAC,gBAAgB,CAC1B,KAAK,IAAI,2BAAU,CAAC,SAAS,EAC7B,qBAAqB,EACrB,MAAM,CACP,CAAC;IACJ,CAAC;IAED;;OAEG;IACG,8BAA8B,CAClC,KAAiB;;YAEjB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,0BAA0B,CAAC,CAAC;YAE3E,IAAI,CAAC,6BAA6B,CAAC,KAAK,CAAC,GAAG;gBAC1C,YAAY,EAAE,IAAI,IAAI,EAAE;gBACxB,gBAAgB,EAAE,CAAC;aACpB,CAAC;YACF,OAAO,GAAG,CAAC;QACb,CAAC;KAAA;IAED,gCAAgC,CAC9B,KAAiB;QAEjB,OAAO,IAAI,CAAC,6BAA6B,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,4BAA4B,CAAC,CAAC;IACpE,CAAC;CACF;AAjhCD,gDAihCC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import WebSocket from 'isomorphic-ws';
|
|
3
3
|
import { KlineInterval } from './types/shared';
|
|
4
|
+
import { WsFormattedMessage, WsUserDataEvents } from './types/websockets/ws-events-formatted';
|
|
5
|
+
import { WsRawMessage } from './types/websockets/ws-events-raw';
|
|
4
6
|
import { WSClientConfigurableOptions, WsResponse } from './types/websockets/ws-general';
|
|
5
7
|
import { DefaultLogger } from './util/logger';
|
|
6
8
|
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
9
|
export declare interface WebsocketClientV1 {
|
|
10
10
|
on(event: 'reply', listener: (event: WsResponse) => void): this;
|
|
11
11
|
on(event: 'message', listener: (event: WsRawMessage) => void): this;
|
|
@@ -67,7 +67,7 @@ class WebsocketClientV1 extends events_1.EventEmitter {
|
|
|
67
67
|
this.listenKeyStateCache = new listen_key_state_cache_1.ListenKeyStateCache(this.logger);
|
|
68
68
|
this.options = Object.assign({
|
|
69
69
|
// Some defaults:
|
|
70
|
-
|
|
70
|
+
pongTimeout: 7500, pingInterval: 10000, reconnectTimeout: 500, recvWindow: 5000,
|
|
71
71
|
// Automatically send an authentication op/request after a connection opens, for private connections.
|
|
72
72
|
authPrivateConnectionsOnConnect: false,
|
|
73
73
|
// Individual requests require a signature
|
|
@@ -77,7 +77,7 @@ class WebsocketClientV1 extends events_1.EventEmitter {
|
|
|
77
77
|
this.on('error', () => { });
|
|
78
78
|
}
|
|
79
79
|
getRestClientOptions() {
|
|
80
|
-
return Object.assign(Object.assign(Object.assign({}, this.options), this.options.restOptions), { api_key: this.options.api_key, api_secret: this.options.api_secret });
|
|
80
|
+
return Object.assign(Object.assign(Object.assign({}, this.options), this.options.restOptions), { useTestnet: this.options.useTestnet, api_key: this.options.api_key, api_secret: this.options.api_secret });
|
|
81
81
|
}
|
|
82
82
|
connectToWsUrl(url, wsKey, forceNewConnection) {
|
|
83
83
|
const wsRefKey = wsKey || url;
|
|
@@ -508,11 +508,11 @@ class WebsocketClientV1 extends events_1.EventEmitter {
|
|
|
508
508
|
.keepAliveFuturesUserDataListenKey();
|
|
509
509
|
case 'usdmTestnet':
|
|
510
510
|
return this.restClientCache
|
|
511
|
-
.getUSDMRestClient(this.getRestClientOptions(), this.options.requestOptions
|
|
511
|
+
.getUSDMRestClient(Object.assign(Object.assign({}, this.getRestClientOptions()), { useTestnet: isTestnet }), this.options.requestOptions)
|
|
512
512
|
.keepAliveFuturesUserDataListenKey();
|
|
513
513
|
case 'coinmTestnet':
|
|
514
514
|
return this.restClientCache
|
|
515
|
-
.getCOINMRestClient(this.getRestClientOptions(), this.options.requestOptions
|
|
515
|
+
.getCOINMRestClient(Object.assign(Object.assign({}, this.getRestClientOptions()), { useTestnet: isTestnet }), this.options.requestOptions)
|
|
516
516
|
.keepAliveFuturesUserDataListenKey();
|
|
517
517
|
case 'portfoliom':
|
|
518
518
|
return this.restClientCache
|
|
@@ -1053,7 +1053,7 @@ class WebsocketClientV1 extends events_1.EventEmitter {
|
|
|
1053
1053
|
subscribeUsdFuturesUserDataStream(isTestnet, forceNewConnection, isReconnecting) {
|
|
1054
1054
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1055
1055
|
try {
|
|
1056
|
-
const restClient = this.restClientCache.getUSDMRestClient(this.getRestClientOptions(), this.options.requestOptions
|
|
1056
|
+
const restClient = this.restClientCache.getUSDMRestClient(Object.assign(Object.assign({}, this.getRestClientOptions()), { useTestnet: isTestnet }), this.options.requestOptions);
|
|
1057
1057
|
const { listenKey } = yield restClient.getFuturesUserDataListenKey();
|
|
1058
1058
|
const market = isTestnet ? 'usdmTestnet' : 'usdm';
|
|
1059
1059
|
const wsKey = (0, websocket_util_1.getLegacyWsStoreKeyWithContext)(market, 'userData', undefined, listenKey);
|
|
@@ -1084,7 +1084,7 @@ class WebsocketClientV1 extends events_1.EventEmitter {
|
|
|
1084
1084
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1085
1085
|
try {
|
|
1086
1086
|
const { listenKey } = yield this.restClientCache
|
|
1087
|
-
.getCOINMRestClient(this.getRestClientOptions(), this.options.requestOptions
|
|
1087
|
+
.getCOINMRestClient(Object.assign(Object.assign({}, this.getRestClientOptions()), { useTestnet: isTestnet }), this.options.requestOptions)
|
|
1088
1088
|
.getFuturesUserDataListenKey();
|
|
1089
1089
|
const market = isTestnet ? 'coinmTestnet' : 'coinm';
|
|
1090
1090
|
const wsKey = (0, websocket_util_1.getLegacyWsStoreKeyWithContext)(market, 'userData', undefined, listenKey);
|