ccxt 4.3.33 → 4.3.35
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/README.md +3 -3
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/alpaca.js +1 -1
- package/dist/cjs/src/base/Exchange.js +37 -0
- package/dist/cjs/src/binance.js +1 -0
- package/dist/cjs/src/bitmart.js +2 -9
- package/dist/cjs/src/coinbase.js +169 -55
- package/dist/cjs/src/coinex.js +26 -19
- package/dist/cjs/src/kraken.js +3 -1
- package/dist/cjs/src/pro/binance.js +352 -0
- package/dist/cjs/src/pro/bitget.js +31 -1
- package/dist/cjs/src/pro/bitmex.js +108 -0
- package/dist/cjs/src/pro/bybit.js +85 -0
- package/dist/cjs/src/pro/gate.js +183 -0
- package/dist/cjs/src/pro/kucoinfutures.js +4 -0
- package/dist/cjs/src/pro/okx.js +258 -0
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/abstract/binance.d.ts +1 -0
- package/js/src/abstract/binancecoinm.d.ts +1 -0
- package/js/src/abstract/binanceus.d.ts +1 -0
- package/js/src/abstract/binanceusdm.d.ts +1 -0
- package/js/src/ace.d.ts +3 -3
- package/js/src/alpaca.d.ts +3 -3
- package/js/src/alpaca.js +1 -1
- package/js/src/ascendex.d.ts +3 -3
- package/js/src/base/Exchange.d.ts +14 -3
- package/js/src/base/Exchange.js +37 -0
- package/js/src/base/types.d.ts +1 -0
- package/js/src/bigone.d.ts +3 -3
- package/js/src/binance.d.ts +4 -4
- package/js/src/binance.js +1 -0
- package/js/src/bingx.d.ts +3 -3
- package/js/src/bit2c.d.ts +2 -2
- package/js/src/bitbank.d.ts +2 -2
- package/js/src/bitbns.d.ts +2 -2
- package/js/src/bitfinex.d.ts +3 -3
- package/js/src/bitfinex2.d.ts +1 -1
- package/js/src/bitflyer.d.ts +2 -2
- package/js/src/bitget.d.ts +4 -4
- package/js/src/bithumb.d.ts +2 -2
- package/js/src/bitmart.d.ts +3 -3
- package/js/src/bitmart.js +2 -9
- package/js/src/bitmex.d.ts +4 -4
- package/js/src/bitopro.d.ts +4 -4
- package/js/src/bitrue.d.ts +3 -3
- package/js/src/bitso.d.ts +3 -3
- package/js/src/bitstamp.d.ts +3 -3
- package/js/src/bitteam.d.ts +4 -4
- package/js/src/bitvavo.d.ts +3 -3
- package/js/src/blockchaincom.d.ts +2 -2
- package/js/src/blofin.d.ts +4 -4
- package/js/src/btcalpha.d.ts +4 -4
- package/js/src/btcbox.d.ts +2 -2
- package/js/src/btcmarkets.d.ts +4 -4
- package/js/src/btcturk.d.ts +2 -2
- package/js/src/bybit.d.ts +3 -3
- package/js/src/cex.d.ts +2 -2
- package/js/src/coinbase.d.ts +4 -3
- package/js/src/coinbase.js +169 -55
- package/js/src/coinbaseexchange.d.ts +2 -2
- package/js/src/coinbaseinternational.d.ts +4 -4
- package/js/src/coincheck.d.ts +3 -3
- package/js/src/coinex.d.ts +3 -3
- package/js/src/coinex.js +26 -19
- package/js/src/coinlist.d.ts +3 -3
- package/js/src/coinmate.d.ts +3 -3
- package/js/src/coinmetro.d.ts +3 -3
- package/js/src/coinone.d.ts +2 -2
- package/js/src/coinsph.d.ts +3 -3
- package/js/src/cryptocom.d.ts +2 -2
- package/js/src/currencycom.d.ts +3 -3
- package/js/src/delta.d.ts +2 -2
- package/js/src/deribit.d.ts +3 -3
- package/js/src/digifinex.d.ts +3 -3
- package/js/src/exmo.d.ts +3 -3
- package/js/src/gate.d.ts +3 -3
- package/js/src/gemini.d.ts +3 -3
- package/js/src/hitbtc.d.ts +3 -3
- package/js/src/hollaex.d.ts +2 -2
- package/js/src/htx.d.ts +3 -3
- package/js/src/huobijp.d.ts +3 -3
- package/js/src/hyperliquid.d.ts +3 -3
- package/js/src/idex.d.ts +3 -3
- package/js/src/indodax.d.ts +3 -3
- package/js/src/kraken.d.ts +3 -3
- package/js/src/kraken.js +3 -1
- package/js/src/krakenfutures.d.ts +2 -2
- package/js/src/kucoin.d.ts +3 -3
- package/js/src/kuna.d.ts +3 -3
- package/js/src/latoken.d.ts +3 -3
- package/js/src/lbank.d.ts +2 -2
- package/js/src/luno.d.ts +2 -2
- package/js/src/lykke.d.ts +2 -2
- package/js/src/mercado.d.ts +2 -2
- package/js/src/mexc.d.ts +2 -2
- package/js/src/ndax.d.ts +3 -3
- package/js/src/novadax.d.ts +4 -4
- package/js/src/oceanex.d.ts +3 -3
- package/js/src/okcoin.d.ts +4 -4
- package/js/src/okx.d.ts +4 -4
- package/js/src/onetrading.d.ts +3 -3
- package/js/src/p2b.d.ts +3 -3
- package/js/src/paymium.d.ts +2 -2
- package/js/src/phemex.d.ts +5 -5
- package/js/src/poloniex.d.ts +4 -4
- package/js/src/poloniexfutures.d.ts +3 -3
- package/js/src/pro/binance.d.ts +9 -2
- package/js/src/pro/binance.js +352 -0
- package/js/src/pro/bitget.js +31 -1
- package/js/src/pro/bitmex.d.ts +4 -1
- package/js/src/pro/bitmex.js +108 -0
- package/js/src/pro/bybit.d.ts +4 -1
- package/js/src/pro/bybit.js +85 -0
- package/js/src/pro/gate.d.ts +5 -1
- package/js/src/pro/gate.js +183 -0
- package/js/src/pro/kucoinfutures.js +4 -0
- package/js/src/pro/okx.d.ts +8 -1
- package/js/src/pro/okx.js +258 -0
- package/js/src/probit.d.ts +4 -4
- package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.d.ts +1 -1
- package/js/src/timex.d.ts +3 -3
- package/js/src/tokocrypto.d.ts +2 -2
- package/js/src/tradeogre.d.ts +2 -2
- package/js/src/upbit.d.ts +4 -4
- package/js/src/wavesexchange.d.ts +2 -2
- package/js/src/wazirx.d.ts +4 -4
- package/js/src/whitebit.d.ts +4 -4
- package/js/src/woo.d.ts +4 -4
- package/js/src/woofipro.d.ts +4 -4
- package/js/src/yobit.d.ts +2 -2
- package/js/src/zaif.d.ts +3 -3
- package/js/src/zonda.d.ts +2 -2
- package/package.json +1 -1
|
@@ -17,6 +17,10 @@ class binance extends binance$1 {
|
|
|
17
17
|
'has': {
|
|
18
18
|
'ws': true,
|
|
19
19
|
'watchBalance': true,
|
|
20
|
+
'watchLiquidations': true,
|
|
21
|
+
'watchLiquidationsForSymbols': true,
|
|
22
|
+
'watchMyLiquidations': true,
|
|
23
|
+
'watchMyLiquidationsForSymbols': true,
|
|
20
24
|
'watchBidsAsks': true,
|
|
21
25
|
'watchMyTrades': true,
|
|
22
26
|
'watchOHLCV': true,
|
|
@@ -101,6 +105,8 @@ class binance extends binance$1 {
|
|
|
101
105
|
// get updates every 1000ms or 100ms
|
|
102
106
|
// or every 0ms in real-time for futures
|
|
103
107
|
'watchOrderBookRate': 100,
|
|
108
|
+
'liquidationsLimit': 1000,
|
|
109
|
+
'myLiquidationsLimit': 1000,
|
|
104
110
|
'tradesLimit': 1000,
|
|
105
111
|
'ordersLimit': 1000,
|
|
106
112
|
'OHLCVLimit': 1000,
|
|
@@ -125,6 +131,9 @@ class binance extends binance$1 {
|
|
|
125
131
|
'fetchBalanceSnapshot': false,
|
|
126
132
|
'awaitBalanceSnapshot': true, // whether to wait for the balance snapshot before providing updates
|
|
127
133
|
},
|
|
134
|
+
'watchLiquidationsForSymbols': {
|
|
135
|
+
'defaultType': 'swap',
|
|
136
|
+
},
|
|
128
137
|
'watchPositions': {
|
|
129
138
|
'fetchPositionsSnapshot': true,
|
|
130
139
|
'awaitPositionsSnapshot': true, // whether to wait for the positions snapshot before providing updates
|
|
@@ -179,6 +188,347 @@ class binance extends binance$1 {
|
|
|
179
188
|
}
|
|
180
189
|
return stream;
|
|
181
190
|
}
|
|
191
|
+
async watchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
|
|
192
|
+
/**
|
|
193
|
+
* @method
|
|
194
|
+
* @name binance#watchLiquidations
|
|
195
|
+
* @description watch the public liquidations of a trading pair
|
|
196
|
+
* @see https://binance-docs.github.io/apidocs/futures/en/#liquidation-order-streams
|
|
197
|
+
* @see https://binance-docs.github.io/apidocs/delivery/en/#liquidation-order-streams
|
|
198
|
+
* @param {string} symbol unified CCXT market symbol
|
|
199
|
+
* @param {int} [since] the earliest time in ms to fetch liquidations for
|
|
200
|
+
* @param {int} [limit] the maximum number of liquidation structures to retrieve
|
|
201
|
+
* @param {object} [params] exchange specific parameters for the bitmex api endpoint
|
|
202
|
+
* @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
|
|
203
|
+
*/
|
|
204
|
+
return this.watchLiquidationsForSymbols([symbol], since, limit, params);
|
|
205
|
+
}
|
|
206
|
+
async watchLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
207
|
+
/**
|
|
208
|
+
* @method
|
|
209
|
+
* @name binance#watchLiquidationsForSymbols
|
|
210
|
+
* @description watch the public liquidations of a trading pair
|
|
211
|
+
* @see https://binance-docs.github.io/apidocs/futures/en/#all-market-liquidation-order-streams
|
|
212
|
+
* @see https://binance-docs.github.io/apidocs/delivery/en/#all-market-liquidation-order-streams
|
|
213
|
+
* @param {string} symbol unified CCXT market symbol
|
|
214
|
+
* @param {int} [since] the earliest time in ms to fetch liquidations for
|
|
215
|
+
* @param {int} [limit] the maximum number of liquidation structures to retrieve
|
|
216
|
+
* @param {object} [params] exchange specific parameters for the bitmex api endpoint
|
|
217
|
+
* @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
|
|
218
|
+
*/
|
|
219
|
+
await this.loadMarkets();
|
|
220
|
+
const subscriptionHashes = [];
|
|
221
|
+
const messageHashes = [];
|
|
222
|
+
let streamHash = 'liquidations';
|
|
223
|
+
symbols = this.marketSymbols(symbols, undefined, true, true);
|
|
224
|
+
if (this.isEmpty(symbols)) {
|
|
225
|
+
subscriptionHashes.push('!' + 'forceOrder@arr');
|
|
226
|
+
messageHashes.push('liquidations');
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
230
|
+
const market = this.market(symbols[i]);
|
|
231
|
+
subscriptionHashes.push(market['id'] + '@forceOrder');
|
|
232
|
+
messageHashes.push('liquidations::' + symbols[i]);
|
|
233
|
+
}
|
|
234
|
+
streamHash += '::' + symbols.join(',');
|
|
235
|
+
}
|
|
236
|
+
const firstMarket = this.getMarketFromSymbols(symbols);
|
|
237
|
+
let type = undefined;
|
|
238
|
+
[type, params] = this.handleMarketTypeAndParams('watchLiquidationsForSymbols', firstMarket, params);
|
|
239
|
+
if (type === 'spot') {
|
|
240
|
+
throw new errors.BadRequest(this.id + 'watchLiquidationsForSymbols is not supported for swap symbols');
|
|
241
|
+
}
|
|
242
|
+
let subType = undefined;
|
|
243
|
+
[subType, params] = this.handleSubTypeAndParams('watchLiquidationsForSymbols', firstMarket, params);
|
|
244
|
+
if (this.isLinear(type, subType)) {
|
|
245
|
+
type = 'future';
|
|
246
|
+
}
|
|
247
|
+
else if (this.isInverse(type, subType)) {
|
|
248
|
+
type = 'delivery';
|
|
249
|
+
}
|
|
250
|
+
const numSubscriptions = subscriptionHashes.length;
|
|
251
|
+
const url = this.urls['api']['ws'][type] + '/' + this.stream(type, streamHash, numSubscriptions);
|
|
252
|
+
const requestId = this.requestId(url);
|
|
253
|
+
const request = {
|
|
254
|
+
'method': 'SUBSCRIBE',
|
|
255
|
+
'params': subscriptionHashes,
|
|
256
|
+
'id': requestId,
|
|
257
|
+
};
|
|
258
|
+
const subscribe = {
|
|
259
|
+
'id': requestId,
|
|
260
|
+
};
|
|
261
|
+
const newLiquidations = await this.watchMultiple(url, messageHashes, this.extend(request, params), subscriptionHashes, subscribe);
|
|
262
|
+
if (this.newUpdates) {
|
|
263
|
+
return newLiquidations;
|
|
264
|
+
}
|
|
265
|
+
return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
|
|
266
|
+
}
|
|
267
|
+
handleLiquidation(client, message) {
|
|
268
|
+
//
|
|
269
|
+
// future
|
|
270
|
+
// {
|
|
271
|
+
// "e":"forceOrder",
|
|
272
|
+
// "E":1698871323061,
|
|
273
|
+
// "o":{
|
|
274
|
+
// "s":"BTCUSDT",
|
|
275
|
+
// "S":"BUY",
|
|
276
|
+
// "o":"LIMIT",
|
|
277
|
+
// "f":"IOC",
|
|
278
|
+
// "q":"1.437",
|
|
279
|
+
// "p":"35100.81",
|
|
280
|
+
// "ap":"34959.70",
|
|
281
|
+
// "X":"FILLED",
|
|
282
|
+
// "l":"1.437",
|
|
283
|
+
// "z":"1.437",
|
|
284
|
+
// "T":1698871323059
|
|
285
|
+
// }
|
|
286
|
+
// }
|
|
287
|
+
// delivery
|
|
288
|
+
// {
|
|
289
|
+
// "e":"forceOrder", // Event Type
|
|
290
|
+
// "E": 1591154240950, // Event Time
|
|
291
|
+
// "o":{
|
|
292
|
+
// "s":"BTCUSD_200925", // Symbol
|
|
293
|
+
// "ps": "BTCUSD", // Pair
|
|
294
|
+
// "S":"SELL", // Side
|
|
295
|
+
// "o":"LIMIT", // Order Type
|
|
296
|
+
// "f":"IOC", // Time in Force
|
|
297
|
+
// "q":"1", // Original Quantity
|
|
298
|
+
// "p":"9425.5", // Price
|
|
299
|
+
// "ap":"9496.5", // Average Price
|
|
300
|
+
// "X":"FILLED", // Order Status
|
|
301
|
+
// "l":"1", // Order Last Filled Quantity
|
|
302
|
+
// "z":"1", // Order Filled Accumulated Quantity
|
|
303
|
+
// "T": 1591154240949, // Order Trade Time
|
|
304
|
+
// }
|
|
305
|
+
// }
|
|
306
|
+
//
|
|
307
|
+
const rawLiquidation = this.safeValue(message, 'o', {});
|
|
308
|
+
const marketId = this.safeString(rawLiquidation, 's');
|
|
309
|
+
const market = this.safeMarket(marketId, undefined, '', 'contract');
|
|
310
|
+
const symbol = market['symbol'];
|
|
311
|
+
const liquidation = this.parseWsLiquidation(rawLiquidation, market);
|
|
312
|
+
let liquidations = this.safeValue(this.liquidations, symbol);
|
|
313
|
+
if (liquidations === undefined) {
|
|
314
|
+
const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
|
|
315
|
+
liquidations = new Cache.ArrayCache(limit);
|
|
316
|
+
}
|
|
317
|
+
liquidations.append(liquidation);
|
|
318
|
+
this.liquidations[symbol] = liquidations;
|
|
319
|
+
client.resolve([liquidation], 'liquidations');
|
|
320
|
+
client.resolve([liquidation], 'liquidations::' + symbol);
|
|
321
|
+
}
|
|
322
|
+
parseWsLiquidation(liquidation, market = undefined) {
|
|
323
|
+
//
|
|
324
|
+
// future
|
|
325
|
+
// {
|
|
326
|
+
// "s":"BTCUSDT",
|
|
327
|
+
// "S":"BUY",
|
|
328
|
+
// "o":"LIMIT",
|
|
329
|
+
// "f":"IOC",
|
|
330
|
+
// "q":"1.437",
|
|
331
|
+
// "p":"35100.81",
|
|
332
|
+
// "ap":"34959.70",
|
|
333
|
+
// "X":"FILLED",
|
|
334
|
+
// "l":"1.437",
|
|
335
|
+
// "z":"1.437",
|
|
336
|
+
// "T":1698871323059
|
|
337
|
+
// }
|
|
338
|
+
// delivery
|
|
339
|
+
// {
|
|
340
|
+
// "s":"BTCUSD_200925", // Symbol
|
|
341
|
+
// "ps": "BTCUSD", // Pair
|
|
342
|
+
// "S":"SELL", // Side
|
|
343
|
+
// "o":"LIMIT", // Order Type
|
|
344
|
+
// "f":"IOC", // Time in Force
|
|
345
|
+
// "q":"1", // Original Quantity
|
|
346
|
+
// "p":"9425.5", // Price
|
|
347
|
+
// "ap":"9496.5", // Average Price
|
|
348
|
+
// "X":"FILLED", // Order Status
|
|
349
|
+
// "l":"1", // Order Last Filled Quantity
|
|
350
|
+
// "z":"1", // Order Filled Accumulated Quantity
|
|
351
|
+
// "T": 1591154240949, // Order Trade Time
|
|
352
|
+
// }
|
|
353
|
+
// myLiquidation
|
|
354
|
+
// {
|
|
355
|
+
// "s":"BTCUSDT", // Symbol
|
|
356
|
+
// "c":"TEST", // Client Order Id
|
|
357
|
+
// // special client order id:
|
|
358
|
+
// // starts with "autoclose-": liquidation order
|
|
359
|
+
// // "adl_autoclose": ADL auto close order
|
|
360
|
+
// // "settlement_autoclose-": settlement order for delisting or delivery
|
|
361
|
+
// "S":"SELL", // Side
|
|
362
|
+
// "o":"TRAILING_STOP_MARKET", // Order Type
|
|
363
|
+
// "f":"GTC", // Time in Force
|
|
364
|
+
// "q":"0.001", // Original Quantity
|
|
365
|
+
// "p":"0", // Original Price
|
|
366
|
+
// "ap":"0", // Average Price
|
|
367
|
+
// "sp":"7103.04", // Stop Price. Please ignore with TRAILING_STOP_MARKET order
|
|
368
|
+
// "x":"NEW", // Execution Type
|
|
369
|
+
// "X":"NEW", // Order Status
|
|
370
|
+
// "i":8886774, // Order Id
|
|
371
|
+
// "l":"0", // Order Last Filled Quantity
|
|
372
|
+
// "z":"0", // Order Filled Accumulated Quantity
|
|
373
|
+
// "L":"0", // Last Filled Price
|
|
374
|
+
// "N":"USDT", // Commission Asset, will not push if no commission
|
|
375
|
+
// "n":"0", // Commission, will not push if no commission
|
|
376
|
+
// "T":1568879465650, // Order Trade Time
|
|
377
|
+
// "t":0, // Trade Id
|
|
378
|
+
// "b":"0", // Bids Notional
|
|
379
|
+
// "a":"9.91", // Ask Notional
|
|
380
|
+
// "m":false, // Is this trade the maker side?
|
|
381
|
+
// "R":false, // Is this reduce only
|
|
382
|
+
// "wt":"CONTRACT_PRICE", // Stop Price Working Type
|
|
383
|
+
// "ot":"TRAILING_STOP_MARKET",// Original Order Type
|
|
384
|
+
// "ps":"LONG", // Position Side
|
|
385
|
+
// "cp":false, // If Close-All, pushed with conditional order
|
|
386
|
+
// "AP":"7476.89", // Activation Price, only puhed with TRAILING_STOP_MARKET order
|
|
387
|
+
// "cr":"5.0", // Callback Rate, only puhed with TRAILING_STOP_MARKET order
|
|
388
|
+
// "pP": false, // If price protection is turned on
|
|
389
|
+
// "si": 0, // ignore
|
|
390
|
+
// "ss": 0, // ignore
|
|
391
|
+
// "rp":"0", // Realized Profit of the trade
|
|
392
|
+
// "V":"EXPIRE_TAKER", // STP mode
|
|
393
|
+
// "pm":"OPPONENT", // Price match mode
|
|
394
|
+
// "gtd":0 // TIF GTD order auto cancel time
|
|
395
|
+
// }
|
|
396
|
+
//
|
|
397
|
+
const marketId = this.safeString(liquidation, 's');
|
|
398
|
+
market = this.safeMarket(marketId, market);
|
|
399
|
+
const timestamp = this.safeInteger(liquidation, 'T');
|
|
400
|
+
return this.safeLiquidation({
|
|
401
|
+
'info': liquidation,
|
|
402
|
+
'symbol': this.safeSymbol(marketId, market),
|
|
403
|
+
'contracts': this.safeNumber(liquidation, 'l'),
|
|
404
|
+
'contractSize': this.safeNumber(market, 'contractSize'),
|
|
405
|
+
'price': this.safeNumber(liquidation, 'ap'),
|
|
406
|
+
'baseValue': undefined,
|
|
407
|
+
'quoteValue': undefined,
|
|
408
|
+
'timestamp': timestamp,
|
|
409
|
+
'datetime': this.iso8601(timestamp),
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
async watchMyLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
|
|
413
|
+
/**
|
|
414
|
+
* @method
|
|
415
|
+
* @name binance#watchMyLiquidations
|
|
416
|
+
* @description watch the private liquidations of a trading pair
|
|
417
|
+
* @see https://binance-docs.github.io/apidocs/futures/en/#event-order-update
|
|
418
|
+
* @see https://binance-docs.github.io/apidocs/delivery/en/#event-order-update
|
|
419
|
+
* @param {string} symbol unified CCXT market symbol
|
|
420
|
+
* @param {int} [since] the earliest time in ms to fetch liquidations for
|
|
421
|
+
* @param {int} [limit] the maximum number of liquidation structures to retrieve
|
|
422
|
+
* @param {object} [params] exchange specific parameters for the bitmex api endpoint
|
|
423
|
+
* @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
|
|
424
|
+
*/
|
|
425
|
+
return this.watchMyLiquidationsForSymbols([symbol], since, limit, params);
|
|
426
|
+
}
|
|
427
|
+
async watchMyLiquidationsForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
|
|
428
|
+
/**
|
|
429
|
+
* @method
|
|
430
|
+
* @name binance#watchMyLiquidationsForSymbols
|
|
431
|
+
* @description watch the private liquidations of a trading pair
|
|
432
|
+
* @see https://binance-docs.github.io/apidocs/futures/en/#event-order-update
|
|
433
|
+
* @see https://binance-docs.github.io/apidocs/delivery/en/#event-order-update
|
|
434
|
+
* @param {string} symbol unified CCXT market symbol
|
|
435
|
+
* @param {int} [since] the earliest time in ms to fetch liquidations for
|
|
436
|
+
* @param {int} [limit] the maximum number of liquidation structures to retrieve
|
|
437
|
+
* @param {object} [params] exchange specific parameters for the bitmex api endpoint
|
|
438
|
+
* @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
|
|
439
|
+
*/
|
|
440
|
+
await this.loadMarkets();
|
|
441
|
+
symbols = this.marketSymbols(symbols, undefined, true, true, true);
|
|
442
|
+
const market = this.getMarketFromSymbols(symbols);
|
|
443
|
+
const messageHashes = ['myLiquidations'];
|
|
444
|
+
if (!this.isEmpty(symbols)) {
|
|
445
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
446
|
+
const symbol = symbols[i];
|
|
447
|
+
messageHashes.push('myLiquidations::' + symbol);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
let type = undefined;
|
|
451
|
+
[type, params] = this.handleMarketTypeAndParams('watchMyLiquidationsForSymbols', market, params);
|
|
452
|
+
let subType = undefined;
|
|
453
|
+
[subType, params] = this.handleSubTypeAndParams('watchMyLiquidationsForSymbols', market, params);
|
|
454
|
+
if (this.isLinear(type, subType)) {
|
|
455
|
+
type = 'future';
|
|
456
|
+
}
|
|
457
|
+
else if (this.isInverse(type, subType)) {
|
|
458
|
+
type = 'delivery';
|
|
459
|
+
}
|
|
460
|
+
await this.authenticate(params);
|
|
461
|
+
const url = this.urls['api']['ws'][type] + '/' + this.options[type]['listenKey'];
|
|
462
|
+
const message = undefined;
|
|
463
|
+
const newLiquidations = await this.watchMultiple(url, messageHashes, message, [type]);
|
|
464
|
+
if (this.newUpdates) {
|
|
465
|
+
return newLiquidations;
|
|
466
|
+
}
|
|
467
|
+
return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit);
|
|
468
|
+
}
|
|
469
|
+
handleMyLiquidation(client, message) {
|
|
470
|
+
//
|
|
471
|
+
// {
|
|
472
|
+
// "s":"BTCUSDT", // Symbol
|
|
473
|
+
// "c":"TEST", // Client Order Id
|
|
474
|
+
// // special client order id:
|
|
475
|
+
// // starts with "autoclose-": liquidation order
|
|
476
|
+
// // "adl_autoclose": ADL auto close order
|
|
477
|
+
// // "settlement_autoclose-": settlement order for delisting or delivery
|
|
478
|
+
// "S":"SELL", // Side
|
|
479
|
+
// "o":"TRAILING_STOP_MARKET", // Order Type
|
|
480
|
+
// "f":"GTC", // Time in Force
|
|
481
|
+
// "q":"0.001", // Original Quantity
|
|
482
|
+
// "p":"0", // Original Price
|
|
483
|
+
// "ap":"0", // Average Price
|
|
484
|
+
// "sp":"7103.04", // Stop Price. Please ignore with TRAILING_STOP_MARKET order
|
|
485
|
+
// "x":"NEW", // Execution Type
|
|
486
|
+
// "X":"NEW", // Order Status
|
|
487
|
+
// "i":8886774, // Order Id
|
|
488
|
+
// "l":"0", // Order Last Filled Quantity
|
|
489
|
+
// "z":"0", // Order Filled Accumulated Quantity
|
|
490
|
+
// "L":"0", // Last Filled Price
|
|
491
|
+
// "N":"USDT", // Commission Asset, will not push if no commission
|
|
492
|
+
// "n":"0", // Commission, will not push if no commission
|
|
493
|
+
// "T":1568879465650, // Order Trade Time
|
|
494
|
+
// "t":0, // Trade Id
|
|
495
|
+
// "b":"0", // Bids Notional
|
|
496
|
+
// "a":"9.91", // Ask Notional
|
|
497
|
+
// "m":false, // Is this trade the maker side?
|
|
498
|
+
// "R":false, // Is this reduce only
|
|
499
|
+
// "wt":"CONTRACT_PRICE", // Stop Price Working Type
|
|
500
|
+
// "ot":"TRAILING_STOP_MARKET",// Original Order Type
|
|
501
|
+
// "ps":"LONG", // Position Side
|
|
502
|
+
// "cp":false, // If Close-All, pushed with conditional order
|
|
503
|
+
// "AP":"7476.89", // Activation Price, only puhed with TRAILING_STOP_MARKET order
|
|
504
|
+
// "cr":"5.0", // Callback Rate, only puhed with TRAILING_STOP_MARKET order
|
|
505
|
+
// "pP": false, // If price protection is turned on
|
|
506
|
+
// "si": 0, // ignore
|
|
507
|
+
// "ss": 0, // ignore
|
|
508
|
+
// "rp":"0", // Realized Profit of the trade
|
|
509
|
+
// "V":"EXPIRE_TAKER", // STP mode
|
|
510
|
+
// "pm":"OPPONENT", // Price match mode
|
|
511
|
+
// "gtd":0 // TIF GTD order auto cancel time
|
|
512
|
+
// }
|
|
513
|
+
//
|
|
514
|
+
const orderType = this.safeString(message, 'o');
|
|
515
|
+
if (orderType !== 'LIQUIDATION') {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const marketId = this.safeString(message, 's');
|
|
519
|
+
const market = this.safeMarket(marketId);
|
|
520
|
+
const symbol = this.safeSymbol(marketId);
|
|
521
|
+
const liquidation = this.parseWsLiquidation(message, market);
|
|
522
|
+
let myLiquidations = this.safeValue(this.myLiquidations, symbol);
|
|
523
|
+
if (myLiquidations === undefined) {
|
|
524
|
+
const limit = this.safeInteger(this.options, 'myLiquidationsLimit', 1000);
|
|
525
|
+
myLiquidations = new Cache.ArrayCache(limit);
|
|
526
|
+
}
|
|
527
|
+
myLiquidations.append(liquidation);
|
|
528
|
+
this.myLiquidations[symbol] = myLiquidations;
|
|
529
|
+
client.resolve([liquidation], 'myLiquidations');
|
|
530
|
+
client.resolve([liquidation], 'myLiquidations::' + symbol);
|
|
531
|
+
}
|
|
182
532
|
async watchOrderBook(symbol, limit = undefined, params = {}) {
|
|
183
533
|
/**
|
|
184
534
|
* @method
|
|
@@ -2818,6 +3168,7 @@ class binance extends binance$1 {
|
|
|
2818
3168
|
}
|
|
2819
3169
|
this.handleMyTrade(client, message);
|
|
2820
3170
|
this.handleOrder(client, message);
|
|
3171
|
+
this.handleMyLiquidation(client, message);
|
|
2821
3172
|
}
|
|
2822
3173
|
async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
2823
3174
|
/**
|
|
@@ -3436,6 +3787,7 @@ class binance extends binance$1 {
|
|
|
3436
3787
|
'ACCOUNT_UPDATE': this.handleAcountUpdate,
|
|
3437
3788
|
'executionReport': this.handleOrderUpdate,
|
|
3438
3789
|
'ORDER_TRADE_UPDATE': this.handleOrderUpdate,
|
|
3790
|
+
'forceOrder': this.handleLiquidation,
|
|
3439
3791
|
};
|
|
3440
3792
|
let event = this.safeString(message, 'e');
|
|
3441
3793
|
if (Array.isArray(message)) {
|
|
@@ -966,7 +966,9 @@ class bitget extends bitget$1 {
|
|
|
966
966
|
* @param {int} [limit] the maximum number of order structures to retrieve
|
|
967
967
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
968
968
|
* @param {boolean} [params.stop] *contract only* set to true for watching trigger orders
|
|
969
|
-
* @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin orders
|
|
969
|
+
* @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin orders]
|
|
970
|
+
* @param {string} [params.type] 'spot', 'swap'
|
|
971
|
+
* @param {string} [params.subType] 'linear', 'inverse'
|
|
970
972
|
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure
|
|
971
973
|
*/
|
|
972
974
|
await this.loadMarkets();
|
|
@@ -982,11 +984,26 @@ class bitget extends bitget$1 {
|
|
|
982
984
|
marketId = market['id'];
|
|
983
985
|
messageHash = messageHash + ':' + symbol;
|
|
984
986
|
}
|
|
987
|
+
const productType = this.safeString(params, 'productType');
|
|
985
988
|
let type = undefined;
|
|
986
989
|
[type, params] = this.handleMarketTypeAndParams('watchOrders', market, params);
|
|
990
|
+
let subType = undefined;
|
|
991
|
+
[subType, params] = this.handleSubTypeAndParams('watchOrders', market, params, 'linear');
|
|
987
992
|
if ((type === 'spot') && (symbol === undefined)) {
|
|
988
993
|
throw new errors.ArgumentsRequired(this.id + ' watchOrders requires a symbol argument for ' + type + ' markets.');
|
|
989
994
|
}
|
|
995
|
+
if ((productType === undefined) && (type !== 'spot') && (symbol === undefined)) {
|
|
996
|
+
messageHash = messageHash + ':' + subType;
|
|
997
|
+
}
|
|
998
|
+
else if (productType === 'USDT-FUTURES') {
|
|
999
|
+
messageHash = messageHash + ':linear';
|
|
1000
|
+
}
|
|
1001
|
+
else if (productType === 'COIN-FUTURES') {
|
|
1002
|
+
messageHash = messageHash + ':inverse';
|
|
1003
|
+
}
|
|
1004
|
+
else if (productType === 'USDC-FUTURES') {
|
|
1005
|
+
messageHash = messageHash + ':usdcfutures'; // non unified channel
|
|
1006
|
+
}
|
|
990
1007
|
let instType = undefined;
|
|
991
1008
|
[instType, params] = this.getInstType(market, params);
|
|
992
1009
|
if (type === 'spot') {
|
|
@@ -1008,6 +1025,7 @@ class bitget extends bitget$1 {
|
|
|
1008
1025
|
channel = 'orders-crossed';
|
|
1009
1026
|
}
|
|
1010
1027
|
}
|
|
1028
|
+
subscriptionHash = subscriptionHash + ':' + instType;
|
|
1011
1029
|
const args = {
|
|
1012
1030
|
'instType': instType,
|
|
1013
1031
|
'channel': channel,
|
|
@@ -1067,6 +1085,9 @@ class bitget extends bitget$1 {
|
|
|
1067
1085
|
else {
|
|
1068
1086
|
marketType = 'contract';
|
|
1069
1087
|
}
|
|
1088
|
+
const isLinearSwap = (instType === 'USDT-FUTURES');
|
|
1089
|
+
const isInverseSwap = (instType === 'COIN-FUTURES');
|
|
1090
|
+
const isUSDCFutures = (instType === 'USDC-FUTURES');
|
|
1070
1091
|
const data = this.safeValue(message, 'data', []);
|
|
1071
1092
|
if (this.orders === undefined) {
|
|
1072
1093
|
const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
|
|
@@ -1093,6 +1114,15 @@ class bitget extends bitget$1 {
|
|
|
1093
1114
|
client.resolve(stored, innerMessageHash);
|
|
1094
1115
|
}
|
|
1095
1116
|
client.resolve(stored, messageHash);
|
|
1117
|
+
if (isLinearSwap) {
|
|
1118
|
+
client.resolve(stored, 'order:linear');
|
|
1119
|
+
}
|
|
1120
|
+
if (isInverseSwap) {
|
|
1121
|
+
client.resolve(stored, 'order:inverse');
|
|
1122
|
+
}
|
|
1123
|
+
if (isUSDCFutures) {
|
|
1124
|
+
client.resolve(stored, 'order:usdcfutures');
|
|
1125
|
+
}
|
|
1096
1126
|
}
|
|
1097
1127
|
parseWsOrder(order, market = undefined) {
|
|
1098
1128
|
//
|
|
@@ -13,6 +13,10 @@ class bitmex extends bitmex$1 {
|
|
|
13
13
|
'has': {
|
|
14
14
|
'ws': true,
|
|
15
15
|
'watchBalance': true,
|
|
16
|
+
'watchLiquidations': true,
|
|
17
|
+
'watchLiquidationsForSymbols': true,
|
|
18
|
+
'watchMyLiquidations': undefined,
|
|
19
|
+
'watchMyLiquidationsForSymbols': undefined,
|
|
16
20
|
'watchMyTrades': true,
|
|
17
21
|
'watchOHLCV': true,
|
|
18
22
|
'watchOrderBook': true,
|
|
@@ -349,6 +353,109 @@ class bitmex extends bitmex$1 {
|
|
|
349
353
|
}
|
|
350
354
|
return message;
|
|
351
355
|
}
|
|
356
|
+
async watchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
|
|
357
|
+
/**
|
|
358
|
+
* @method
|
|
359
|
+
* @name bitmex#watchLiquidations
|
|
360
|
+
* @description watch the public liquidations of a trading pair
|
|
361
|
+
* @see https://www.bitmex.com/app/wsAPI#Liquidation
|
|
362
|
+
* @param {string} symbol unified CCXT market symbol
|
|
363
|
+
* @param {int} [since] the earliest time in ms to fetch liquidations for
|
|
364
|
+
* @param {int} [limit] the maximum number of liquidation structures to retrieve
|
|
365
|
+
* @param {object} [params] exchange specific parameters for the bitmex api endpoint
|
|
366
|
+
* @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
|
|
367
|
+
*/
|
|
368
|
+
return this.watchLiquidationsForSymbols([symbol], since, limit, params);
|
|
369
|
+
}
|
|
370
|
+
async watchLiquidationsForSymbols(symbols = undefined, since = undefined, limit = undefined, params = {}) {
|
|
371
|
+
/**
|
|
372
|
+
* @method
|
|
373
|
+
* @name bitmex#watchLiquidationsForSymbols
|
|
374
|
+
* @description watch the public liquidations of a trading pair
|
|
375
|
+
* @see https://www.bitmex.com/app/wsAPI#Liquidation
|
|
376
|
+
* @param {string} symbol unified CCXT market symbol
|
|
377
|
+
* @param {int} [since] the earliest time in ms to fetch liquidations for
|
|
378
|
+
* @param {int} [limit] the maximum number of liquidation structures to retrieve
|
|
379
|
+
* @param {object} [params] exchange specific parameters for the bitmex api endpoint
|
|
380
|
+
* @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
|
|
381
|
+
*/
|
|
382
|
+
await this.loadMarkets();
|
|
383
|
+
symbols = this.marketSymbols(symbols, undefined, true, true);
|
|
384
|
+
const messageHashes = [];
|
|
385
|
+
const subscriptionHashes = [];
|
|
386
|
+
if (this.isEmpty(symbols)) {
|
|
387
|
+
subscriptionHashes.push('liquidation');
|
|
388
|
+
messageHashes.push('liquidations');
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
392
|
+
const symbol = symbols[i];
|
|
393
|
+
const market = this.market(symbol);
|
|
394
|
+
subscriptionHashes.push('liquidation:' + market['id']);
|
|
395
|
+
messageHashes.push('liquidations::' + symbol);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const url = this.urls['api']['ws'];
|
|
399
|
+
const request = {
|
|
400
|
+
'op': 'subscribe',
|
|
401
|
+
'args': subscriptionHashes,
|
|
402
|
+
};
|
|
403
|
+
const newLiquidations = await this.watchMultiple(url, messageHashes, this.deepExtend(request, params), subscriptionHashes);
|
|
404
|
+
if (this.newUpdates) {
|
|
405
|
+
return newLiquidations;
|
|
406
|
+
}
|
|
407
|
+
return this.filterBySymbolsSinceLimit(this.liquidations, symbols, since, limit, true);
|
|
408
|
+
}
|
|
409
|
+
handleLiquidation(client, message) {
|
|
410
|
+
//
|
|
411
|
+
// {
|
|
412
|
+
// "table":"liquidation",
|
|
413
|
+
// "action":"partial",
|
|
414
|
+
// "keys":[
|
|
415
|
+
// "orderID"
|
|
416
|
+
// ],
|
|
417
|
+
// "types":{
|
|
418
|
+
// "orderID":"guid",
|
|
419
|
+
// "symbol":"symbol",
|
|
420
|
+
// "side":"symbol",
|
|
421
|
+
// "price":"float",
|
|
422
|
+
// "leavesQty":"long"
|
|
423
|
+
// },
|
|
424
|
+
// "filter":{},
|
|
425
|
+
// "data":[
|
|
426
|
+
// {
|
|
427
|
+
// "orderID":"e0a568ee-7830-4428-92c3-73e82b9576ce",
|
|
428
|
+
// "symbol":"XPLAUSDT",
|
|
429
|
+
// "side":"Sell",
|
|
430
|
+
// "price":0.206,
|
|
431
|
+
// "leavesQty":340
|
|
432
|
+
// }
|
|
433
|
+
// ]
|
|
434
|
+
// }
|
|
435
|
+
//
|
|
436
|
+
const rawLiquidations = this.safeValue(message, 'data', []);
|
|
437
|
+
const newLiquidations = [];
|
|
438
|
+
for (let i = 0; i < rawLiquidations.length; i++) {
|
|
439
|
+
const rawLiquidation = rawLiquidations[i];
|
|
440
|
+
const liquidation = this.parseLiquidation(rawLiquidation);
|
|
441
|
+
const symbol = liquidation['symbol'];
|
|
442
|
+
let liquidations = this.safeValue(this.liquidations, symbol);
|
|
443
|
+
if (liquidations === undefined) {
|
|
444
|
+
const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
|
|
445
|
+
liquidations = new Cache.ArrayCache(limit);
|
|
446
|
+
}
|
|
447
|
+
liquidations.append(liquidation);
|
|
448
|
+
this.liquidations[symbol] = liquidations;
|
|
449
|
+
newLiquidations.push(liquidation);
|
|
450
|
+
}
|
|
451
|
+
client.resolve(newLiquidations, 'liquidations');
|
|
452
|
+
const liquidationsBySymbol = this.indexBy(newLiquidations, 'symbol');
|
|
453
|
+
const symbols = Object.keys(liquidationsBySymbol);
|
|
454
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
455
|
+
const symbol = symbols[i];
|
|
456
|
+
client.resolve(liquidationsBySymbol[symbol], 'liquidations::' + symbol);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
352
459
|
async watchBalance(params = {}) {
|
|
353
460
|
/**
|
|
354
461
|
* @method
|
|
@@ -1608,6 +1715,7 @@ class bitmex extends bitmex$1 {
|
|
|
1608
1715
|
'order': this.handleOrders,
|
|
1609
1716
|
'execution': this.handleMyTrades,
|
|
1610
1717
|
'margin': this.handleBalance,
|
|
1718
|
+
'liquidation': this.handleLiquidation,
|
|
1611
1719
|
'position': this.handlePositions,
|
|
1612
1720
|
};
|
|
1613
1721
|
const method = this.safeValue(methods, table);
|