ccxt 4.1.12 → 4.1.13

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 (86) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +947 -15
  3. package/dist/ccxt.browser.min.js +2 -2
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/ace.js +1 -0
  6. package/dist/cjs/src/alpaca.js +1 -0
  7. package/dist/cjs/src/base/Exchange.js +30 -0
  8. package/dist/cjs/src/bigone.js +1 -0
  9. package/dist/cjs/src/binance.js +231 -1
  10. package/dist/cjs/src/bingx.js +1 -0
  11. package/dist/cjs/src/bitbank.js +1 -0
  12. package/dist/cjs/src/bitbns.js +1 -0
  13. package/dist/cjs/src/bitfinex.js +1 -0
  14. package/dist/cjs/src/bitfinex2.js +1 -0
  15. package/dist/cjs/src/bitflyer.js +1 -0
  16. package/dist/cjs/src/bitforex.js +1 -0
  17. package/dist/cjs/src/bitget.js +11 -2
  18. package/dist/cjs/src/bithumb.js +1 -0
  19. package/dist/cjs/src/bitmart.js +103 -0
  20. package/dist/cjs/src/bitmex.js +70 -0
  21. package/dist/cjs/src/bitopro.js +1 -0
  22. package/dist/cjs/src/bitpanda.js +1 -0
  23. package/dist/cjs/src/bitrue.js +1 -0
  24. package/dist/cjs/src/bitso.js +1 -0
  25. package/dist/cjs/src/bitstamp.js +1 -0
  26. package/dist/cjs/src/bitvavo.js +1 -0
  27. package/dist/cjs/src/blockchaincom.js +1 -0
  28. package/dist/cjs/src/btcalpha.js +1 -0
  29. package/dist/cjs/src/btcmarkets.js +1 -0
  30. package/dist/cjs/src/btcturk.js +1 -0
  31. package/dist/cjs/src/bybit.js +3 -3
  32. package/dist/cjs/src/deribit.js +163 -0
  33. package/dist/cjs/src/gate.js +189 -0
  34. package/dist/cjs/src/huobi.js +102 -0
  35. package/dist/cjs/src/kucoin.js +1 -0
  36. package/dist/cjs/src/kucoinfutures.js +1 -1
  37. package/dist/cjs/src/okx.js +1 -0
  38. package/dist/cjs/src/poloniex.js +20 -7
  39. package/js/ccxt.d.ts +3 -3
  40. package/js/ccxt.js +1 -1
  41. package/js/src/abstract/poloniex.d.ts +18 -5
  42. package/js/src/ace.js +1 -0
  43. package/js/src/alpaca.js +1 -0
  44. package/js/src/base/Exchange.d.ts +6 -2
  45. package/js/src/base/Exchange.js +30 -0
  46. package/js/src/base/types.d.ts +9 -0
  47. package/js/src/bigone.js +1 -0
  48. package/js/src/binance.d.ts +13 -1
  49. package/js/src/binance.js +231 -1
  50. package/js/src/bingx.d.ts +1 -0
  51. package/js/src/bingx.js +1 -0
  52. package/js/src/bitbank.js +1 -0
  53. package/js/src/bitbns.js +1 -0
  54. package/js/src/bitfinex.js +1 -0
  55. package/js/src/bitfinex2.js +1 -0
  56. package/js/src/bitflyer.js +1 -0
  57. package/js/src/bitforex.js +1 -0
  58. package/js/src/bitget.js +11 -2
  59. package/js/src/bithumb.js +1 -0
  60. package/js/src/bitmart.d.ts +12 -0
  61. package/js/src/bitmart.js +103 -0
  62. package/js/src/bitmex.d.ts +13 -1
  63. package/js/src/bitmex.js +70 -0
  64. package/js/src/bitopro.js +1 -0
  65. package/js/src/bitpanda.js +1 -0
  66. package/js/src/bitrue.js +1 -0
  67. package/js/src/bitso.js +1 -0
  68. package/js/src/bitstamp.js +1 -0
  69. package/js/src/bitvavo.js +1 -0
  70. package/js/src/blockchaincom.js +1 -0
  71. package/js/src/btcalpha.js +1 -0
  72. package/js/src/btcmarkets.js +1 -0
  73. package/js/src/btcturk.js +1 -0
  74. package/js/src/bybit.js +3 -3
  75. package/js/src/deribit.d.ts +14 -0
  76. package/js/src/deribit.js +163 -0
  77. package/js/src/gate.d.ts +13 -0
  78. package/js/src/gate.js +189 -0
  79. package/js/src/huobi.d.ts +12 -0
  80. package/js/src/huobi.js +102 -0
  81. package/js/src/kucoin.js +1 -0
  82. package/js/src/kucoinfutures.js +1 -1
  83. package/js/src/okx.js +1 -0
  84. package/js/src/poloniex.js +20 -7
  85. package/package.json +1 -1
  86. package/skip-tests.json +61 -5
@@ -233,6 +233,7 @@ export default class bitforex extends Exchange {
233
233
  'max': undefined,
234
234
  },
235
235
  },
236
+ 'created': undefined,
236
237
  'info': market,
237
238
  });
238
239
  }
package/js/src/bitget.js CHANGED
@@ -1477,6 +1477,7 @@ export default class bitget extends Exchange {
1477
1477
  'max': undefined,
1478
1478
  },
1479
1479
  },
1480
+ 'created': undefined,
1480
1481
  };
1481
1482
  }
1482
1483
  return result;
@@ -3885,8 +3886,16 @@ export default class bitget extends Exchange {
3885
3886
  //
3886
3887
  const data = this.safeValue(response, 'data');
3887
3888
  if (data !== undefined) {
3888
- const result = this.safeValue(data, 'orderList', data);
3889
- return this.addPaginationCursorToResult(data, result);
3889
+ if ('orderList' in data) {
3890
+ const orderList = this.safeValue(data, 'orderList');
3891
+ if (!orderList) {
3892
+ return [];
3893
+ }
3894
+ return this.addPaginationCursorToResult(data, orderList);
3895
+ }
3896
+ else {
3897
+ return this.addPaginationCursorToResult(response, data);
3898
+ }
3890
3899
  }
3891
3900
  const parsedData = JSON.parse(response);
3892
3901
  return this.safeValue(parsedData, 'data', []);
package/js/src/bithumb.js CHANGED
@@ -261,6 +261,7 @@ export default class bithumb extends Exchange {
261
261
  },
262
262
  'cost': {}, // set via options
263
263
  },
264
+ 'created': undefined,
264
265
  'info': market,
265
266
  }, extension);
266
267
  result.push(entry);
@@ -256,6 +256,18 @@ export default class bitmart extends Exchange {
256
256
  fetchPosition(symbol: string, params?: {}): Promise<import("./base/types.js").Position>;
257
257
  fetchPositions(symbols?: string[], params?: {}): Promise<import("./base/types.js").Position[]>;
258
258
  parsePosition(position: any, market?: any): import("./base/types.js").Position;
259
+ fetchMyLiquidations(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Liquidation[]>;
260
+ parseLiquidation(liquidation: any, market?: any): {
261
+ info: any;
262
+ symbol: any;
263
+ contracts: number;
264
+ contractSize: number;
265
+ price: number;
266
+ baseValue: number;
267
+ quoteValue: number;
268
+ timestamp: number;
269
+ datetime: string;
270
+ };
259
271
  nonce(): number;
260
272
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
261
273
  url: string;
package/js/src/bitmart.js CHANGED
@@ -63,8 +63,10 @@ export default class bitmart extends Exchange {
63
63
  'fetchFundingRate': true,
64
64
  'fetchFundingRateHistory': false,
65
65
  'fetchFundingRates': false,
66
+ 'fetchLiquidations': false,
66
67
  'fetchMarginMode': false,
67
68
  'fetchMarkets': true,
69
+ 'fetchMyLiquidations': true,
68
70
  'fetchMyTrades': true,
69
71
  'fetchOHLCV': true,
70
72
  'fetchOpenInterest': true,
@@ -3937,6 +3939,107 @@ export default class bitmart extends Exchange {
3937
3939
  'takeProfitPrice': undefined,
3938
3940
  });
3939
3941
  }
3942
+ async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3943
+ /**
3944
+ * @method
3945
+ * @name bitmart#fetchMyLiquidations
3946
+ * @description retrieves the users liquidated positions
3947
+ * @see https://developer-pro.bitmart.com/en/futures/#get-order-history-keyed
3948
+ * @param {string} symbol unified CCXT market symbol
3949
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
3950
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
3951
+ * @param {object} [params] exchange specific parameters for the bitmart api endpoint
3952
+ * @param {int} [params.until] timestamp in ms of the latest liquidation
3953
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
3954
+ */
3955
+ this.checkRequiredSymbol('fetchMyLiquidations', symbol);
3956
+ await this.loadMarkets();
3957
+ const market = this.market(symbol);
3958
+ if (!market['swap']) {
3959
+ throw new NotSupported(this.id + ' fetchMyLiquidations() supports swap markets only');
3960
+ }
3961
+ let request = {
3962
+ 'symbol': market['id'],
3963
+ };
3964
+ if (since !== undefined) {
3965
+ request['start_time'] = since;
3966
+ }
3967
+ [request, params] = this.handleUntilOption('end_time', request, params);
3968
+ const response = await this.privateGetContractPrivateOrderHistory(this.extend(request, params));
3969
+ //
3970
+ // {
3971
+ // "code": 1000,
3972
+ // "message": "Ok",
3973
+ // "data": [
3974
+ // {
3975
+ // "order_id": "231007865458273",
3976
+ // "client_order_id": "",
3977
+ // "price": "27407.9",
3978
+ // "size": "1",
3979
+ // "symbol": "BTCUSDT",
3980
+ // "state": 4,
3981
+ // "side": 3,
3982
+ // "type": "liquidate",
3983
+ // "leverage": "10",
3984
+ // "open_type": "isolated",
3985
+ // "deal_avg_price": "27422.6",
3986
+ // "deal_size": "1",
3987
+ // "create_time": 1696405864011,
3988
+ // "update_time": 1696405864045
3989
+ // },
3990
+ // ],
3991
+ // "trace": "4cad855074664097ac6ba4257c47305d.71.16965658195443021"
3992
+ // }
3993
+ //
3994
+ const data = this.safeValue(response, 'data', []);
3995
+ const result = [];
3996
+ for (let i = 0; i < data.length; i++) {
3997
+ const entry = data[i];
3998
+ const checkLiquidation = this.safeString(entry, 'type');
3999
+ if (checkLiquidation === 'liquidate') {
4000
+ result.push(entry);
4001
+ }
4002
+ }
4003
+ return this.parseLiquidations(result, market, since, limit);
4004
+ }
4005
+ parseLiquidation(liquidation, market = undefined) {
4006
+ //
4007
+ // {
4008
+ // "order_id": "231007865458273",
4009
+ // "client_order_id": "",
4010
+ // "price": "27407.9",
4011
+ // "size": "1",
4012
+ // "symbol": "BTCUSDT",
4013
+ // "state": 4,
4014
+ // "side": 3,
4015
+ // "type": "market",
4016
+ // "leverage": "10",
4017
+ // "open_type": "isolated",
4018
+ // "deal_avg_price": "27422.6",
4019
+ // "deal_size": "1",
4020
+ // "create_time": 1696405864011,
4021
+ // "update_time": 1696405864045
4022
+ // }
4023
+ //
4024
+ const marketId = this.safeString(liquidation, 'symbol');
4025
+ const timestamp = this.safeInteger(liquidation, 'update_time');
4026
+ const contractsString = this.safeString(liquidation, 'deal_size');
4027
+ const contractSizeString = this.safeString(market, 'contractSize');
4028
+ const priceString = this.safeString(liquidation, 'deal_avg_price');
4029
+ const baseValueString = Precise.stringMul(contractsString, contractSizeString);
4030
+ const quoteValueString = Precise.stringMul(baseValueString, priceString);
4031
+ return {
4032
+ 'info': liquidation,
4033
+ 'symbol': this.safeSymbol(marketId, market),
4034
+ 'contracts': this.parseNumber(contractsString),
4035
+ 'contractSize': this.parseNumber(contractSizeString),
4036
+ 'price': this.parseNumber(priceString),
4037
+ 'baseValue': this.parseNumber(baseValueString),
4038
+ 'quoteValue': this.parseNumber(quoteValueString),
4039
+ 'timestamp': timestamp,
4040
+ 'datetime': this.iso8601(timestamp),
4041
+ };
4042
+ }
3940
4043
  nonce() {
3941
4044
  return this.milliseconds();
3942
4045
  }
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bitmex.js';
2
- import { Int, OrderSide, OrderType, Trade, OHLCV, Order } from './base/types.js';
2
+ import { Int, OrderSide, OrderType, Trade, OHLCV, Order, Liquidation } from './base/types.js';
3
3
  /**
4
4
  * @class bitmex
5
5
  * @extends Exchange
@@ -163,6 +163,18 @@ export default class bitmex extends Exchange {
163
163
  };
164
164
  fetchDepositWithdrawFees(codes?: string[], params?: {}): Promise<any>;
165
165
  calculateRateLimiterCost(api: any, method: any, path: any, params: any, config?: {}): any;
166
+ fetchLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
167
+ parseLiquidation(liquidation: any, market?: any): {
168
+ info: any;
169
+ symbol: any;
170
+ contracts: any;
171
+ contractSize: number;
172
+ price: number;
173
+ baseValue: any;
174
+ quoteValue: any;
175
+ timestamp: any;
176
+ datetime: any;
177
+ };
166
178
  handleErrors(code: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
167
179
  nonce(): number;
168
180
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
package/js/src/bitmex.js CHANGED
@@ -61,9 +61,11 @@ export default class bitmex extends Exchange {
61
61
  'fetchLedger': true,
62
62
  'fetchLeverage': false,
63
63
  'fetchLeverageTiers': false,
64
+ 'fetchLiquidations': true,
64
65
  'fetchMarketLeverageTiers': false,
65
66
  'fetchMarkets': true,
66
67
  'fetchMarkOHLCV': false,
68
+ 'fetchMyLiquidations': false,
67
69
  'fetchMyTrades': true,
68
70
  'fetchOHLCV': true,
69
71
  'fetchOpenOrders': true,
@@ -2651,6 +2653,74 @@ export default class bitmex extends Exchange {
2651
2653
  }
2652
2654
  return cost;
2653
2655
  }
2656
+ async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
2657
+ /**
2658
+ * @method
2659
+ * @name bitmex#fetchLiquidations
2660
+ * @description retrieves the public liquidations of a trading pair
2661
+ * @see https://www.bitmex.com/api/explorer/#!/Liquidation/Liquidation_get
2662
+ * @param {string} symbol unified CCXT market symbol
2663
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
2664
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
2665
+ * @param {object} [params] exchange specific parameters for the bitmex api endpoint
2666
+ * @param {int} [params.until] timestamp in ms of the latest liquidation
2667
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2668
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
2669
+ */
2670
+ await this.loadMarkets();
2671
+ let paginate = false;
2672
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchLiquidations', 'paginate');
2673
+ if (paginate) {
2674
+ return await this.fetchPaginatedCallDynamic('fetchLiquidations', symbol, since, limit, params);
2675
+ }
2676
+ const market = this.market(symbol);
2677
+ let request = {
2678
+ 'symbol': market['id'],
2679
+ };
2680
+ if (since !== undefined) {
2681
+ request['startTime'] = since;
2682
+ }
2683
+ if (limit !== undefined) {
2684
+ request['count'] = limit;
2685
+ }
2686
+ [request, params] = this.handleUntilOption('endTime', request, params);
2687
+ const response = await this.publicGetLiquidation(this.extend(request, params));
2688
+ //
2689
+ // [
2690
+ // {
2691
+ // "orderID": "string",
2692
+ // "symbol": "string",
2693
+ // "side": "string",
2694
+ // "price": 0,
2695
+ // "leavesQty": 0
2696
+ // }
2697
+ // ]
2698
+ //
2699
+ return this.parseLiquidations(response, market, since, limit);
2700
+ }
2701
+ parseLiquidation(liquidation, market = undefined) {
2702
+ //
2703
+ // {
2704
+ // "orderID": "string",
2705
+ // "symbol": "string",
2706
+ // "side": "string",
2707
+ // "price": 0,
2708
+ // "leavesQty": 0
2709
+ // }
2710
+ //
2711
+ const marketId = this.safeString(liquidation, 'symbol');
2712
+ return {
2713
+ 'info': liquidation,
2714
+ 'symbol': this.safeSymbol(marketId, market),
2715
+ 'contracts': undefined,
2716
+ 'contractSize': this.safeNumber(market, 'contractSize'),
2717
+ 'price': this.safeNumber(liquidation, 'price'),
2718
+ 'baseValue': undefined,
2719
+ 'quoteValue': undefined,
2720
+ 'timestamp': undefined,
2721
+ 'datetime': undefined,
2722
+ };
2723
+ }
2654
2724
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2655
2725
  if (response === undefined) {
2656
2726
  return undefined;
package/js/src/bitopro.js CHANGED
@@ -361,6 +361,7 @@ export default class bitopro extends Exchange {
361
361
  'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'basePrecision'))),
362
362
  },
363
363
  'active': active,
364
+ 'created': undefined,
364
365
  'info': market,
365
366
  });
366
367
  }
@@ -433,6 +433,7 @@ export default class bitpanda extends Exchange {
433
433
  'max': undefined,
434
434
  },
435
435
  },
436
+ 'created': undefined,
436
437
  'info': market,
437
438
  });
438
439
  }
package/js/src/bitrue.js CHANGED
@@ -705,6 +705,7 @@ export default class bitrue extends Exchange {
705
705
  'max': undefined,
706
706
  },
707
707
  },
708
+ 'created': undefined,
708
709
  'info': market,
709
710
  };
710
711
  result.push(entry);
package/js/src/bitso.js CHANGED
@@ -471,6 +471,7 @@ export default class bitso extends Exchange {
471
471
  'max': this.safeNumber(market, 'maximum_value'),
472
472
  },
473
473
  },
474
+ 'created': undefined,
474
475
  'info': market,
475
476
  }, fee));
476
477
  }
@@ -508,6 +508,7 @@ export default class bitstamp extends Exchange {
508
508
  'max': undefined,
509
509
  },
510
510
  },
511
+ 'created': undefined,
511
512
  'info': market,
512
513
  });
513
514
  }
package/js/src/bitvavo.js CHANGED
@@ -387,6 +387,7 @@ export default class bitvavo extends Exchange {
387
387
  'max': undefined,
388
388
  },
389
389
  },
390
+ 'created': undefined,
390
391
  'info': market,
391
392
  });
392
393
  }
@@ -349,6 +349,7 @@ export default class blockchaincom extends Exchange {
349
349
  'max': undefined,
350
350
  },
351
351
  },
352
+ 'created': undefined,
352
353
  });
353
354
  }
354
355
  return result;
@@ -229,6 +229,7 @@ export default class btcalpha extends Exchange {
229
229
  'max': undefined,
230
230
  },
231
231
  },
232
+ 'created': undefined,
232
233
  'info': market,
233
234
  });
234
235
  }
@@ -434,6 +434,7 @@ export default class btcmarkets extends Exchange {
434
434
  'max': undefined,
435
435
  },
436
436
  },
437
+ 'created': undefined,
437
438
  'info': market,
438
439
  });
439
440
  }
package/js/src/btcturk.js CHANGED
@@ -262,6 +262,7 @@ export default class btcturk extends Exchange {
262
262
  'max': undefined,
263
263
  },
264
264
  },
265
+ 'created': undefined,
265
266
  'info': entry,
266
267
  });
267
268
  }
package/js/src/bybit.js CHANGED
@@ -2777,7 +2777,7 @@ export default class bybit extends Exchange {
2777
2777
  const feeToken = this.safeString(trade, 'feeTokenId');
2778
2778
  const feeCurrency = this.safeCurrencyCode(feeToken);
2779
2779
  fee = {
2780
- 'cost': feeCost,
2780
+ 'cost': Precise.stringAbs(feeCost),
2781
2781
  'currency': feeCurrency,
2782
2782
  };
2783
2783
  }
@@ -2943,7 +2943,7 @@ export default class bybit extends Exchange {
2943
2943
  feeCurrencyCode = market['inverse'] ? market['base'] : market['settle'];
2944
2944
  }
2945
2945
  fee = {
2946
- 'cost': feeCostString,
2946
+ 'cost': Precise.stringAbs(feeCostString),
2947
2947
  'currency': feeCurrencyCode,
2948
2948
  };
2949
2949
  }
@@ -5543,7 +5543,7 @@ export default class bybit extends Exchange {
5543
5543
  'referenceAccount': undefined,
5544
5544
  'referenceId': referenceId,
5545
5545
  'status': undefined,
5546
- 'amount': this.parseNumber(amount),
5546
+ 'amount': this.parseNumber(Precise.stringAbs(amount)),
5547
5547
  'before': this.parseNumber(before),
5548
5548
  'after': this.parseNumber(after),
5549
5549
  'fee': this.parseNumber(this.safeString(item, 'fee')),
@@ -182,6 +182,20 @@ export default class deribit extends Exchange {
182
182
  previousFundingTimestamp: any;
183
183
  previousFundingDatetime: any;
184
184
  };
185
+ fetchLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
186
+ addPaginationCursorToResult(cursor: any, data: any): any;
187
+ fetchMyLiquidations(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Liquidation[]>;
188
+ parseLiquidation(liquidation: any, market?: any): {
189
+ info: any;
190
+ symbol: any;
191
+ contracts: any;
192
+ contractSize: number;
193
+ price: any;
194
+ baseValue: number;
195
+ quoteValue: any;
196
+ timestamp: number;
197
+ datetime: string;
198
+ };
185
199
  nonce(): number;
186
200
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
187
201
  url: string;
package/js/src/deribit.js CHANGED
@@ -61,9 +61,11 @@ export default class deribit extends Exchange {
61
61
  'fetchFundingRateHistory': true,
62
62
  'fetchIndexOHLCV': false,
63
63
  'fetchLeverageTiers': false,
64
+ 'fetchLiquidations': true,
64
65
  'fetchMarginMode': false,
65
66
  'fetchMarkets': true,
66
67
  'fetchMarkOHLCV': false,
68
+ 'fetchMyLiquidations': true,
67
69
  'fetchMySettlementHistory': false,
68
70
  'fetchMyTrades': true,
69
71
  'fetchOHLCV': true,
@@ -2917,6 +2919,167 @@ export default class deribit extends Exchange {
2917
2919
  'previousFundingDatetime': undefined,
2918
2920
  };
2919
2921
  }
2922
+ async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
2923
+ /**
2924
+ * @method
2925
+ * @name deribit#fetchLiquidations
2926
+ * @description retrieves the public liquidations of a trading pair
2927
+ * @see https://docs.deribit.com/#public-get_last_settlements_by_currency
2928
+ * @param {string} symbol unified CCXT market symbol
2929
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
2930
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
2931
+ * @param {object} [params] exchange specific parameters for the deribit api endpoint
2932
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2933
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
2934
+ */
2935
+ await this.loadMarkets();
2936
+ let paginate = false;
2937
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchLiquidations', 'paginate');
2938
+ if (paginate) {
2939
+ return await this.fetchPaginatedCallCursor('fetchLiquidations', symbol, since, limit, params, 'continuation', 'continuation', undefined);
2940
+ }
2941
+ const market = this.market(symbol);
2942
+ if (market['spot']) {
2943
+ throw new NotSupported(this.id + ' fetchLiquidations() does not support ' + market['type'] + ' markets');
2944
+ }
2945
+ const request = {
2946
+ 'instrument_name': market['id'],
2947
+ 'type': 'bankruptcy',
2948
+ };
2949
+ if (since !== undefined) {
2950
+ request['search_start_timestamp'] = since;
2951
+ }
2952
+ if (limit !== undefined) {
2953
+ request['count'] = limit;
2954
+ }
2955
+ const response = await this.publicGetGetLastSettlementsByInstrument(this.extend(request, params));
2956
+ //
2957
+ // {
2958
+ // "jsonrpc": "2.0",
2959
+ // "result": {
2960
+ // "settlements": [
2961
+ // {
2962
+ // "type": "bankruptcy",
2963
+ // "timestamp": 1696579200041,
2964
+ // "funded": 10000.0,
2965
+ // "session_bankrupcy": 10000.0
2966
+ // "session_profit_loss": 112951.68715857354,
2967
+ // "session_tax": 0.15,
2968
+ // "session_tax_rate": 0.0015,
2969
+ // "socialized": 0.001,
2970
+ // },
2971
+ // ],
2972
+ // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
2973
+ // },
2974
+ // "usIn": 1696652052254890,
2975
+ // "usOut": 1696652052255733,
2976
+ // "usDiff": 843,
2977
+ // "testnet": false
2978
+ // }
2979
+ //
2980
+ const result = this.safeValue(response, 'result', {});
2981
+ const cursor = this.safeString(result, 'continuation');
2982
+ const settlements = this.safeValue(result, 'settlements', []);
2983
+ const settlementsWithCursor = this.addPaginationCursorToResult(cursor, settlements);
2984
+ return this.parseLiquidations(settlementsWithCursor, market, since, limit);
2985
+ }
2986
+ addPaginationCursorToResult(cursor, data) {
2987
+ if (cursor !== undefined) {
2988
+ const dataLength = data.length;
2989
+ if (dataLength > 0) {
2990
+ const first = data[0];
2991
+ const last = data[dataLength - 1];
2992
+ first['continuation'] = cursor;
2993
+ last['continuation'] = cursor;
2994
+ data[0] = first;
2995
+ data[dataLength - 1] = last;
2996
+ }
2997
+ }
2998
+ return data;
2999
+ }
3000
+ async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3001
+ /**
3002
+ * @method
3003
+ * @name deribit#fetchMyLiquidations
3004
+ * @description retrieves the users liquidated positions
3005
+ * @see https://docs.deribit.com/#private-get_settlement_history_by_instrument
3006
+ * @param {string} symbol unified CCXT market symbol
3007
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
3008
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
3009
+ * @param {object} [params] exchange specific parameters for the deribit api endpoint
3010
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
3011
+ */
3012
+ this.checkRequiredSymbol('fetchMyLiquidations', symbol);
3013
+ await this.loadMarkets();
3014
+ const market = this.market(symbol);
3015
+ if (market['spot']) {
3016
+ throw new NotSupported(this.id + ' fetchMyLiquidations() does not support ' + market['type'] + ' markets');
3017
+ }
3018
+ const request = {
3019
+ 'instrument_name': market['id'],
3020
+ 'type': 'bankruptcy',
3021
+ };
3022
+ if (since !== undefined) {
3023
+ request['search_start_timestamp'] = since;
3024
+ }
3025
+ if (limit !== undefined) {
3026
+ request['count'] = limit;
3027
+ }
3028
+ const response = await this.privateGetGetSettlementHistoryByInstrument(this.extend(request, params));
3029
+ //
3030
+ // {
3031
+ // "jsonrpc": "2.0",
3032
+ // "result": {
3033
+ // "settlements": [
3034
+ // {
3035
+ // "type": "bankruptcy",
3036
+ // "timestamp": 1696579200041,
3037
+ // "funded": 10000.0,
3038
+ // "session_bankrupcy": 10000.0
3039
+ // "session_profit_loss": 112951.68715857354,
3040
+ // "session_tax": 0.15,
3041
+ // "session_tax_rate": 0.0015,
3042
+ // "socialized": 0.001,
3043
+ // },
3044
+ // ],
3045
+ // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
3046
+ // },
3047
+ // "usIn": 1696652052254890,
3048
+ // "usOut": 1696652052255733,
3049
+ // "usDiff": 843,
3050
+ // "testnet": false
3051
+ // }
3052
+ //
3053
+ const result = this.safeValue(response, 'result', {});
3054
+ const settlements = this.safeValue(result, 'settlements', []);
3055
+ return this.parseLiquidations(settlements, market, since, limit);
3056
+ }
3057
+ parseLiquidation(liquidation, market = undefined) {
3058
+ //
3059
+ // {
3060
+ // "type": "bankruptcy",
3061
+ // "timestamp": 1696579200041,
3062
+ // "funded": 1,
3063
+ // "session_bankrupcy": 0.001,
3064
+ // "session_profit_loss": 0.001,
3065
+ // "session_tax": 0.0015,
3066
+ // "session_tax_rate": 0.0015,
3067
+ // "socialized": 0.001,
3068
+ // }
3069
+ //
3070
+ const timestamp = this.safeInteger(liquidation, 'timestamp');
3071
+ return {
3072
+ 'info': liquidation,
3073
+ 'symbol': this.safeSymbol(undefined, market),
3074
+ 'contracts': undefined,
3075
+ 'contractSize': this.safeNumber(market, 'contractSize'),
3076
+ 'price': undefined,
3077
+ 'baseValue': this.safeNumber(liquidation, 'session_bankrupcy'),
3078
+ 'quoteValue': undefined,
3079
+ 'timestamp': timestamp,
3080
+ 'datetime': this.iso8601(timestamp),
3081
+ };
3082
+ }
2920
3083
  nonce() {
2921
3084
  return this.milliseconds();
2922
3085
  }
package/js/src/gate.d.ts CHANGED
@@ -411,5 +411,18 @@ export default class gate extends Exchange {
411
411
  parseLedgerEntryType(type: any): string;
412
412
  setPositionMode(hedged: any, symbol?: any, params?: {}): Promise<any>;
413
413
  fetchUnderlyingAssets(params?: {}): Promise<any[]>;
414
+ fetchLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Liquidation[]>;
415
+ fetchMyLiquidations(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Liquidation[]>;
416
+ parseLiquidation(liquidation: any, market?: any): {
417
+ info: any;
418
+ symbol: any;
419
+ contracts: number;
420
+ contractSize: number;
421
+ price: number;
422
+ baseValue: number;
423
+ quoteValue: number;
424
+ timestamp: number;
425
+ datetime: string;
426
+ };
414
427
  handleErrors(code: any, reason: any, url: any, method: any, headers: any, body: any, response: any, requestHeaders: any, requestBody: any): any;
415
428
  }