ccxt 4.1.11 → 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 (96) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +1056 -66
  3. package/dist/ccxt.browser.min.js +3 -3
  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 +310 -37
  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 +20 -4
  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 +15 -9
  32. package/dist/cjs/src/cryptocom.js +1 -1
  33. package/dist/cjs/src/delta.js +2 -2
  34. package/dist/cjs/src/deribit.js +163 -0
  35. package/dist/cjs/src/gate.js +189 -0
  36. package/dist/cjs/src/huobi.js +105 -4
  37. package/dist/cjs/src/kucoin.js +1 -0
  38. package/dist/cjs/src/kucoinfutures.js +1 -1
  39. package/dist/cjs/src/okx.js +2 -0
  40. package/dist/cjs/src/poloniex.js +21 -7
  41. package/dist/cjs/src/whitebit.js +1 -0
  42. package/js/ccxt.d.ts +3 -3
  43. package/js/ccxt.js +1 -1
  44. package/js/src/abstract/poloniex.d.ts +18 -5
  45. package/js/src/ace.js +1 -0
  46. package/js/src/alpaca.js +1 -0
  47. package/js/src/base/Exchange.d.ts +6 -2
  48. package/js/src/base/Exchange.js +30 -0
  49. package/js/src/base/types.d.ts +9 -0
  50. package/js/src/bigone.js +1 -0
  51. package/js/src/binance.d.ts +13 -1
  52. package/js/src/binance.js +310 -37
  53. package/js/src/bingx.d.ts +1 -0
  54. package/js/src/bingx.js +1 -0
  55. package/js/src/bitbank.js +1 -0
  56. package/js/src/bitbns.js +1 -0
  57. package/js/src/bitfinex.js +1 -0
  58. package/js/src/bitfinex2.js +1 -0
  59. package/js/src/bitflyer.js +1 -0
  60. package/js/src/bitforex.js +1 -0
  61. package/js/src/bitget.js +20 -4
  62. package/js/src/bithumb.js +1 -0
  63. package/js/src/bitmart.d.ts +12 -0
  64. package/js/src/bitmart.js +103 -0
  65. package/js/src/bitmex.d.ts +13 -1
  66. package/js/src/bitmex.js +70 -0
  67. package/js/src/bitopro.js +1 -0
  68. package/js/src/bitpanda.js +1 -0
  69. package/js/src/bitrue.js +1 -0
  70. package/js/src/bitso.js +1 -0
  71. package/js/src/bitstamp.js +1 -0
  72. package/js/src/bitvavo.js +1 -0
  73. package/js/src/blockchaincom.js +1 -0
  74. package/js/src/btcalpha.js +1 -0
  75. package/js/src/btcmarkets.js +1 -0
  76. package/js/src/btcturk.js +1 -0
  77. package/js/src/bybit.d.ts +3 -3
  78. package/js/src/bybit.js +15 -9
  79. package/js/src/cryptocom.d.ts +1 -1
  80. package/js/src/cryptocom.js +1 -1
  81. package/js/src/delta.d.ts +2 -54
  82. package/js/src/delta.js +2 -2
  83. package/js/src/deribit.d.ts +14 -0
  84. package/js/src/deribit.js +163 -0
  85. package/js/src/gate.d.ts +13 -0
  86. package/js/src/gate.js +189 -0
  87. package/js/src/huobi.d.ts +13 -1
  88. package/js/src/huobi.js +105 -4
  89. package/js/src/kucoin.js +1 -0
  90. package/js/src/kucoinfutures.js +1 -1
  91. package/js/src/mexc.d.ts +4 -4
  92. package/js/src/okx.js +2 -0
  93. package/js/src/poloniex.js +21 -7
  94. package/js/src/whitebit.js +1 -0
  95. package/package.json +1 -1
  96. package/skip-tests.json +61 -5
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
  }
package/js/src/gate.js CHANGED
@@ -108,10 +108,12 @@ export default class gate extends Exchange {
108
108
  'fetchLedger': true,
109
109
  'fetchLeverage': false,
110
110
  'fetchLeverageTiers': true,
111
+ 'fetchLiquidations': true,
111
112
  'fetchMarginMode': false,
112
113
  'fetchMarketLeverageTiers': 'emulated',
113
114
  'fetchMarkets': true,
114
115
  'fetchMarkOHLCV': true,
116
+ 'fetchMyLiquidations': true,
115
117
  'fetchMySettlementHistory': true,
116
118
  'fetchMyTrades': true,
117
119
  'fetchNetworkDepositAddress': true,
@@ -6329,6 +6331,193 @@ export default class gate extends Exchange {
6329
6331
  }
6330
6332
  return underlyings;
6331
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 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 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.stringAbs(contractsStringRaw);
6502
+ const contractSizeString = this.safeString(market, 'contractSize');
6503
+ const priceString = this.safeString2(liquidation, 'liq_price', 'fill_price');
6504
+ const baseValueString = Precise.stringMul(contractsString, contractSizeString);
6505
+ let quoteValueString = this.safeString(liquidation, 'pnl');
6506
+ if (quoteValueString === undefined) {
6507
+ quoteValueString = Precise.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.stringAbs(quoteValueString)),
6517
+ 'timestamp': timestamp,
6518
+ 'datetime': this.iso8601(timestamp),
6519
+ };
6520
+ }
6332
6521
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
6333
6522
  if (response === undefined) {
6334
6523
  return undefined;
package/js/src/huobi.d.ts CHANGED
@@ -269,7 +269,7 @@ export default class huobi extends Exchange {
269
269
  };
270
270
  parsePosition(position: any, market?: any): import("./base/types.js").Position;
271
271
  fetchPositions(symbols?: string[], params?: {}): Promise<import("./base/types.js").Position[]>;
272
- fetchPosition(symbol: string, params?: {}): Promise<any>;
272
+ fetchPosition(symbol: string, params?: {}): Promise<import("./base/types.js").Position>;
273
273
  parseLedgerEntryType(type: any): string;
274
274
  parseLedgerEntry(item: any, currency?: any): {
275
275
  id: string;
@@ -317,4 +317,16 @@ export default class huobi extends Exchange {
317
317
  timestamp: number;
318
318
  datetime: string;
319
319
  };
320
+ fetchLiquidations(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").Liquidation[]>;
321
+ parseLiquidation(liquidation: any, market?: any): {
322
+ info: any;
323
+ symbol: any;
324
+ contracts: number;
325
+ contractSize: number;
326
+ price: number;
327
+ baseValue: number;
328
+ quoteValue: number;
329
+ timestamp: number;
330
+ datetime: string;
331
+ };
320
332
  }
package/js/src/huobi.js CHANGED
@@ -75,9 +75,11 @@ export default class huobi extends Exchange {
75
75
  'fetchLedgerEntry': undefined,
76
76
  'fetchLeverage': false,
77
77
  'fetchLeverageTiers': true,
78
+ 'fetchLiquidations': true,
78
79
  'fetchMarketLeverageTiers': true,
79
80
  'fetchMarkets': true,
80
81
  'fetchMarkOHLCV': true,
82
+ 'fetchMyLiquidations': false,
81
83
  'fetchMyTrades': true,
82
84
  'fetchOHLCV': true,
83
85
  'fetchOpenInterest': true,
@@ -7218,10 +7220,9 @@ export default class huobi extends Exchange {
7218
7220
  }
7219
7221
  const timestamp = this.safeInteger(response, 'ts');
7220
7222
  const parsed = this.parsePosition(this.extend(position, omitted));
7221
- return this.extend(parsed, {
7222
- 'timestamp': timestamp,
7223
- 'datetime': this.iso8601(timestamp),
7224
- });
7223
+ parsed['timestamp'] = timestamp;
7224
+ parsed['datetime'] = this.iso8601(timestamp);
7225
+ return parsed;
7225
7226
  }
7226
7227
  parseLedgerEntryType(type) {
7227
7228
  const types = {
@@ -8231,4 +8232,104 @@ export default class huobi extends Exchange {
8231
8232
  'datetime': this.iso8601(timestamp),
8232
8233
  };
8233
8234
  }
8235
+ async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
8236
+ /**
8237
+ * @method
8238
+ * @name huobi#fetchLiquidations
8239
+ * @description retrieves the public liquidations of a trading pair
8240
+ * @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-liquidation-orders-new
8241
+ * @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-liquidation-orders-new
8242
+ * @see https://huobiapi.github.io/docs/dm/v1/en/#query-liquidation-order-information-new
8243
+ * @param {string} symbol unified CCXT market symbol
8244
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
8245
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
8246
+ * @param {object} [params] exchange specific parameters for the huobi api endpoint
8247
+ * @param {int} [params.until] timestamp in ms of the latest liquidation
8248
+ * @param {int} [params.tradeType] default 0, linear swap 0: all liquidated orders, 5: liquidated longs; 6: liquidated shorts, inverse swap and future 0: filled liquidated orders, 5: liquidated close orders, 6: liquidated open orders
8249
+ * @returns {object} an array of [liquidation structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure}
8250
+ */
8251
+ await this.loadMarkets();
8252
+ const market = this.market(symbol);
8253
+ const tradeType = this.safeInteger(params, 'trade_type', 0);
8254
+ let request = {
8255
+ 'trade_type': tradeType,
8256
+ };
8257
+ if (since !== undefined) {
8258
+ request['start_time'] = since;
8259
+ }
8260
+ [request, params] = this.handleUntilOption('end_time', request, params);
8261
+ let response = undefined;
8262
+ if (market['swap']) {
8263
+ request['contract'] = market['id'];
8264
+ if (market['linear']) {
8265
+ response = await this.contractPublicGetLinearSwapApiV3SwapLiquidationOrders(this.extend(request, params));
8266
+ }
8267
+ else {
8268
+ response = await this.contractPublicGetSwapApiV3SwapLiquidationOrders(this.extend(request, params));
8269
+ }
8270
+ }
8271
+ else if (market['future']) {
8272
+ request['symbol'] = market['id'];
8273
+ response = await this.contractPublicGetApiV3ContractLiquidationOrders(this.extend(request, params));
8274
+ }
8275
+ else {
8276
+ throw new NotSupported(this.id + ' fetchLiquidations() does not support ' + market['type'] + ' orders');
8277
+ }
8278
+ //
8279
+ // {
8280
+ // "code": 200,
8281
+ // "msg": "",
8282
+ // "data": [
8283
+ // {
8284
+ // "query_id": 452057,
8285
+ // "contract_code": "BTC-USDT-211210",
8286
+ // "symbol": "USDT",
8287
+ // "direction": "sell",
8288
+ // "offset": "close",
8289
+ // "volume": 479.000000000000000000,
8290
+ // "price": 51441.700000000000000000,
8291
+ // "created_at": 1638593647864,
8292
+ // "amount": 0.479000000000000000,
8293
+ // "trade_turnover": 24640.574300000000000000,
8294
+ // "business_type": "futures",
8295
+ // "pair": "BTC-USDT"
8296
+ // }
8297
+ // ],
8298
+ // "ts": 1604312615051
8299
+ // }
8300
+ //
8301
+ const data = this.safeValue(response, 'data', []);
8302
+ return this.parseLiquidations(data, market, since, limit);
8303
+ }
8304
+ parseLiquidation(liquidation, market = undefined) {
8305
+ //
8306
+ // {
8307
+ // "query_id": 452057,
8308
+ // "contract_code": "BTC-USDT-211210",
8309
+ // "symbol": "USDT",
8310
+ // "direction": "sell",
8311
+ // "offset": "close",
8312
+ // "volume": 479.000000000000000000,
8313
+ // "price": 51441.700000000000000000,
8314
+ // "created_at": 1638593647864,
8315
+ // "amount": 0.479000000000000000,
8316
+ // "trade_turnover": 24640.574300000000000000,
8317
+ // "business_type": "futures",
8318
+ // "pair": "BTC-USDT"
8319
+ // }
8320
+ //
8321
+ const marketId = this.safeString(liquidation, 'contract_code');
8322
+ const timestamp = this.safeInteger(liquidation, 'created_at');
8323
+ return {
8324
+ 'info': liquidation,
8325
+ 'symbol': this.safeSymbol(marketId, market),
8326
+ 'contracts': this.safeNumber(liquidation, 'volume'),
8327
+ 'contractSize': this.safeNumber(market, 'contractSize'),
8328
+ 'price': this.safeNumber(liquidation, 'price'),
8329
+ 'baseValue': this.safeNumber(liquidation, 'amount'),
8330
+ 'quoteValue': this.safeNumber(liquidation, 'trade_turnover'),
8331
+ 'timestamp': timestamp,
8332
+ 'datetime': this.iso8601(timestamp),
8333
+ };
8334
+ }
8234
8335
  }
package/js/src/kucoin.js CHANGED
@@ -1200,6 +1200,7 @@ export default class kucoin extends Exchange {
1200
1200
  'id': accountId,
1201
1201
  'type': type,
1202
1202
  'currency': code,
1203
+ 'code': code,
1203
1204
  'info': account,
1204
1205
  });
1205
1206
  }
@@ -1036,7 +1036,7 @@ export default class kucoinfutures extends kucoin {
1036
1036
  //
1037
1037
  const symbol = this.safeString(position, 'symbol');
1038
1038
  market = this.safeMarket(symbol, market);
1039
- const timestamp = this.safeNumber(position, 'currentTimestamp');
1039
+ const timestamp = this.safeInteger(position, 'currentTimestamp');
1040
1040
  const size = this.safeString(position, 'currentQty');
1041
1041
  let side = undefined;
1042
1042
  if (Precise.stringGt(size, '0')) {
package/js/src/mexc.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/mexc.js';
2
- import { IndexType, Int, OrderSide, Balances, OrderType, OHLCV, FundingRateHistory } from './base/types.js';
2
+ import { IndexType, Int, OrderSide, Balances, OrderType, OHLCV, FundingRateHistory, Position } from './base/types.js';
3
3
  /**
4
4
  * @class mexc
5
5
  * @extends Exchange
@@ -141,9 +141,9 @@ export default class mexc extends Exchange {
141
141
  fee: any;
142
142
  };
143
143
  parseTransactionStatusByType(status: any, type?: any): string;
144
- fetchPosition(symbol: string, params?: {}): Promise<any>;
145
- fetchPositions(symbols?: string[], params?: {}): Promise<import("./base/types.js").Position[]>;
146
- parsePosition(position: any, market?: any): import("./base/types.js").Position;
144
+ fetchPosition(symbol: string, params?: {}): Promise<Position>;
145
+ fetchPositions(symbols?: string[], params?: {}): Promise<Position[]>;
146
+ parsePosition(position: any, market?: any): Position;
147
147
  fetchTransfer(id: string, since?: Int, limit?: Int, params?: {}): Promise<{
148
148
  info: any;
149
149
  id: string;
package/js/src/okx.js CHANGED
@@ -1241,6 +1241,7 @@ export default class okx extends Exchange {
1241
1241
  'type': type,
1242
1242
  'currency': undefined,
1243
1243
  'info': account,
1244
+ 'code': undefined,
1244
1245
  });
1245
1246
  }
1246
1247
  return result;
@@ -2115,6 +2116,7 @@ export default class okx extends Exchange {
2115
2116
  }
2116
2117
  }
2117
2118
  else if (price === 'index') {
2119
+ request['instId'] = market['info']['instFamily']; // okx index candles require instFamily instead of instId
2118
2120
  if (isHistoryCandles) {
2119
2121
  response = await this.publicGetMarketHistoryIndexCandles(this.extend(request, params));
2120
2122
  }