ccxt 4.3.32 → 4.3.34

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 (128) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +2 -2
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +26 -0
  5. package/dist/cjs/src/binance.js +1 -0
  6. package/dist/cjs/src/bitget.js +1 -1
  7. package/dist/cjs/src/coinbase.js +106 -53
  8. package/dist/cjs/src/pro/binance.js +352 -0
  9. package/dist/cjs/src/pro/bitmex.js +108 -0
  10. package/dist/cjs/src/pro/bybit.js +85 -0
  11. package/dist/cjs/src/pro/gate.js +183 -0
  12. package/dist/cjs/src/pro/kucoinfutures.js +4 -0
  13. package/dist/cjs/src/pro/okx.js +259 -1
  14. package/dist/cjs/src/whitebit.js +2 -2
  15. package/js/ccxt.d.ts +1 -1
  16. package/js/ccxt.js +1 -1
  17. package/js/src/abstract/binance.d.ts +1 -0
  18. package/js/src/abstract/binancecoinm.d.ts +1 -0
  19. package/js/src/abstract/binanceus.d.ts +1 -0
  20. package/js/src/abstract/binanceusdm.d.ts +1 -0
  21. package/js/src/ace.d.ts +3 -3
  22. package/js/src/alpaca.d.ts +2 -2
  23. package/js/src/ascendex.d.ts +3 -3
  24. package/js/src/base/Exchange.d.ts +13 -3
  25. package/js/src/base/Exchange.js +26 -0
  26. package/js/src/base/types.d.ts +1 -0
  27. package/js/src/bigone.d.ts +3 -3
  28. package/js/src/binance.d.ts +4 -4
  29. package/js/src/binance.js +1 -0
  30. package/js/src/bingx.d.ts +3 -3
  31. package/js/src/bit2c.d.ts +2 -2
  32. package/js/src/bitbank.d.ts +2 -2
  33. package/js/src/bitbns.d.ts +2 -2
  34. package/js/src/bitfinex.d.ts +3 -3
  35. package/js/src/bitfinex2.d.ts +1 -1
  36. package/js/src/bitflyer.d.ts +2 -2
  37. package/js/src/bitget.d.ts +4 -4
  38. package/js/src/bitget.js +1 -1
  39. package/js/src/bithumb.d.ts +2 -2
  40. package/js/src/bitmart.d.ts +3 -3
  41. package/js/src/bitmex.d.ts +4 -4
  42. package/js/src/bitopro.d.ts +4 -4
  43. package/js/src/bitrue.d.ts +3 -3
  44. package/js/src/bitso.d.ts +3 -3
  45. package/js/src/bitstamp.d.ts +3 -3
  46. package/js/src/bitteam.d.ts +4 -4
  47. package/js/src/bitvavo.d.ts +3 -3
  48. package/js/src/blockchaincom.d.ts +2 -2
  49. package/js/src/blofin.d.ts +4 -4
  50. package/js/src/btcalpha.d.ts +4 -4
  51. package/js/src/btcbox.d.ts +2 -2
  52. package/js/src/btcmarkets.d.ts +4 -4
  53. package/js/src/btcturk.d.ts +2 -2
  54. package/js/src/bybit.d.ts +3 -3
  55. package/js/src/cex.d.ts +2 -2
  56. package/js/src/coinbase.d.ts +3 -3
  57. package/js/src/coinbase.js +106 -53
  58. package/js/src/coinbaseexchange.d.ts +2 -2
  59. package/js/src/coinbaseinternational.d.ts +4 -4
  60. package/js/src/coincheck.d.ts +3 -3
  61. package/js/src/coinex.d.ts +3 -3
  62. package/js/src/coinlist.d.ts +3 -3
  63. package/js/src/coinmate.d.ts +3 -3
  64. package/js/src/coinmetro.d.ts +3 -3
  65. package/js/src/coinone.d.ts +2 -2
  66. package/js/src/coinsph.d.ts +3 -3
  67. package/js/src/cryptocom.d.ts +2 -2
  68. package/js/src/currencycom.d.ts +3 -3
  69. package/js/src/delta.d.ts +2 -2
  70. package/js/src/deribit.d.ts +3 -3
  71. package/js/src/digifinex.d.ts +3 -3
  72. package/js/src/exmo.d.ts +3 -3
  73. package/js/src/gate.d.ts +3 -3
  74. package/js/src/gemini.d.ts +3 -3
  75. package/js/src/hitbtc.d.ts +3 -3
  76. package/js/src/hollaex.d.ts +2 -2
  77. package/js/src/htx.d.ts +3 -3
  78. package/js/src/huobijp.d.ts +3 -3
  79. package/js/src/hyperliquid.d.ts +3 -3
  80. package/js/src/idex.d.ts +3 -3
  81. package/js/src/indodax.d.ts +3 -3
  82. package/js/src/kraken.d.ts +3 -3
  83. package/js/src/krakenfutures.d.ts +2 -2
  84. package/js/src/kucoin.d.ts +3 -3
  85. package/js/src/kuna.d.ts +3 -3
  86. package/js/src/latoken.d.ts +3 -3
  87. package/js/src/lbank.d.ts +2 -2
  88. package/js/src/luno.d.ts +2 -2
  89. package/js/src/lykke.d.ts +2 -2
  90. package/js/src/mercado.d.ts +2 -2
  91. package/js/src/mexc.d.ts +2 -2
  92. package/js/src/ndax.d.ts +3 -3
  93. package/js/src/novadax.d.ts +4 -4
  94. package/js/src/oceanex.d.ts +3 -3
  95. package/js/src/okcoin.d.ts +4 -4
  96. package/js/src/okx.d.ts +4 -4
  97. package/js/src/onetrading.d.ts +3 -3
  98. package/js/src/p2b.d.ts +3 -3
  99. package/js/src/paymium.d.ts +2 -2
  100. package/js/src/phemex.d.ts +5 -5
  101. package/js/src/poloniex.d.ts +4 -4
  102. package/js/src/poloniexfutures.d.ts +3 -3
  103. package/js/src/pro/binance.d.ts +9 -2
  104. package/js/src/pro/binance.js +352 -0
  105. package/js/src/pro/bitmex.d.ts +4 -1
  106. package/js/src/pro/bitmex.js +108 -0
  107. package/js/src/pro/bybit.d.ts +4 -1
  108. package/js/src/pro/bybit.js +85 -0
  109. package/js/src/pro/gate.d.ts +5 -1
  110. package/js/src/pro/gate.js +183 -0
  111. package/js/src/pro/kucoinfutures.js +4 -0
  112. package/js/src/pro/okx.d.ts +8 -1
  113. package/js/src/pro/okx.js +259 -1
  114. package/js/src/probit.d.ts +4 -4
  115. package/js/src/timex.d.ts +3 -3
  116. package/js/src/tokocrypto.d.ts +2 -2
  117. package/js/src/tradeogre.d.ts +2 -2
  118. package/js/src/upbit.d.ts +4 -4
  119. package/js/src/wavesexchange.d.ts +2 -2
  120. package/js/src/wazirx.d.ts +4 -4
  121. package/js/src/whitebit.d.ts +4 -4
  122. package/js/src/whitebit.js +2 -2
  123. package/js/src/woo.d.ts +4 -4
  124. package/js/src/woofipro.d.ts +4 -4
  125. package/js/src/yobit.d.ts +2 -2
  126. package/js/src/zaif.d.ts +3 -3
  127. package/js/src/zonda.d.ts +2 -2
  128. 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)) {
@@ -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);
@@ -22,6 +22,10 @@ class bybit extends bybit$1 {
22
22
  'fetchTradesWs': false,
23
23
  'fetchBalanceWs': false,
24
24
  'watchBalance': true,
25
+ 'watchLiquidations': true,
26
+ 'watchLiquidationsForSymbols': false,
27
+ 'watchMyLiquidations': false,
28
+ 'watchMyLiquidationsForSymbols': false,
25
29
  'watchMyTrades': true,
26
30
  'watchOHLCV': true,
27
31
  'watchOHLCVForSymbols': false,
@@ -1199,6 +1203,86 @@ class bybit extends bybit$1 {
1199
1203
  }
1200
1204
  client.resolve(newPositions, 'positions');
1201
1205
  }
1206
+ async watchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
1207
+ /**
1208
+ * @method
1209
+ * @name bybit#watchLiquidations
1210
+ * @description watch the public liquidations of a trading pair
1211
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/liquidation
1212
+ * @param {string} symbol unified CCXT market symbol
1213
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
1214
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
1215
+ * @param {object} [params] exchange specific parameters for the bitmex api endpoint
1216
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
1217
+ */
1218
+ await this.loadMarkets();
1219
+ const market = this.market(symbol);
1220
+ symbol = market['symbol'];
1221
+ const url = this.getUrlByMarketType(symbol, false, 'watchLiquidations', params);
1222
+ params = this.cleanParams(params);
1223
+ const messageHash = 'liquidations::' + symbol;
1224
+ const topic = 'liquidation.' + market['id'];
1225
+ const newLiquidation = await this.watchTopics(url, [messageHash], [topic], params);
1226
+ if (this.newUpdates) {
1227
+ return [newLiquidation];
1228
+ }
1229
+ return this.filterBySymbolsSinceLimit(this.liquidations, [symbol], since, limit, true);
1230
+ }
1231
+ handleLiquidation(client, message) {
1232
+ //
1233
+ // {
1234
+ // "data": {
1235
+ // "price": "0.03803",
1236
+ // "side": "Buy",
1237
+ // "size": "1637",
1238
+ // "symbol": "GALAUSDT",
1239
+ // "updatedTime": 1673251091822
1240
+ // },
1241
+ // "topic": "liquidation.GALAUSDT",
1242
+ // "ts": 1673251091822,
1243
+ // "type": "snapshot"
1244
+ // }
1245
+ //
1246
+ const rawLiquidation = this.safeDict(message, 'data', {});
1247
+ const marketId = this.safeString(rawLiquidation, 'symbol');
1248
+ const market = this.safeMarket(marketId, undefined, '', 'contract');
1249
+ const symbol = this.safeSymbol(marketId);
1250
+ const liquidation = this.parseWsLiquidation(rawLiquidation, market);
1251
+ let liquidations = this.safeValue(this.liquidations, symbol);
1252
+ if (liquidations === undefined) {
1253
+ const limit = this.safeInteger(this.options, 'liquidationsLimit', 1000);
1254
+ liquidations = new Cache.ArrayCache(limit);
1255
+ }
1256
+ liquidations.append(liquidation);
1257
+ this.liquidations[symbol] = liquidations;
1258
+ client.resolve([liquidation], 'liquidations');
1259
+ client.resolve([liquidation], 'liquidations::' + symbol);
1260
+ }
1261
+ parseWsLiquidation(liquidation, market = undefined) {
1262
+ //
1263
+ // {
1264
+ // "price": "0.03803",
1265
+ // "side": "Buy",
1266
+ // "size": "1637",
1267
+ // "symbol": "GALAUSDT",
1268
+ // "updatedTime": 1673251091822
1269
+ // }
1270
+ //
1271
+ const marketId = this.safeString(liquidation, 'symbol');
1272
+ market = this.safeMarket(marketId, market, '', 'contract');
1273
+ const timestamp = this.safeInteger(liquidation, 'updatedTime');
1274
+ return this.safeLiquidation({
1275
+ 'info': liquidation,
1276
+ 'symbol': this.safeSymbol(marketId, market),
1277
+ 'contracts': this.safeNumber(liquidation, 'size'),
1278
+ 'contractSize': this.safeNumber(market, 'contractSize'),
1279
+ 'price': this.safeNumber(liquidation, 'price'),
1280
+ 'baseValue': undefined,
1281
+ 'quoteValue': undefined,
1282
+ 'timestamp': timestamp,
1283
+ 'datetime': this.iso8601(timestamp),
1284
+ });
1285
+ }
1202
1286
  async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1203
1287
  /**
1204
1288
  * @method
@@ -1959,6 +2043,7 @@ class bybit extends bybit$1 {
1959
2043
  'ticketInfo': this.handleMyTrades,
1960
2044
  'user.openapi.perp.trade': this.handleMyTrades,
1961
2045
  'position': this.handlePositions,
2046
+ 'liquidation': this.handleLiquidation,
1962
2047
  'pong': this.handlePong,
1963
2048
  'order.create': this.handleOrderWs,
1964
2049
  'order.amend': this.handleOrderWs,