ccxt 4.1.12 → 4.1.14

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 (152) hide show
  1. package/CHANGELOG.md +219 -0
  2. package/CONTRIBUTING.md +1 -0
  3. package/README.md +3 -3
  4. package/dist/ccxt.browser.js +1242 -120
  5. package/dist/ccxt.browser.min.js +3 -3
  6. package/dist/cjs/ccxt.js +1 -1
  7. package/dist/cjs/src/ace.js +1 -0
  8. package/dist/cjs/src/alpaca.js +1 -0
  9. package/dist/cjs/src/ascendex.js +1 -0
  10. package/dist/cjs/src/base/Exchange.js +30 -0
  11. package/dist/cjs/src/bigone.js +1 -0
  12. package/dist/cjs/src/binance.js +237 -3
  13. package/dist/cjs/src/bingx.js +5 -2
  14. package/dist/cjs/src/bitbank.js +1 -0
  15. package/dist/cjs/src/bitbns.js +1 -0
  16. package/dist/cjs/src/bitfinex.js +1 -0
  17. package/dist/cjs/src/bitfinex2.js +1 -0
  18. package/dist/cjs/src/bitflyer.js +1 -0
  19. package/dist/cjs/src/bitforex.js +1 -0
  20. package/dist/cjs/src/bitget.js +203 -3
  21. package/dist/cjs/src/bithumb.js +1 -0
  22. package/dist/cjs/src/bitmart.js +105 -0
  23. package/dist/cjs/src/bitmex.js +70 -0
  24. package/dist/cjs/src/bitopro.js +1 -0
  25. package/dist/cjs/src/bitpanda.js +1 -0
  26. package/dist/cjs/src/bitrue.js +1 -0
  27. package/dist/cjs/src/bitso.js +1 -0
  28. package/dist/cjs/src/bitstamp.js +1 -0
  29. package/dist/cjs/src/bittrex.js +6 -0
  30. package/dist/cjs/src/bitvavo.js +1 -0
  31. package/dist/cjs/src/blockchaincom.js +1 -0
  32. package/dist/cjs/src/btcalpha.js +1 -0
  33. package/dist/cjs/src/btcmarkets.js +1 -0
  34. package/dist/cjs/src/btcturk.js +1 -0
  35. package/dist/cjs/src/bybit.js +3 -3
  36. package/dist/cjs/src/cex.js +1 -0
  37. package/dist/cjs/src/coinbase.js +1 -0
  38. package/dist/cjs/src/coinbasepro.js +1 -0
  39. package/dist/cjs/src/coinex.js +2 -0
  40. package/dist/cjs/src/coinfalcon.js +1 -0
  41. package/dist/cjs/src/coinmate.js +1 -0
  42. package/dist/cjs/src/coinone.js +2 -1
  43. package/dist/cjs/src/cryptocom.js +25 -87
  44. package/dist/cjs/src/currencycom.js +1 -0
  45. package/dist/cjs/src/delta.js +1 -0
  46. package/dist/cjs/src/deribit.js +164 -0
  47. package/dist/cjs/src/digifinex.js +1 -0
  48. package/dist/cjs/src/exmo.js +1 -0
  49. package/dist/cjs/src/gate.js +192 -0
  50. package/dist/cjs/src/gemini.js +1 -0
  51. package/dist/cjs/src/hitbtc.js +1 -0
  52. package/dist/cjs/src/hollaex.js +1 -0
  53. package/dist/cjs/src/huobi.js +102 -0
  54. package/dist/cjs/src/huobijp.js +1 -0
  55. package/dist/cjs/src/idex.js +1 -0
  56. package/dist/cjs/src/independentreserve.js +1 -0
  57. package/dist/cjs/src/indodax.js +1 -0
  58. package/dist/cjs/src/kraken.js +9 -0
  59. package/dist/cjs/src/krakenfutures.js +1 -0
  60. package/dist/cjs/src/kucoin.js +1 -0
  61. package/dist/cjs/src/kucoinfutures.js +1 -1
  62. package/dist/cjs/src/latoken.js +1 -0
  63. package/dist/cjs/src/okx.js +1 -0
  64. package/dist/cjs/src/poloniex.js +21 -7
  65. package/dist/cjs/src/poloniexfutures.js +8 -2
  66. package/dist/cjs/src/pro/krakenfutures.js +14 -10
  67. package/dist/cjs/src/woo.js +1 -0
  68. package/js/ccxt.d.ts +3 -3
  69. package/js/ccxt.js +1 -1
  70. package/js/src/abstract/binance.d.ts +4 -0
  71. package/js/src/abstract/binancecoinm.d.ts +4 -0
  72. package/js/src/abstract/binanceus.d.ts +4 -0
  73. package/js/src/abstract/binanceusdm.d.ts +4 -0
  74. package/js/src/abstract/kraken.d.ts +8 -0
  75. package/js/src/abstract/poloniex.d.ts +18 -5
  76. package/js/src/abstract/poloniexfutures.d.ts +6 -1
  77. package/js/src/ace.js +1 -0
  78. package/js/src/alpaca.js +1 -0
  79. package/js/src/ascendex.js +1 -0
  80. package/js/src/base/Exchange.d.ts +6 -2
  81. package/js/src/base/Exchange.js +30 -0
  82. package/js/src/base/types.d.ts +9 -0
  83. package/js/src/bigone.js +1 -0
  84. package/js/src/binance.d.ts +13 -1
  85. package/js/src/binance.js +237 -3
  86. package/js/src/bingx.d.ts +1 -0
  87. package/js/src/bingx.js +5 -2
  88. package/js/src/bitbank.js +1 -0
  89. package/js/src/bitbns.js +1 -0
  90. package/js/src/bitfinex.js +1 -0
  91. package/js/src/bitfinex2.js +1 -0
  92. package/js/src/bitflyer.js +1 -0
  93. package/js/src/bitforex.js +1 -0
  94. package/js/src/bitget.d.ts +28 -0
  95. package/js/src/bitget.js +203 -3
  96. package/js/src/bithumb.js +1 -0
  97. package/js/src/bitmart.d.ts +12 -0
  98. package/js/src/bitmart.js +105 -0
  99. package/js/src/bitmex.d.ts +13 -1
  100. package/js/src/bitmex.js +70 -0
  101. package/js/src/bitopro.js +1 -0
  102. package/js/src/bitpanda.js +1 -0
  103. package/js/src/bitrue.js +1 -0
  104. package/js/src/bitso.js +1 -0
  105. package/js/src/bitstamp.js +1 -0
  106. package/js/src/bittrex.d.ts +2 -2
  107. package/js/src/bittrex.js +6 -0
  108. package/js/src/bitvavo.js +1 -0
  109. package/js/src/blockchaincom.js +1 -0
  110. package/js/src/btcalpha.js +1 -0
  111. package/js/src/btcmarkets.js +1 -0
  112. package/js/src/btcturk.js +1 -0
  113. package/js/src/bybit.js +3 -3
  114. package/js/src/cex.js +1 -0
  115. package/js/src/coinbase.js +1 -0
  116. package/js/src/coinbasepro.js +1 -0
  117. package/js/src/coinex.js +2 -0
  118. package/js/src/coinfalcon.js +1 -0
  119. package/js/src/coinmate.js +1 -0
  120. package/js/src/coinone.js +2 -1
  121. package/js/src/cryptocom.d.ts +0 -2
  122. package/js/src/cryptocom.js +25 -87
  123. package/js/src/currencycom.js +1 -0
  124. package/js/src/delta.js +1 -0
  125. package/js/src/deribit.d.ts +14 -0
  126. package/js/src/deribit.js +164 -0
  127. package/js/src/digifinex.js +1 -0
  128. package/js/src/exmo.js +1 -0
  129. package/js/src/gate.d.ts +14 -0
  130. package/js/src/gate.js +192 -0
  131. package/js/src/gemini.d.ts +1 -0
  132. package/js/src/gemini.js +1 -0
  133. package/js/src/hitbtc.js +1 -0
  134. package/js/src/hollaex.js +1 -0
  135. package/js/src/huobi.d.ts +12 -0
  136. package/js/src/huobi.js +102 -0
  137. package/js/src/huobijp.js +1 -0
  138. package/js/src/idex.js +1 -0
  139. package/js/src/independentreserve.js +1 -0
  140. package/js/src/indodax.js +1 -0
  141. package/js/src/kraken.js +9 -0
  142. package/js/src/krakenfutures.js +1 -0
  143. package/js/src/kucoin.js +1 -0
  144. package/js/src/kucoinfutures.js +1 -1
  145. package/js/src/latoken.js +1 -0
  146. package/js/src/okx.js +1 -0
  147. package/js/src/poloniex.js +21 -7
  148. package/js/src/poloniexfutures.js +8 -2
  149. package/js/src/pro/krakenfutures.js +14 -10
  150. package/js/src/woo.js +1 -0
  151. package/package.json +1 -1
  152. package/skip-tests.json +94 -12
@@ -213,6 +213,7 @@ class coinfalcon extends coinfalcon$1 {
213
213
  'max': undefined,
214
214
  },
215
215
  },
216
+ 'created': undefined,
216
217
  'info': market,
217
218
  });
218
219
  }
@@ -288,6 +288,7 @@ class coinmate extends coinmate$1 {
288
288
  'max': undefined,
289
289
  },
290
290
  },
291
+ 'created': undefined,
291
292
  'info': market,
292
293
  });
293
294
  }
@@ -229,6 +229,7 @@ class coinone extends coinone$1 {
229
229
  'max': undefined,
230
230
  },
231
231
  },
232
+ 'created': undefined,
232
233
  'info': ticker,
233
234
  });
234
235
  }
@@ -886,7 +887,7 @@ class coinone extends coinone$1 {
886
887
  const payload = this.stringToBase64(json);
887
888
  body = payload;
888
889
  const secret = this.secret.toUpperCase();
889
- const signature = this.hmac(payload, this.encode(secret), sha512.sha512);
890
+ const signature = this.hmac(this.encode(payload), this.encode(secret), sha512.sha512);
890
891
  headers = {
891
892
  'Content-Type': 'application/json',
892
893
  'X-COINONE-PAYLOAD': payload,
@@ -36,11 +36,11 @@ class cryptocom extends cryptocom$1 {
36
36
  'fetchAccounts': true,
37
37
  'fetchBalance': true,
38
38
  'fetchBidsAsks': false,
39
- 'fetchBorrowInterest': true,
39
+ 'fetchBorrowInterest': false,
40
40
  'fetchBorrowRate': false,
41
41
  'fetchBorrowRateHistories': false,
42
42
  'fetchBorrowRateHistory': false,
43
- 'fetchBorrowRates': true,
43
+ 'fetchBorrowRates': false,
44
44
  'fetchClosedOrders': 'emulated',
45
45
  'fetchCurrencies': false,
46
46
  'fetchDepositAddress': true,
@@ -334,6 +334,7 @@ class cryptocom extends cryptocom$1 {
334
334
  'precisionMode': number.TICK_SIZE,
335
335
  'exceptions': {
336
336
  'exact': {
337
+ '219': errors.InvalidOrder,
337
338
  '10001': errors.ExchangeError,
338
339
  '10002': errors.PermissionDenied,
339
340
  '10003': errors.PermissionDenied,
@@ -563,6 +564,7 @@ class cryptocom extends cryptocom$1 {
563
564
  'max': undefined,
564
565
  },
565
566
  },
567
+ 'created': undefined,
566
568
  'info': market,
567
569
  });
568
570
  }
@@ -1055,7 +1057,7 @@ class cryptocom extends cryptocom$1 {
1055
1057
  }
1056
1058
  const postOnly = this.safeValue(params, 'postOnly', false);
1057
1059
  if ((postOnly) || (timeInForce === 'PO')) {
1058
- request['exec_inst'] = 'POST_ONLY';
1060
+ request['exec_inst'] = ['POST_ONLY'];
1059
1061
  request['time_in_force'] = 'GOOD_TILL_CANCEL';
1060
1062
  }
1061
1063
  const triggerPrice = this.safeStringN(params, ['stopPrice', 'triggerPrice', 'ref_price']);
@@ -1863,8 +1865,8 @@ class cryptocom extends cryptocom$1 {
1863
1865
  'close': last,
1864
1866
  'last': last,
1865
1867
  'previousClose': undefined,
1866
- 'change': this.safeString(ticker, 'c'),
1867
- 'percentage': undefined,
1868
+ 'change': undefined,
1869
+ 'percentage': this.safeString(ticker, 'c'),
1868
1870
  'average': undefined,
1869
1871
  'baseVolume': this.safeString(ticker, 'v'),
1870
1872
  'quoteVolume': this.safeString(ticker, 'vv'),
@@ -2008,10 +2010,16 @@ class cryptocom extends cryptocom$1 {
2008
2010
  const created = this.safeInteger(order, 'create_time');
2009
2011
  const marketId = this.safeString(order, 'instrument_name');
2010
2012
  const symbol = this.safeSymbol(marketId, market);
2011
- const execInst = this.safeString(order, 'exec_inst');
2012
- let postOnly = undefined;
2013
+ const execInst = this.safeValue(order, 'exec_inst');
2014
+ let postOnly = false;
2013
2015
  if (execInst !== undefined) {
2014
- postOnly = (execInst === 'POST_ONLY');
2016
+ for (let i = 0; i < execInst.length; i++) {
2017
+ const inst = execInst[i];
2018
+ if (inst === 'POST_ONLY') {
2019
+ postOnly = true;
2020
+ break;
2021
+ }
2022
+ }
2015
2023
  }
2016
2024
  const feeCurrency = this.safeString(order, 'fee_instrument_name');
2017
2025
  return this.safeOrder({
@@ -2244,52 +2252,6 @@ class cryptocom extends cryptocom$1 {
2244
2252
  'info': info,
2245
2253
  };
2246
2254
  }
2247
- async fetchBorrowInterest(code = undefined, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2248
- await this.loadMarkets();
2249
- const request = {};
2250
- let market = undefined;
2251
- let currency = undefined;
2252
- if (symbol !== undefined) {
2253
- market = this.market(symbol);
2254
- }
2255
- if (code !== undefined) {
2256
- currency = this.currency(code);
2257
- request['currency'] = currency['id'];
2258
- }
2259
- if (since !== undefined) {
2260
- request['start_ts'] = since;
2261
- }
2262
- if (limit !== undefined) {
2263
- request['page_size'] = limit;
2264
- }
2265
- const response = await this.v2PrivatePostPrivateMarginGetInterestHistory(this.extend(request, params));
2266
- //
2267
- // {
2268
- // "id": 1656705829020,
2269
- // "method": "private/margin/get-interest-history",
2270
- // "code": 0,
2271
- // "result": {
2272
- // "list": [
2273
- // {
2274
- // "loan_id": "2643528867803765921",
2275
- // "currency": "USDT",
2276
- // "interest": 0.00000004,
2277
- // "time": 1656702899559,
2278
- // "stake_amount": 6,
2279
- // "interest_rate": 0.000025
2280
- // },
2281
- // ]
2282
- // }
2283
- // }
2284
- //
2285
- const data = this.safeValue(response, 'result', {});
2286
- const rows = this.safeValue(data, 'list', []);
2287
- let interest = undefined;
2288
- for (let i = 0; i < rows.length; i++) {
2289
- interest = this.parseBorrowInterests(rows, market);
2290
- }
2291
- return this.filterByCurrencySinceLimit(interest, code, since, limit);
2292
- }
2293
2255
  parseBorrowInterest(info, market = undefined) {
2294
2256
  //
2295
2257
  // {
@@ -2318,38 +2280,6 @@ class cryptocom extends cryptocom$1 {
2318
2280
  'info': info,
2319
2281
  };
2320
2282
  }
2321
- async fetchBorrowRates(params = {}) {
2322
- /**
2323
- * @method
2324
- * @name cryptocom#fetchBorrowRates
2325
- * @description fetch the borrow interest rates of all currencies
2326
- * @param {object} [params] extra parameters specific to the cryptocom api endpoint
2327
- * @returns {object} a list of [borrow rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#borrow-rate-structure}
2328
- */
2329
- await this.loadMarkets();
2330
- const response = await this.v2PrivatePostPrivateMarginGetUserConfig(params);
2331
- //
2332
- // {
2333
- // "id": 1656707947456,
2334
- // "method": "private/margin/get-user-config",
2335
- // "code": 0,
2336
- // "result": {
2337
- // "stake_amount": 6,
2338
- // "currency_configs": [
2339
- // {
2340
- // "currency": "AGLD",
2341
- // "hourly_rate": 0.00003334,
2342
- // "max_borrow_limit": 342.4032393,
2343
- // "min_borrow_limit": 30
2344
- // },
2345
- // ]
2346
- // }
2347
- // }
2348
- //
2349
- const data = this.safeValue(response, 'result', {});
2350
- const rates = this.safeValue(data, 'currency_configs', []);
2351
- return this.parseBorrowRates(rates, 'currency');
2352
- }
2353
2283
  parseBorrowRates(info, codeKey) {
2354
2284
  //
2355
2285
  // {
@@ -3022,7 +2952,15 @@ class cryptocom extends cryptocom$1 {
3022
2952
  const paramsKeys = Object.keys(keysorted);
3023
2953
  let strSortKey = '';
3024
2954
  for (let i = 0; i < paramsKeys.length; i++) {
3025
- strSortKey = strSortKey + paramsKeys[i].toString() + requestParams[paramsKeys[i]].toString();
2955
+ const key = paramsKeys[i].toString();
2956
+ let value = requestParams[paramsKeys[i]];
2957
+ if (Array.isArray(value)) {
2958
+ value = value.join(',');
2959
+ }
2960
+ else {
2961
+ value = value.toString();
2962
+ }
2963
+ strSortKey = strSortKey + key + value;
3026
2964
  }
3027
2965
  const payload = path + nonce + this.apiKey + strSortKey + nonce;
3028
2966
  const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256);
@@ -567,6 +567,7 @@ class currencycom extends currencycom$1 {
567
567
  'max': undefined,
568
568
  },
569
569
  },
570
+ 'created': undefined,
570
571
  'info': market,
571
572
  });
572
573
  }
@@ -819,6 +819,7 @@ class delta extends delta$1 {
819
819
  'max': undefined,
820
820
  },
821
821
  },
822
+ 'created': this.parse8601(this.safeString(market, 'launch_time')),
822
823
  'info': market,
823
824
  });
824
825
  }
@@ -58,9 +58,11 @@ class deribit extends deribit$1 {
58
58
  'fetchFundingRateHistory': true,
59
59
  'fetchIndexOHLCV': false,
60
60
  'fetchLeverageTiers': false,
61
+ 'fetchLiquidations': true,
61
62
  'fetchMarginMode': false,
62
63
  'fetchMarkets': true,
63
64
  'fetchMarkOHLCV': false,
65
+ 'fetchMyLiquidations': true,
64
66
  'fetchMySettlementHistory': false,
65
67
  'fetchMyTrades': true,
66
68
  'fetchOHLCV': true,
@@ -809,6 +811,7 @@ class deribit extends deribit$1 {
809
811
  'max': undefined,
810
812
  },
811
813
  },
814
+ 'created': this.safeInteger(market, 'creation_timestamp'),
812
815
  'info': market,
813
816
  });
814
817
  }
@@ -2914,6 +2917,167 @@ class deribit extends deribit$1 {
2914
2917
  'previousFundingDatetime': undefined,
2915
2918
  };
2916
2919
  }
2920
+ async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
2921
+ /**
2922
+ * @method
2923
+ * @name deribit#fetchLiquidations
2924
+ * @description retrieves the public liquidations of a trading pair
2925
+ * @see https://docs.deribit.com/#public-get_last_settlements_by_currency
2926
+ * @param {string} symbol unified CCXT market symbol
2927
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
2928
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
2929
+ * @param {object} [params] exchange specific parameters for the deribit api endpoint
2930
+ * @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)
2931
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
2932
+ */
2933
+ await this.loadMarkets();
2934
+ let paginate = false;
2935
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchLiquidations', 'paginate');
2936
+ if (paginate) {
2937
+ return await this.fetchPaginatedCallCursor('fetchLiquidations', symbol, since, limit, params, 'continuation', 'continuation', undefined);
2938
+ }
2939
+ const market = this.market(symbol);
2940
+ if (market['spot']) {
2941
+ throw new errors.NotSupported(this.id + ' fetchLiquidations() does not support ' + market['type'] + ' markets');
2942
+ }
2943
+ const request = {
2944
+ 'instrument_name': market['id'],
2945
+ 'type': 'bankruptcy',
2946
+ };
2947
+ if (since !== undefined) {
2948
+ request['search_start_timestamp'] = since;
2949
+ }
2950
+ if (limit !== undefined) {
2951
+ request['count'] = limit;
2952
+ }
2953
+ const response = await this.publicGetGetLastSettlementsByInstrument(this.extend(request, params));
2954
+ //
2955
+ // {
2956
+ // "jsonrpc": "2.0",
2957
+ // "result": {
2958
+ // "settlements": [
2959
+ // {
2960
+ // "type": "bankruptcy",
2961
+ // "timestamp": 1696579200041,
2962
+ // "funded": 10000.0,
2963
+ // "session_bankrupcy": 10000.0
2964
+ // "session_profit_loss": 112951.68715857354,
2965
+ // "session_tax": 0.15,
2966
+ // "session_tax_rate": 0.0015,
2967
+ // "socialized": 0.001,
2968
+ // },
2969
+ // ],
2970
+ // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
2971
+ // },
2972
+ // "usIn": 1696652052254890,
2973
+ // "usOut": 1696652052255733,
2974
+ // "usDiff": 843,
2975
+ // "testnet": false
2976
+ // }
2977
+ //
2978
+ const result = this.safeValue(response, 'result', {});
2979
+ const cursor = this.safeString(result, 'continuation');
2980
+ const settlements = this.safeValue(result, 'settlements', []);
2981
+ const settlementsWithCursor = this.addPaginationCursorToResult(cursor, settlements);
2982
+ return this.parseLiquidations(settlementsWithCursor, market, since, limit);
2983
+ }
2984
+ addPaginationCursorToResult(cursor, data) {
2985
+ if (cursor !== undefined) {
2986
+ const dataLength = data.length;
2987
+ if (dataLength > 0) {
2988
+ const first = data[0];
2989
+ const last = data[dataLength - 1];
2990
+ first['continuation'] = cursor;
2991
+ last['continuation'] = cursor;
2992
+ data[0] = first;
2993
+ data[dataLength - 1] = last;
2994
+ }
2995
+ }
2996
+ return data;
2997
+ }
2998
+ async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2999
+ /**
3000
+ * @method
3001
+ * @name deribit#fetchMyLiquidations
3002
+ * @description retrieves the users liquidated positions
3003
+ * @see https://docs.deribit.com/#private-get_settlement_history_by_instrument
3004
+ * @param {string} symbol unified CCXT market symbol
3005
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
3006
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
3007
+ * @param {object} [params] exchange specific parameters for the deribit api endpoint
3008
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
3009
+ */
3010
+ this.checkRequiredSymbol('fetchMyLiquidations', symbol);
3011
+ await this.loadMarkets();
3012
+ const market = this.market(symbol);
3013
+ if (market['spot']) {
3014
+ throw new errors.NotSupported(this.id + ' fetchMyLiquidations() does not support ' + market['type'] + ' markets');
3015
+ }
3016
+ const request = {
3017
+ 'instrument_name': market['id'],
3018
+ 'type': 'bankruptcy',
3019
+ };
3020
+ if (since !== undefined) {
3021
+ request['search_start_timestamp'] = since;
3022
+ }
3023
+ if (limit !== undefined) {
3024
+ request['count'] = limit;
3025
+ }
3026
+ const response = await this.privateGetGetSettlementHistoryByInstrument(this.extend(request, params));
3027
+ //
3028
+ // {
3029
+ // "jsonrpc": "2.0",
3030
+ // "result": {
3031
+ // "settlements": [
3032
+ // {
3033
+ // "type": "bankruptcy",
3034
+ // "timestamp": 1696579200041,
3035
+ // "funded": 10000.0,
3036
+ // "session_bankrupcy": 10000.0
3037
+ // "session_profit_loss": 112951.68715857354,
3038
+ // "session_tax": 0.15,
3039
+ // "session_tax_rate": 0.0015,
3040
+ // "socialized": 0.001,
3041
+ // },
3042
+ // ],
3043
+ // "continuation": "5dHzoGyD8Hs8KURoUhfgXgHpJTA5oyapoudSmNeAfEftqRbjNE6jNNUpo2oCu1khnZL9ao"
3044
+ // },
3045
+ // "usIn": 1696652052254890,
3046
+ // "usOut": 1696652052255733,
3047
+ // "usDiff": 843,
3048
+ // "testnet": false
3049
+ // }
3050
+ //
3051
+ const result = this.safeValue(response, 'result', {});
3052
+ const settlements = this.safeValue(result, 'settlements', []);
3053
+ return this.parseLiquidations(settlements, market, since, limit);
3054
+ }
3055
+ parseLiquidation(liquidation, market = undefined) {
3056
+ //
3057
+ // {
3058
+ // "type": "bankruptcy",
3059
+ // "timestamp": 1696579200041,
3060
+ // "funded": 1,
3061
+ // "session_bankrupcy": 0.001,
3062
+ // "session_profit_loss": 0.001,
3063
+ // "session_tax": 0.0015,
3064
+ // "session_tax_rate": 0.0015,
3065
+ // "socialized": 0.001,
3066
+ // }
3067
+ //
3068
+ const timestamp = this.safeInteger(liquidation, 'timestamp');
3069
+ return {
3070
+ 'info': liquidation,
3071
+ 'symbol': this.safeSymbol(undefined, market),
3072
+ 'contracts': undefined,
3073
+ 'contractSize': this.safeNumber(market, 'contractSize'),
3074
+ 'price': undefined,
3075
+ 'baseValue': this.safeNumber(liquidation, 'session_bankrupcy'),
3076
+ 'quoteValue': undefined,
3077
+ 'timestamp': timestamp,
3078
+ 'datetime': this.iso8601(timestamp),
3079
+ };
3080
+ }
2917
3081
  nonce() {
2918
3082
  return this.milliseconds();
2919
3083
  }
@@ -653,6 +653,7 @@ class digifinex extends digifinex$1 {
653
653
  'max': undefined,
654
654
  },
655
655
  },
656
+ 'created': undefined,
656
657
  'info': market,
657
658
  });
658
659
  }
@@ -826,6 +826,7 @@ class exmo extends exmo$1 {
826
826
  'max': this.safeNumber(market, 'max_amount'),
827
827
  },
828
828
  },
829
+ 'created': undefined,
829
830
  'info': market,
830
831
  });
831
832
  }
@@ -105,10 +105,12 @@ class gate extends gate$1 {
105
105
  'fetchLedger': true,
106
106
  'fetchLeverage': false,
107
107
  'fetchLeverageTiers': true,
108
+ 'fetchLiquidations': true,
108
109
  'fetchMarginMode': false,
109
110
  'fetchMarketLeverageTiers': 'emulated',
110
111
  'fetchMarkets': true,
111
112
  'fetchMarkOHLCV': true,
113
+ 'fetchMyLiquidations': true,
112
114
  'fetchMySettlementHistory': true,
113
115
  'fetchMyTrades': true,
114
116
  'fetchNetworkDepositAddress': true,
@@ -1093,6 +1095,7 @@ class gate extends gate$1 {
1093
1095
  'max': margin ? this.safeNumber(market, 'max_quote_amount') : undefined,
1094
1096
  },
1095
1097
  },
1098
+ 'created': undefined,
1096
1099
  'info': market,
1097
1100
  });
1098
1101
  }
@@ -1290,6 +1293,7 @@ class gate extends gate$1 {
1290
1293
  'max': undefined,
1291
1294
  },
1292
1295
  },
1296
+ 'created': undefined,
1293
1297
  'info': market,
1294
1298
  };
1295
1299
  }
@@ -1410,6 +1414,7 @@ class gate extends gate$1 {
1410
1414
  'max': undefined,
1411
1415
  },
1412
1416
  },
1417
+ 'created': this.safeIntegerProduct(market, 'create_time', 1000),
1413
1418
  'info': market,
1414
1419
  });
1415
1420
  }
@@ -6326,6 +6331,193 @@ class gate extends gate$1 {
6326
6331
  }
6327
6332
  return underlyings;
6328
6333
  }
6334
+ async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
6335
+ /**
6336
+ * @method
6337
+ * @name gate#fetchLiquidations
6338
+ * @description retrieves the public liquidations of a trading pair
6339
+ * @see https://www.gate.io/docs/developers/apiv4/en/#retrieve-liquidation-history
6340
+ * @param {string} symbol unified CCXT market symbol
6341
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
6342
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
6343
+ * @param {object} [params] exchange specific parameters for the gate api endpoint
6344
+ * @param {int} [params.until] timestamp in ms of the latest liquidation
6345
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
6346
+ */
6347
+ await this.loadMarkets();
6348
+ const market = this.market(symbol);
6349
+ if (!market['swap']) {
6350
+ throw new errors.NotSupported(this.id + ' fetchLiquidations() supports swap markets only');
6351
+ }
6352
+ let request = {
6353
+ 'settle': market['settleId'],
6354
+ 'contract': market['id'],
6355
+ };
6356
+ if (since !== undefined) {
6357
+ request['from'] = since;
6358
+ }
6359
+ if (limit !== undefined) {
6360
+ request['limit'] = limit;
6361
+ }
6362
+ [request, params] = this.handleUntilOption('to', request, params);
6363
+ const response = await this.publicFuturesGetSettleLiqOrders(this.extend(request, params));
6364
+ //
6365
+ // [
6366
+ // {
6367
+ // "contract": "BTC_USDT",
6368
+ // "left": 0,
6369
+ // "size": -165,
6370
+ // "fill_price": "28070",
6371
+ // "order_price": "28225",
6372
+ // "time": 1696736132
6373
+ // },
6374
+ // ]
6375
+ //
6376
+ return this.parseLiquidations(response, market, since, limit);
6377
+ }
6378
+ async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
6379
+ /**
6380
+ * @method
6381
+ * @name gate#fetchMyLiquidations
6382
+ * @description retrieves the users liquidated positions
6383
+ * @see https://www.gate.io/docs/developers/apiv4/en/#list-liquidation-history
6384
+ * @see https://www.gate.io/docs/developers/apiv4/en/#list-liquidation-history-2
6385
+ * @see https://www.gate.io/docs/developers/apiv4/en/#list-user-s-liquidation-history-of-specified-underlying
6386
+ * @param {string} symbol unified CCXT market symbol
6387
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
6388
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
6389
+ * @param {object} [params] exchange specific parameters for the gate api endpoint
6390
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
6391
+ */
6392
+ this.checkRequiredSymbol('fetchMyLiquidations', symbol);
6393
+ await this.loadMarkets();
6394
+ const market = this.market(symbol);
6395
+ const request = {
6396
+ 'contract': market['id'],
6397
+ };
6398
+ let response = undefined;
6399
+ if ((market['swap']) || (market['future'])) {
6400
+ if (limit !== undefined) {
6401
+ request['limit'] = limit;
6402
+ }
6403
+ request['settle'] = market['settleId'];
6404
+ }
6405
+ else if (market['option']) {
6406
+ const marketId = market['id'];
6407
+ const optionParts = marketId.split('-');
6408
+ request['underlying'] = this.safeString(optionParts, 0);
6409
+ }
6410
+ if (market['swap']) {
6411
+ response = await this.privateFuturesGetSettleLiquidates(this.extend(request, params));
6412
+ }
6413
+ else if (market['future']) {
6414
+ response = await this.privateDeliveryGetSettleLiquidates(this.extend(request, params));
6415
+ }
6416
+ else if (market['option']) {
6417
+ response = await this.privateOptionsGetPositionClose(this.extend(request, params));
6418
+ }
6419
+ else {
6420
+ throw new errors.NotSupported(this.id + ' fetchMyLiquidations() does not support ' + market['type'] + ' orders');
6421
+ }
6422
+ //
6423
+ // swap and future
6424
+ //
6425
+ // [
6426
+ // {
6427
+ // "time": 1548654951,
6428
+ // "contract": "BTC_USDT",
6429
+ // "size": 600,
6430
+ // "leverage": "25",
6431
+ // "margin": "0.006705256878",
6432
+ // "entry_price": "3536.123",
6433
+ // "liq_price": "3421.54",
6434
+ // "mark_price": "3420.27",
6435
+ // "order_id": 317393847,
6436
+ // "order_price": "3405",
6437
+ // "fill_price": "3424",
6438
+ // "left": 0
6439
+ // }
6440
+ // ]
6441
+ //
6442
+ // option
6443
+ //
6444
+ // [
6445
+ // {
6446
+ // "time": 1631764800,
6447
+ // "pnl": "-42914.291",
6448
+ // "settle_size": "-10001",
6449
+ // "side": "short",
6450
+ // "contract": "BTC_USDT-20210916-5000-C",
6451
+ // "text": "settled"
6452
+ // }
6453
+ // ]
6454
+ //
6455
+ return this.parseLiquidations(response, market, since, limit);
6456
+ }
6457
+ parseLiquidation(liquidation, market = undefined) {
6458
+ //
6459
+ // fetchLiquidations
6460
+ //
6461
+ // {
6462
+ // "contract": "BTC_USDT",
6463
+ // "left": 0,
6464
+ // "size": -165,
6465
+ // "fill_price": "28070",
6466
+ // "order_price": "28225",
6467
+ // "time": 1696736132
6468
+ // }
6469
+ //
6470
+ // swap and future: fetchMyLiquidations
6471
+ //
6472
+ // {
6473
+ // "time": 1548654951,
6474
+ // "contract": "BTC_USDT",
6475
+ // "size": 600,
6476
+ // "leverage": "25",
6477
+ // "margin": "0.006705256878",
6478
+ // "entry_price": "3536.123",
6479
+ // "liq_price": "3421.54",
6480
+ // "mark_price": "3420.27",
6481
+ // "order_id": 317393847,
6482
+ // "order_price": "3405",
6483
+ // "fill_price": "3424",
6484
+ // "left": 0
6485
+ // }
6486
+ //
6487
+ // option: fetchMyLiquidations
6488
+ //
6489
+ // {
6490
+ // "time": 1631764800,
6491
+ // "pnl": "-42914.291",
6492
+ // "settle_size": "-10001",
6493
+ // "side": "short",
6494
+ // "contract": "BTC_USDT-20210916-5000-C",
6495
+ // "text": "settled"
6496
+ // }
6497
+ //
6498
+ const marketId = this.safeString(liquidation, 'contract');
6499
+ const timestamp = this.safeTimestamp(liquidation, 'time');
6500
+ const contractsStringRaw = this.safeString2(liquidation, 'size', 'settle_size');
6501
+ const contractsString = Precise["default"].stringAbs(contractsStringRaw);
6502
+ const contractSizeString = this.safeString(market, 'contractSize');
6503
+ const priceString = this.safeString2(liquidation, 'liq_price', 'fill_price');
6504
+ const baseValueString = Precise["default"].stringMul(contractsString, contractSizeString);
6505
+ let quoteValueString = this.safeString(liquidation, 'pnl');
6506
+ if (quoteValueString === undefined) {
6507
+ quoteValueString = Precise["default"].stringMul(baseValueString, priceString);
6508
+ }
6509
+ return {
6510
+ 'info': liquidation,
6511
+ 'symbol': this.safeSymbol(marketId, market),
6512
+ 'contracts': this.parseNumber(contractsString),
6513
+ 'contractSize': this.parseNumber(contractSizeString),
6514
+ 'price': this.parseNumber(priceString),
6515
+ 'baseValue': this.parseNumber(baseValueString),
6516
+ 'quoteValue': this.parseNumber(Precise["default"].stringAbs(quoteValueString)),
6517
+ 'timestamp': timestamp,
6518
+ 'datetime': this.iso8601(timestamp),
6519
+ };
6520
+ }
6329
6521
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
6330
6522
  if (response === undefined) {
6331
6523
  return undefined;