ccxt 4.1.89 → 4.1.90

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 (52) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +710 -312
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +2 -2
  6. package/dist/cjs/src/bitforex.js +2 -0
  7. package/dist/cjs/src/bitget.js +11 -4
  8. package/dist/cjs/src/bitmex.js +2 -0
  9. package/dist/cjs/src/blockchaincom.js +0 -41
  10. package/dist/cjs/src/bybit.js +29 -14
  11. package/dist/cjs/src/coinlist.js +2 -0
  12. package/dist/cjs/src/coinsph.js +2 -0
  13. package/dist/cjs/src/cryptocom.js +2 -0
  14. package/dist/cjs/src/gate.js +276 -11
  15. package/dist/cjs/src/htx.js +264 -219
  16. package/dist/cjs/src/kuna.js +2 -0
  17. package/dist/cjs/src/mexc.js +2 -0
  18. package/dist/cjs/src/okcoin.js +4 -1
  19. package/dist/cjs/src/phemex.js +54 -1
  20. package/dist/cjs/src/poloniex.js +28 -2
  21. package/dist/cjs/src/pro/binance.js +6 -6
  22. package/dist/cjs/src/pro/poloniex.js +15 -10
  23. package/dist/cjs/src/tokocrypto.js +2 -0
  24. package/dist/cjs/src/wazirx.js +2 -0
  25. package/dist/cjs/src/whitebit.js +2 -0
  26. package/js/ccxt.d.ts +1 -1
  27. package/js/ccxt.js +1 -1
  28. package/js/src/base/Exchange.js +2 -2
  29. package/js/src/bitforex.js +2 -0
  30. package/js/src/bitget.js +11 -4
  31. package/js/src/bitmex.js +2 -0
  32. package/js/src/blockchaincom.d.ts +0 -2
  33. package/js/src/blockchaincom.js +0 -41
  34. package/js/src/bybit.js +29 -14
  35. package/js/src/coinlist.js +2 -0
  36. package/js/src/coinsph.js +2 -0
  37. package/js/src/cryptocom.js +2 -0
  38. package/js/src/gate.d.ts +47 -0
  39. package/js/src/gate.js +276 -11
  40. package/js/src/htx.js +264 -219
  41. package/js/src/kuna.js +2 -0
  42. package/js/src/mexc.js +2 -0
  43. package/js/src/okcoin.js +4 -1
  44. package/js/src/phemex.d.ts +1 -0
  45. package/js/src/phemex.js +54 -1
  46. package/js/src/poloniex.js +28 -2
  47. package/js/src/pro/binance.js +6 -6
  48. package/js/src/pro/poloniex.js +16 -11
  49. package/js/src/tokocrypto.js +2 -0
  50. package/js/src/wazirx.js +2 -0
  51. package/js/src/whitebit.js +2 -0
  52. package/package.json +1 -1
@@ -10664,7 +10664,7 @@ class Exchange {
10664
10664
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10665
10665
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
10666
10666
  */
10667
- if (this.options['createMarketOrderWithCost'] || (this.options['createMarketBuyOrderWithCost'] && this.options['createMarketSellOrderWithCost'])) {
10667
+ if (this.has['createMarketOrderWithCost'] || (this.has['createMarketBuyOrderWithCost'] && this.has['createMarketSellOrderWithCost'])) {
10668
10668
  return await this.createOrder(symbol, 'market', side, cost, 1, params);
10669
10669
  }
10670
10670
  throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.NotSupported(this.id + ' createMarketOrderWithCost() is not supported yet');
@@ -10679,7 +10679,7 @@ class Exchange {
10679
10679
  * @param {object} [params] extra parameters specific to the exchange API endpoint
10680
10680
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
10681
10681
  */
10682
- if (this.options['createMarketBuyOrderRequiresPrice'] || this.options['createMarketBuyOrderWithCost']) {
10682
+ if (this.options['createMarketBuyOrderRequiresPrice'] || this.has['createMarketBuyOrderWithCost']) {
10683
10683
  return await this.createOrder(symbol, 'market', 'buy', cost, 1, params);
10684
10684
  }
10685
10685
  throw new _errors_js__WEBPACK_IMPORTED_MODULE_3__.NotSupported(this.id + ' createMarketBuyOrderWithCost() is not supported yet');
@@ -39418,6 +39418,8 @@ class bitforex extends _abstract_bitforex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
39418
39418
  'fetchWithdrawal': false,
39419
39419
  'fetchWithdrawals': false,
39420
39420
  'reduceMargin': false,
39421
+ 'repayCrossMargin': false,
39422
+ 'repayIsolatedMargin': false,
39421
39423
  'setLeverage': false,
39422
39424
  'setMargin': false,
39423
39425
  'setMarginMode': false,
@@ -44059,7 +44061,7 @@ class bitget extends _abstract_bitget_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
44059
44061
  if (feeCostString !== undefined) {
44060
44062
  // swap
44061
44063
  fee = {
44062
- 'cost': feeCostString,
44064
+ 'cost': this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAbs(feeCostString)),
44063
44065
  'currency': market['settle'],
44064
44066
  };
44065
44067
  }
@@ -44067,10 +44069,17 @@ class bitget extends _abstract_bitget_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
44067
44069
  if (feeDetail !== undefined) {
44068
44070
  const parsedFeeDetail = JSON.parse(feeDetail);
44069
44071
  const feeValues = Object.values(parsedFeeDetail);
44070
- const first = this.safeValue(feeValues, 0);
44072
+ let feeObject = undefined;
44073
+ for (let i = 0; i < feeValues.length; i++) {
44074
+ const feeValue = feeValues[i];
44075
+ if (this.safeValue(feeValue, 'feeCoinCode') !== undefined) {
44076
+ feeObject = feeValue;
44077
+ break;
44078
+ }
44079
+ }
44071
44080
  fee = {
44072
- 'cost': this.safeString(first, 'totalFee'),
44073
- 'currency': this.safeCurrencyCode(this.safeString(first, 'feeCoinCode')),
44081
+ 'cost': this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAbs(this.safeString(feeObject, 'totalFee'))),
44082
+ 'currency': this.safeCurrencyCode(this.safeString(feeObject, 'feeCoinCode')),
44074
44083
  };
44075
44084
  }
44076
44085
  let postOnly = undefined;
@@ -53814,6 +53823,8 @@ class bitmex extends _abstract_bitmex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
53814
53823
  'cancelAllOrders': true,
53815
53824
  'cancelOrder': true,
53816
53825
  'cancelOrders': true,
53826
+ 'closeAllPositions': false,
53827
+ 'closePosition': true,
53817
53828
  'createOrder': true,
53818
53829
  'createReduceOnlyOrder': true,
53819
53830
  'editOrder': true,
@@ -70860,47 +70871,6 @@ class blockchaincom extends _abstract_blockchaincom_js__WEBPACK_IMPORTED_MODULE_
70860
70871
  'fee': fee,
70861
70872
  };
70862
70873
  }
70863
- async fetchWithdrawalWhitelist(params = {}) {
70864
- /**
70865
- * @method
70866
- * @name blockchaincom#fetchWithdrawalWhitelist
70867
- * @description fetch the list of withdrawal addresses on the whitelist
70868
- * @param {object} [params] extra parameters specific to the exchange API endpoint
70869
- * @returns {object} dictionary with keys beneficiaryId, name, currency
70870
- */
70871
- await this.loadMarkets();
70872
- const response = await this.privateGetWhitelist();
70873
- const result = [];
70874
- for (let i = 0; i < response.length; i++) {
70875
- const entry = response[i];
70876
- result.push({
70877
- 'beneficiaryId': this.safeString(entry, 'whitelistId'),
70878
- 'name': this.safeString(entry, 'name'),
70879
- 'currency': this.safeString(entry, 'currency'),
70880
- 'info': entry,
70881
- });
70882
- }
70883
- return result;
70884
- }
70885
- async fetchWithdrawalWhitelistByCurrency(code, params = {}) {
70886
- await this.loadMarkets();
70887
- const currency = this.currency(code);
70888
- const request = {
70889
- 'currency': currency['id'],
70890
- };
70891
- const response = await this.privateGetWhitelistCurrency(this.extend(request, params));
70892
- const result = [];
70893
- for (let i = 0; i < response.length; i++) {
70894
- const entry = response[i];
70895
- result.push({
70896
- 'beneficiaryId': this.safeString(entry, 'whitelistId'),
70897
- 'name': this.safeString(entry, 'name'),
70898
- 'currency': this.safeString(entry, 'currency'),
70899
- 'info': entry,
70900
- });
70901
- }
70902
- return result;
70903
- }
70904
70874
  async withdraw(code, amount, address, tag = undefined, params = {}) {
70905
70875
  /**
70906
70876
  * @method
@@ -75811,6 +75781,7 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
75811
75781
  },
75812
75782
  'precisionMode': _base_functions_number_js__WEBPACK_IMPORTED_MODULE_2__/* .TICK_SIZE */ .sh,
75813
75783
  'options': {
75784
+ 'fetchMarkets': ['spot', 'linear', 'inverse', 'option'],
75814
75785
  'enableUnifiedMargin': undefined,
75815
75786
  'enableUnifiedAccount': undefined,
75816
75787
  'createMarketBuyOrderRequiresPrice': true,
@@ -76316,21 +76287,35 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
76316
76287
  if (this.options['adjustForTimeDifference']) {
76317
76288
  await this.loadTimeDifference();
76318
76289
  }
76319
- const promisesUnresolved = [
76320
- this.fetchSpotMarkets(params),
76321
- this.fetchFutureMarkets({ 'category': 'linear' }),
76322
- this.fetchFutureMarkets({ 'category': 'inverse' }),
76323
- this.fetchOptionMarkets({ 'baseCoin': 'BTC' }),
76324
- this.fetchOptionMarkets({ 'baseCoin': 'ETH' }),
76325
- this.fetchOptionMarkets({ 'baseCoin': 'SOL' }),
76326
- ];
76290
+ const promisesUnresolved = [];
76291
+ const fetchMarkets = this.safeValue(this.options, 'fetchMarkets', ['spot', 'linear', 'inverse']);
76292
+ for (let i = 0; i < fetchMarkets.length; i++) {
76293
+ const marketType = fetchMarkets[i];
76294
+ if (marketType === 'spot') {
76295
+ promisesUnresolved.push(this.fetchSpotMarkets(params));
76296
+ }
76297
+ else if (marketType === 'linear') {
76298
+ promisesUnresolved.push(this.fetchFutureMarkets({ 'category': 'linear' }));
76299
+ }
76300
+ else if (marketType === 'inverse') {
76301
+ promisesUnresolved.push(this.fetchFutureMarkets({ 'category': 'inverse' }));
76302
+ }
76303
+ else if (marketType === 'option') {
76304
+ promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'BTC' }));
76305
+ promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'ETH' }));
76306
+ promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'SOL' }));
76307
+ }
76308
+ else {
76309
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ExchangeError(this.id + ' fetchMarkets() this.options fetchMarkets "' + marketType + '" is not a supported market type');
76310
+ }
76311
+ }
76327
76312
  const promises = await Promise.all(promisesUnresolved);
76328
- const spotMarkets = promises[0];
76329
- const linearMarkets = promises[1];
76330
- const inverseMarkets = promises[2];
76331
- const btcOptionMarkets = promises[3];
76332
- const ethOptionMarkets = promises[4];
76333
- const solOptionMarkets = promises[5];
76313
+ const spotMarkets = this.safeValue(promises, 0, []);
76314
+ const linearMarkets = this.safeValue(promises, 1, []);
76315
+ const inverseMarkets = this.safeValue(promises, 2, []);
76316
+ const btcOptionMarkets = this.safeValue(promises, 3, []);
76317
+ const ethOptionMarkets = this.safeValue(promises, 4, []);
76318
+ const solOptionMarkets = this.safeValue(promises, 5, []);
76334
76319
  const futureMarkets = this.arrayConcat(linearMarkets, inverseMarkets);
76335
76320
  let optionMarkets = this.arrayConcat(btcOptionMarkets, ethOptionMarkets);
76336
76321
  optionMarkets = this.arrayConcat(optionMarkets, solOptionMarkets);
@@ -95645,6 +95630,8 @@ class coinlist extends _abstract_coinlist_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
95645
95630
  'fetchWithdrawals': false,
95646
95631
  'fetchWithdrawalWhitelist': false,
95647
95632
  'reduceMargin': false,
95633
+ 'repayCrossMargin': false,
95634
+ 'repayIsolatedMargin': false,
95648
95635
  'setLeverage': false,
95649
95636
  'setMargin': false,
95650
95637
  'setMarginMode': false,
@@ -99928,6 +99915,8 @@ class coinsph extends _abstract_coinsph_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
99928
99915
  'fetchWithdrawals': true,
99929
99916
  'fetchWithdrawalWhitelist': false,
99930
99917
  'reduceMargin': false,
99918
+ 'repayCrossMargin': false,
99919
+ 'repayIsolatedMargin': false,
99931
99920
  'setLeverage': false,
99932
99921
  'setMargin': false,
99933
99922
  'setMarginMode': false,
@@ -102398,6 +102387,8 @@ class cryptocom extends _abstract_cryptocom_js__WEBPACK_IMPORTED_MODULE_0__/* ["
102398
102387
  'fetchVolatilityHistory': false,
102399
102388
  'fetchWithdrawals': true,
102400
102389
  'reduceMargin': false,
102390
+ 'repayCrossMargin': false,
102391
+ 'repayIsolatedMargin': false,
102401
102392
  'setLeverage': false,
102402
102393
  'setMarginMode': false,
102403
102394
  'setPositionMode': false,
@@ -120982,9 +120973,14 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
120982
120973
  'future': true,
120983
120974
  'option': true,
120984
120975
  'addMargin': true,
120976
+ 'borrowCrossMargin': true,
120977
+ 'borrowIsolatedMargin': true,
120985
120978
  'cancelAllOrders': true,
120986
120979
  'cancelOrder': true,
120980
+ 'createMarketBuyOrderWithCost': true,
120987
120981
  'createMarketOrder': true,
120982
+ 'createMarketOrderWithCost': false,
120983
+ 'createMarketSellOrderWithCost': false,
120988
120984
  'createOrder': true,
120989
120985
  'createOrders': true,
120990
120986
  'createPostOnlyOrder': true,
@@ -121046,6 +121042,8 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
121046
121042
  'fetchVolatilityHistory': false,
121047
121043
  'fetchWithdrawals': true,
121048
121044
  'reduceMargin': true,
121045
+ 'repayCrossMargin': true,
121046
+ 'repayIsolatedMargin': true,
121049
121047
  'setLeverage': true,
121050
121048
  'setMarginMode': false,
121051
121049
  'setPositionMode': true,
@@ -124664,6 +124662,7 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
124664
124662
  * @param {bool} [params.close] *contract only* Set as true to close the position, with size set to 0
124665
124663
  * @param {bool} [params.auto_size] *contract only* Set side to close dual-mode position, close_long closes the long side, while close_short the short one, size also needs to be set to 0
124666
124664
  * @param {int} [params.price_type] *contract only* 0 latest deal price, 1 mark price, 2 index price
124665
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
124667
124666
  * @returns {object|undefined} [An order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
124668
124667
  */
124669
124668
  await this.loadMarkets();
@@ -124861,9 +124860,15 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
124861
124860
  }
124862
124861
  }
124863
124862
  if (contract) {
124864
- const amountToPrecision = this.amountToPrecision(symbol, amount);
124865
- const signedAmount = (side === 'sell') ? _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringNeg(amountToPrecision) : amountToPrecision;
124866
- amount = parseInt(signedAmount);
124863
+ const isClose = this.safeValue(params, 'close');
124864
+ if (isClose) {
124865
+ amount = 0;
124866
+ }
124867
+ else {
124868
+ const amountToPrecision = this.amountToPrecision(symbol, amount);
124869
+ const signedAmount = (side === 'sell') ? _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringNeg(amountToPrecision) : amountToPrecision;
124870
+ amount = parseInt(signedAmount);
124871
+ }
124867
124872
  }
124868
124873
  let request = undefined;
124869
124874
  const nonTriggerOrder = !isStopOrder && (trigger === undefined);
@@ -124911,24 +124916,30 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
124911
124916
  // 'auto_borrow': false, // used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
124912
124917
  // 'auto_repay': false, // automatic repayment for automatic borrow loan generated by cross margin order, diabled by default
124913
124918
  };
124914
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
124915
124919
  if (isMarketOrder && (side === 'buy')) {
124916
- if (createMarketBuyOrderRequiresPrice) {
124920
+ let quoteAmount = undefined;
124921
+ let createMarketBuyOrderRequiresPrice = true;
124922
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
124923
+ const cost = this.safeNumber(params, 'cost');
124924
+ params = this.omit(params, 'cost');
124925
+ if (cost !== undefined) {
124926
+ quoteAmount = this.costToPrecision(symbol, cost);
124927
+ }
124928
+ else if (createMarketBuyOrderRequiresPrice) {
124917
124929
  if (price === undefined) {
124918
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders on spot markets to calculate the total amount to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to false and pass in the cost to spend into the amount parameter');
124930
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
124919
124931
  }
124920
124932
  else {
124921
124933
  const amountString = this.numberToString(amount);
124922
124934
  const priceString = this.numberToString(price);
124923
- const cost = this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString));
124924
- request['amount'] = this.costToPrecision(symbol, cost);
124935
+ const costRequest = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
124936
+ quoteAmount = this.costToPrecision(symbol, costRequest);
124925
124937
  }
124926
124938
  }
124927
124939
  else {
124928
- const cost = this.safeNumber(params, 'cost', amount);
124929
- params = this.omit(params, 'cost');
124930
- request['amount'] = this.costToPrecision(symbol, cost);
124940
+ quoteAmount = this.costToPrecision(symbol, amount);
124931
124941
  }
124942
+ request['amount'] = quoteAmount;
124932
124943
  }
124933
124944
  else {
124934
124945
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -125058,6 +125069,25 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
125058
125069
  }
125059
125070
  return this.extend(request, params);
125060
125071
  }
125072
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
125073
+ /**
125074
+ * @method
125075
+ * @name gate#createMarketBuyOrderWithCost
125076
+ * @description create a market buy order by providing the symbol and cost
125077
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-an-order
125078
+ * @param {string} symbol unified symbol of the market to create an order in
125079
+ * @param {float} cost how much you want to trade in units of the quote currency
125080
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
125081
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
125082
+ */
125083
+ await this.loadMarkets();
125084
+ const market = this.market(symbol);
125085
+ if (!market['spot']) {
125086
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
125087
+ }
125088
+ params['createMarketBuyOrderRequiresPrice'] = false;
125089
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
125090
+ }
125061
125091
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
125062
125092
  /**
125063
125093
  * @method
@@ -126643,6 +126673,210 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
126643
126673
  }
126644
126674
  return tiers;
126645
126675
  }
126676
+ async repayIsolatedMargin(symbol, code, amount, params = {}) {
126677
+ /**
126678
+ * @method
126679
+ * @name gate#repayMargin
126680
+ * @description repay borrowed margin and interest
126681
+ * @see https://www.gate.io/docs/apiv4/en/#repay-a-loan
126682
+ * @param {string} symbol unified market symbol
126683
+ * @param {string} code unified currency code of the currency to repay
126684
+ * @param {float} amount the amount to repay
126685
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
126686
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
126687
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
126688
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
126689
+ */
126690
+ await this.loadMarkets();
126691
+ const currency = this.currency(code);
126692
+ const request = {
126693
+ 'currency': currency['id'].toUpperCase(),
126694
+ 'amount': this.currencyToPrecision(code, amount),
126695
+ };
126696
+ const market = this.market(symbol);
126697
+ request['currency_pair'] = market['id'];
126698
+ request['type'] = 'repay';
126699
+ const response = await this.privateMarginPostUniLoans(this.extend(request, params));
126700
+ //
126701
+ // empty response
126702
+ //
126703
+ return this.parseMarginLoan(response, currency);
126704
+ }
126705
+ async repayCrossMargin(code, amount, params = {}) {
126706
+ /**
126707
+ * @method
126708
+ * @name gate#repayCrossMargin
126709
+ * @description repay cross margin borrowed margin and interest
126710
+ * @see https://www.gate.io/docs/developers/apiv4/en/#cross-margin-repayments
126711
+ * @param {string} code unified currency code of the currency to repay
126712
+ * @param {float} amount the amount to repay
126713
+ * @param {string} symbol unified market symbol, required for isolated margin
126714
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
126715
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
126716
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
126717
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
126718
+ */
126719
+ await this.loadMarkets();
126720
+ const currency = this.currency(code);
126721
+ const request = {
126722
+ 'currency': currency['id'].toUpperCase(),
126723
+ 'amount': this.currencyToPrecision(code, amount),
126724
+ };
126725
+ let response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
126726
+ //
126727
+ // [
126728
+ // {
126729
+ // "id": "17",
126730
+ // "create_time": 1620381696159,
126731
+ // "update_time": 1620381696159,
126732
+ // "currency": "EOS",
126733
+ // "amount": "110.553635",
126734
+ // "text": "web",
126735
+ // "status": 2,
126736
+ // "repaid": "110.506649705159",
126737
+ // "repaid_interest": "0.046985294841",
126738
+ // "unpaid_interest": "0.0000074393366667"
126739
+ // }
126740
+ // ]
126741
+ //
126742
+ response = this.safeValue(response, 0);
126743
+ return this.parseMarginLoan(response, currency);
126744
+ }
126745
+ async borrowIsolatedMargin(symbol, code, amount, params = {}) {
126746
+ /**
126747
+ * @method
126748
+ * @name gate#borrowMargin
126749
+ * @description create a loan to borrow margin
126750
+ * @see https://www.gate.io/docs/developers/apiv4/en/#marginuni
126751
+ * @param {string} code unified currency code of the currency to borrow
126752
+ * @param {float} amount the amount to borrow
126753
+ * @param {string} symbol unified market symbol, required for isolated margin
126754
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
126755
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
126756
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
126757
+ */
126758
+ await this.loadMarkets();
126759
+ const currency = this.currency(code);
126760
+ const request = {
126761
+ 'currency': currency['id'].toUpperCase(),
126762
+ 'amount': this.currencyToPrecision(code, amount),
126763
+ };
126764
+ let response = undefined;
126765
+ const market = this.market(symbol);
126766
+ request['currency_pair'] = market['id'];
126767
+ request['type'] = 'borrow';
126768
+ response = await this.privateMarginPostUniLoans(this.extend(request, params));
126769
+ //
126770
+ // {
126771
+ // "id": "34267567",
126772
+ // "create_time": "1656394778",
126773
+ // "expire_time": "1657258778",
126774
+ // "status": "loaned",
126775
+ // "side": "borrow",
126776
+ // "currency": "USDT",
126777
+ // "rate": "0.0002",
126778
+ // "amount": "100",
126779
+ // "days": 10,
126780
+ // "auto_renew": false,
126781
+ // "currency_pair": "LTC_USDT",
126782
+ // "left": "0",
126783
+ // "repaid": "0",
126784
+ // "paid_interest": "0",
126785
+ // "unpaid_interest": "0.003333333333"
126786
+ // }
126787
+ //
126788
+ return this.parseMarginLoan(response, currency);
126789
+ }
126790
+ async borrowCrossMargin(code, amount, params = {}) {
126791
+ /**
126792
+ * @method
126793
+ * @name gate#borrowMargin
126794
+ * @description create a loan to borrow margin
126795
+ * @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
126796
+ * @param {string} code unified currency code of the currency to borrow
126797
+ * @param {float} amount the amount to borrow
126798
+ * @param {string} symbol unified market symbol, required for isolated margin
126799
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
126800
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
126801
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
126802
+ */
126803
+ await this.loadMarkets();
126804
+ const currency = this.currency(code);
126805
+ const request = {
126806
+ 'currency': currency['id'].toUpperCase(),
126807
+ 'amount': this.currencyToPrecision(code, amount),
126808
+ };
126809
+ const response = await this.privateMarginPostCrossLoans(this.extend(request, params));
126810
+ //
126811
+ // {
126812
+ // "id": "17",
126813
+ // "create_time": 1620381696159,
126814
+ // "update_time": 1620381696159,
126815
+ // "currency": "EOS",
126816
+ // "amount": "110.553635",
126817
+ // "text": "web",
126818
+ // "status": 2,
126819
+ // "repaid": "110.506649705159",
126820
+ // "repaid_interest": "0.046985294841",
126821
+ // "unpaid_interest": "0.0000074393366667"
126822
+ // }
126823
+ //
126824
+ return this.parseMarginLoan(response, currency);
126825
+ }
126826
+ parseMarginLoan(info, currency = undefined) {
126827
+ //
126828
+ // Cross
126829
+ //
126830
+ // {
126831
+ // "id": "17",
126832
+ // "create_time": 1620381696159,
126833
+ // "update_time": 1620381696159,
126834
+ // "currency": "EOS",
126835
+ // "amount": "110.553635",
126836
+ // "text": "web",
126837
+ // "status": 2,
126838
+ // "repaid": "110.506649705159",
126839
+ // "repaid_interest": "0.046985294841",
126840
+ // "unpaid_interest": "0.0000074393366667"
126841
+ // }
126842
+ //
126843
+ // Isolated
126844
+ //
126845
+ // {
126846
+ // "id": "34267567",
126847
+ // "create_time": "1656394778",
126848
+ // "expire_time": "1657258778",
126849
+ // "status": "loaned",
126850
+ // "side": "borrow",
126851
+ // "currency": "USDT",
126852
+ // "rate": "0.0002",
126853
+ // "amount": "100",
126854
+ // "days": 10,
126855
+ // "auto_renew": false,
126856
+ // "currency_pair": "LTC_USDT",
126857
+ // "left": "0",
126858
+ // "repaid": "0",
126859
+ // "paid_interest": "0",
126860
+ // "unpaid_interest": "0.003333333333"
126861
+ // }
126862
+ //
126863
+ const marginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
126864
+ let timestamp = this.safeInteger(info, 'create_time');
126865
+ if (marginMode === 'isolated') {
126866
+ timestamp = this.safeTimestamp(info, 'create_time');
126867
+ }
126868
+ const currencyId = this.safeString(info, 'currency');
126869
+ const marketId = this.safeString(info, 'currency_pair');
126870
+ return {
126871
+ 'id': this.safeInteger(info, 'id'),
126872
+ 'currency': this.safeCurrencyCode(currencyId, currency),
126873
+ 'amount': this.safeNumber(info, 'amount'),
126874
+ 'symbol': this.safeSymbol(marketId, undefined, '_', 'margin'),
126875
+ 'timestamp': timestamp,
126876
+ 'datetime': this.iso8601(timestamp),
126877
+ 'info': info,
126878
+ };
126879
+ }
126646
126880
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
126647
126881
  const authentication = api[0]; // public, private
126648
126882
  const type = api[1]; // spot, margin, future, delivery
@@ -127652,6 +127886,28 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
127652
127886
  'info': greeks,
127653
127887
  };
127654
127888
  }
127889
+ async closePosition(symbol, side = undefined, params = {}) {
127890
+ /**
127891
+ * @method
127892
+ * @name gate#closePositions
127893
+ * @description closes open positions for a market
127894
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order
127895
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order-2
127896
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-an-options-order
127897
+ * @param {string} symbol Unified CCXT market symbol
127898
+ * @param {string} side 'buy' or 'sell'
127899
+ * @param {object} [params] extra parameters specific to the okx api endpoint
127900
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
127901
+ */
127902
+ const request = {
127903
+ 'close': true,
127904
+ };
127905
+ params = this.extend(request, params);
127906
+ if (side === undefined) {
127907
+ side = ''; // side is not used but needs to be present, otherwise crashes in php
127908
+ }
127909
+ return await this.createOrder(symbol, 'market', side, 0, undefined, params);
127910
+ }
127655
127911
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
127656
127912
  if (response === undefined) {
127657
127913
  return undefined;
@@ -136290,30 +136546,32 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136290
136546
  await this.loadMarkets();
136291
136547
  let marketType = undefined;
136292
136548
  [marketType, params] = this.handleMarketTypeAndParams('fetchMyTrades', undefined, params);
136293
- let method = 'statusPublicSpotGetApiV2SummaryJson';
136549
+ let response = undefined;
136294
136550
  if (marketType !== 'spot') {
136295
136551
  const subType = this.safeString(params, 'subType', this.options['defaultSubType']);
136296
136552
  if (marketType === 'swap') {
136297
136553
  if (subType === 'linear') {
136298
- method = 'statusPublicSwapLinearGetApiV2SummaryJson';
136554
+ response = await this.statusPublicSwapLinearGetApiV2SummaryJson();
136299
136555
  }
136300
136556
  else if (subType === 'inverse') {
136301
- method = 'statusPublicSwapInverseGetApiV2SummaryJson';
136557
+ response = await this.statusPublicSwapInverseGetApiV2SummaryJson();
136302
136558
  }
136303
136559
  }
136304
136560
  else if (marketType === 'future') {
136305
136561
  if (subType === 'linear') {
136306
- method = 'statusPublicFutureLinearGetApiV2SummaryJson';
136562
+ response = await this.statusPublicFutureLinearGetApiV2SummaryJson();
136307
136563
  }
136308
136564
  else if (subType === 'inverse') {
136309
- method = 'statusPublicFutureInverseGetApiV2SummaryJson';
136565
+ response = await this.statusPublicFutureInverseGetApiV2SummaryJson();
136310
136566
  }
136311
136567
  }
136312
136568
  else if (marketType === 'contract') {
136313
- method = 'contractPublicGetHeartbeat';
136569
+ response = await this.contractPublicGetHeartbeat();
136314
136570
  }
136315
136571
  }
136316
- const response = await this[method]();
136572
+ else {
136573
+ response = await this.statusPublicSpotGetApiV2SummaryJson();
136574
+ }
136317
136575
  //
136318
136576
  // statusPublicSpotGetApiV2SummaryJson, statusPublicSwapInverseGetApiV2SummaryJson, statusPublicFutureLinearGetApiV2SummaryJson, statusPublicFutureInverseGetApiV2SummaryJson
136319
136577
  //
@@ -136478,7 +136736,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136478
136736
  let status = undefined;
136479
136737
  let updated = undefined;
136480
136738
  let url = undefined;
136481
- if (method === 'contractPublicGetHeartbeat') {
136739
+ if (marketType === 'contract') {
136482
136740
  const statusRaw = this.safeString(response, 'status');
136483
136741
  status = (statusRaw === 'ok') ? 'ok' : 'maintenance'; // 'ok', 'error'
136484
136742
  updated = this.safeString(response, 'ts');
@@ -136512,11 +136770,13 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136512
136770
  const defaultType = this.safeString(this.options, 'defaultType', 'spot');
136513
136771
  let type = this.safeString(options, 'type', defaultType);
136514
136772
  type = this.safeString(params, 'type', type);
136515
- let method = 'spotPublicGetV1CommonTimestamp';
136773
+ let response = undefined;
136516
136774
  if ((type === 'future') || (type === 'swap')) {
136517
- method = 'contractPublicGetApiV1Timestamp';
136775
+ response = await this.contractPublicGetApiV1Timestamp(params);
136776
+ }
136777
+ else {
136778
+ response = await this.spotPublicGetV1CommonTimestamp(params);
136518
136779
  }
136519
- const response = await this[method](params);
136520
136780
  //
136521
136781
  // spot
136522
136782
  //
@@ -136684,7 +136944,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136684
136944
  return allMarkets;
136685
136945
  }
136686
136946
  async fetchMarketsByTypeAndSubType(type, subType, params = {}) {
136687
- let method = 'spotPublicGetV1CommonSymbols';
136688
136947
  const query = this.omit(params, ['type', 'subType']);
136689
136948
  const spot = (type === 'spot');
136690
136949
  const contract = (type !== 'spot');
@@ -136693,25 +136952,28 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136693
136952
  let linear = undefined;
136694
136953
  let inverse = undefined;
136695
136954
  const request = {};
136955
+ let response = undefined;
136696
136956
  if (contract) {
136697
136957
  linear = (subType === 'linear');
136698
136958
  inverse = (subType === 'inverse');
136699
136959
  if (linear) {
136700
- method = 'contractPublicGetLinearSwapApiV1SwapContractInfo';
136701
136960
  if (future) {
136702
136961
  request['business_type'] = 'futures';
136703
136962
  }
136963
+ response = await this.contractPublicGetLinearSwapApiV1SwapContractInfo(this.extend(request, query));
136704
136964
  }
136705
136965
  else if (inverse) {
136706
136966
  if (future) {
136707
- method = 'contractPublicGetApiV1ContractContractInfo';
136967
+ response = await this.contractPublicGetApiV1ContractContractInfo(this.extend(request, query));
136708
136968
  }
136709
136969
  else if (swap) {
136710
- method = 'contractPublicGetSwapApiV1SwapContractInfo';
136970
+ response = await this.contractPublicGetSwapApiV1SwapContractInfo(this.extend(request, query));
136711
136971
  }
136712
136972
  }
136713
136973
  }
136714
- const response = await this[method](this.extend(request, query));
136974
+ else {
136975
+ response = await this.spotPublicGetV1CommonSymbols(this.extend(request, query));
136976
+ }
136715
136977
  //
136716
136978
  // spot
136717
136979
  //
@@ -137098,23 +137360,25 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137098
137360
  await this.loadMarkets();
137099
137361
  const market = this.market(symbol);
137100
137362
  const request = {};
137101
- let fieldName = 'symbol';
137102
- let method = 'spotPublicGetMarketDetailMerged';
137363
+ let response = undefined;
137103
137364
  if (market['linear']) {
137104
- method = 'contractPublicGetLinearSwapExMarketDetailMerged';
137105
- fieldName = 'contract_code';
137365
+ request['contract_code'] = market['id'];
137366
+ response = await this.contractPublicGetLinearSwapExMarketDetailMerged(this.extend(request, params));
137106
137367
  }
137107
137368
  else if (market['inverse']) {
137108
137369
  if (market['future']) {
137109
- method = 'contractPublicGetMarketDetailMerged';
137370
+ request['symbol'] = market['id'];
137371
+ response = await this.contractPublicGetMarketDetailMerged(this.extend(request, params));
137110
137372
  }
137111
137373
  else if (market['swap']) {
137112
- method = 'contractPublicGetSwapExMarketDetailMerged';
137113
- fieldName = 'contract_code';
137374
+ request['contract_code'] = market['id'];
137375
+ response = await this.contractPublicGetSwapExMarketDetailMerged(this.extend(request, params));
137114
137376
  }
137115
137377
  }
137116
- request[fieldName] = market['id'];
137117
- const response = await this[method](this.extend(request, params));
137378
+ else {
137379
+ request['symbol'] = market['id'];
137380
+ response = await this.spotPublicGetMarketDetailMerged(this.extend(request, params));
137381
+ }
137118
137382
  //
137119
137383
  // spot
137120
137384
  //
@@ -137187,7 +137451,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137187
137451
  }
137188
137452
  let type = undefined;
137189
137453
  let subType = undefined;
137190
- let method = 'spotPublicGetMarketTickers';
137191
137454
  [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
137192
137455
  [subType, params] = this.handleSubTypeAndParams('fetchTickers', market, params);
137193
137456
  const request = {};
@@ -137195,24 +137458,27 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137195
137458
  const swap = (type === 'swap');
137196
137459
  const linear = (subType === 'linear');
137197
137460
  const inverse = (subType === 'inverse');
137461
+ params = this.omit(params, ['type', 'subType']);
137462
+ let response = undefined;
137198
137463
  if (future || swap) {
137199
137464
  if (linear) {
137200
- method = 'contractPublicGetLinearSwapExMarketDetailBatchMerged';
137201
137465
  if (future) {
137202
137466
  request['business_type'] = 'futures';
137203
137467
  }
137468
+ response = await this.contractPublicGetLinearSwapExMarketDetailBatchMerged(this.extend(request, params));
137204
137469
  }
137205
137470
  else if (inverse) {
137206
137471
  if (future) {
137207
- method = 'contractPublicGetMarketDetailBatchMerged';
137472
+ response = await this.contractPublicGetMarketDetailBatchMerged(this.extend(request, params));
137208
137473
  }
137209
137474
  else if (swap) {
137210
- method = 'contractPublicGetSwapExMarketDetailBatchMerged';
137475
+ response = await this.contractPublicGetSwapExMarketDetailBatchMerged(this.extend(request, params));
137211
137476
  }
137212
137477
  }
137213
137478
  }
137214
- params = this.omit(params, ['type', 'subType']);
137215
- const response = await this[method](this.extend(request, params));
137479
+ else {
137480
+ response = await this.spotPublicGetMarketTickers(this.extend(request, params));
137481
+ }
137216
137482
  //
137217
137483
  // spot
137218
137484
  //
@@ -137345,19 +137611,19 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137345
137611
  // 'symbol': market['id'], // spot, future
137346
137612
  // 'contract_code': market['id'], // swap
137347
137613
  };
137348
- let fieldName = 'symbol';
137349
- let method = 'spotPublicGetMarketDepth';
137614
+ let response = undefined;
137350
137615
  if (market['linear']) {
137351
- method = 'contractPublicGetLinearSwapExMarketDepth';
137352
- fieldName = 'contract_code';
137616
+ request['contract_code'] = market['id'];
137617
+ response = await this.contractPublicGetLinearSwapExMarketDepth(this.extend(request, params));
137353
137618
  }
137354
137619
  else if (market['inverse']) {
137355
137620
  if (market['future']) {
137356
- method = 'contractPublicGetMarketDepth';
137621
+ request['symbol'] = market['id'];
137622
+ response = await this.contractPublicGetMarketDepth(this.extend(request, params));
137357
137623
  }
137358
137624
  else if (market['swap']) {
137359
- method = 'contractPublicGetSwapExMarketDepth';
137360
- fieldName = 'contract_code';
137625
+ request['contract_code'] = market['id'];
137626
+ response = await this.contractPublicGetSwapExMarketDepth(this.extend(request, params));
137361
137627
  }
137362
137628
  }
137363
137629
  else {
@@ -137373,9 +137639,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137373
137639
  request['depth'] = limit;
137374
137640
  }
137375
137641
  }
137642
+ request['symbol'] = market['id'];
137643
+ response = await this.spotPublicGetMarketDepth(this.extend(request, params));
137376
137644
  }
137377
- request[fieldName] = market['id'];
137378
- const response = await this[method](this.extend(request, params));
137379
137645
  //
137380
137646
  // spot, future, swap
137381
137647
  //
@@ -137626,7 +137892,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137626
137892
  // 'direct': 'prev', // next, prev
137627
137893
  // 'size': limit, // default 20, max 50
137628
137894
  };
137629
- let method = undefined;
137895
+ let response = undefined;
137630
137896
  if (marketType === 'spot') {
137631
137897
  if (symbol !== undefined) {
137632
137898
  market = this.market(symbol);
@@ -137640,7 +137906,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137640
137906
  // request['end-time'] = this.sum (since, 172800000); // 48 hours window
137641
137907
  }
137642
137908
  [request, params] = this.handleUntilOption('end-time', request, params);
137643
- method = 'spotPrivateGetV1OrderMatchresults';
137909
+ response = await this.spotPrivateGetV1OrderMatchresults(this.extend(request, params));
137644
137910
  }
137645
137911
  else {
137646
137912
  if (symbol === undefined) {
@@ -137661,26 +137927,25 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137661
137927
  [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
137662
137928
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
137663
137929
  if (marginMode === 'isolated') {
137664
- method = 'contractPrivatePostLinearSwapApiV3SwapMatchresultsExact';
137930
+ response = await this.contractPrivatePostLinearSwapApiV3SwapMatchresultsExact(this.extend(request, params));
137665
137931
  }
137666
137932
  else if (marginMode === 'cross') {
137667
- method = 'contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact';
137933
+ response = await this.contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact(this.extend(request, params));
137668
137934
  }
137669
137935
  }
137670
137936
  else if (market['inverse']) {
137671
137937
  if (marketType === 'future') {
137672
- method = 'contractPrivatePostApiV3ContractMatchresultsExact';
137673
137938
  request['symbol'] = market['settleId'];
137939
+ response = await this.contractPrivatePostApiV3ContractMatchresultsExact(this.extend(request, params));
137674
137940
  }
137675
137941
  else if (marketType === 'swap') {
137676
- method = 'contractPrivatePostSwapApiV3SwapMatchresultsExact';
137942
+ response = await this.contractPrivatePostSwapApiV3SwapMatchresultsExact(this.extend(request, params));
137677
137943
  }
137678
137944
  else {
137679
137945
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchMyTrades() does not support ' + marketType + ' markets');
137680
137946
  }
137681
137947
  }
137682
137948
  }
137683
- const response = await this[method](this.extend(request, params));
137684
137949
  //
137685
137950
  // spot
137686
137951
  //
@@ -137774,31 +138039,33 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137774
138039
  // 'symbol': market['id'], // spot, future
137775
138040
  // 'contract_code': market['id'], // swap
137776
138041
  };
137777
- let fieldName = 'symbol';
137778
- let method = 'spotPublicGetMarketHistoryTrade';
138042
+ if (limit !== undefined) {
138043
+ request['size'] = Math.min(limit, 2000); // max 2000
138044
+ }
138045
+ let response = undefined;
137779
138046
  if (market['future']) {
137780
138047
  if (market['inverse']) {
137781
- method = 'contractPublicGetMarketHistoryTrade';
138048
+ request['symbol'] = market['id'];
138049
+ response = await this.contractPublicGetMarketHistoryTrade(this.extend(request, params));
137782
138050
  }
137783
138051
  else if (market['linear']) {
137784
- method = 'contractPublicGetLinearSwapExMarketHistoryTrade';
137785
- fieldName = 'contract_code';
138052
+ request['contract_code'] = market['id'];
138053
+ response = await this.contractPublicGetLinearSwapExMarketHistoryTrade(this.extend(request, params));
137786
138054
  }
137787
138055
  }
137788
138056
  else if (market['swap']) {
138057
+ request['contract_code'] = market['id'];
137789
138058
  if (market['inverse']) {
137790
- method = 'contractPublicGetSwapExMarketHistoryTrade';
138059
+ response = await this.contractPublicGetSwapExMarketHistoryTrade(this.extend(request, params));
137791
138060
  }
137792
138061
  else if (market['linear']) {
137793
- method = 'contractPublicGetLinearSwapExMarketHistoryTrade';
138062
+ response = await this.contractPublicGetLinearSwapExMarketHistoryTrade(this.extend(request, params));
137794
138063
  }
137795
- fieldName = 'contract_code';
137796
138064
  }
137797
- request[fieldName] = market['id'];
137798
- if (limit !== undefined) {
137799
- request['size'] = Math.min(limit, 2000); // max 2000
138065
+ else {
138066
+ request['symbol'] = market['id'];
138067
+ response = await this.spotPublicGetMarketHistoryTrade(this.extend(request, params));
137800
138068
  }
137801
- const response = await this[method](this.extend(request, params));
137802
138069
  //
137803
138070
  // {
137804
138071
  // "status": "ok",
@@ -137889,109 +138156,111 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137889
138156
  // 'from': parseInt ((since / 1000).toString ()), spot only
137890
138157
  // 'to': this.seconds (), spot only
137891
138158
  };
137892
- let fieldName = 'symbol';
137893
138159
  const price = this.safeString(params, 'price');
137894
138160
  params = this.omit(params, 'price');
137895
- let method = 'spotPublicGetMarketHistoryCandles';
137896
- if (market['spot']) {
137897
- if (timeframe === '1M' || timeframe === '1y') {
137898
- // for some reason 1M and 1Y does not work with the regular endpoint
137899
- // https://github.com/ccxt/ccxt/issues/18006
137900
- method = 'spotPublicGetMarketHistoryKline';
138161
+ if (market['contract']) {
138162
+ if (limit !== undefined) {
138163
+ request['size'] = limit; // when using limit from and to are ignored
138164
+ // https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data
137901
138165
  }
137902
- if (since !== undefined) {
137903
- request['from'] = this.parseToInt(since / 1000);
138166
+ else {
138167
+ limit = 2000; // only used for from/to calculation
137904
138168
  }
137905
- if (limit !== undefined) {
137906
- request['size'] = limit; // max 2000
138169
+ if (price === undefined) {
138170
+ const duration = this.parseTimeframe(timeframe);
138171
+ if (since === undefined) {
138172
+ const now = this.seconds();
138173
+ request['from'] = now - duration * (limit - 1);
138174
+ request['to'] = now;
138175
+ }
138176
+ else {
138177
+ const start = this.parseToInt(since / 1000);
138178
+ request['from'] = start;
138179
+ request['to'] = this.sum(start, duration * (limit - 1));
138180
+ }
137907
138181
  }
137908
138182
  }
137909
- else if (market['future']) {
138183
+ let response = undefined;
138184
+ if (market['future']) {
137910
138185
  if (market['inverse']) {
138186
+ request['symbol'] = market['id'];
137911
138187
  if (price === 'mark') {
137912
- method = 'contractPublicGetIndexMarketHistoryMarkPriceKline';
138188
+ response = await this.contractPublicGetIndexMarketHistoryMarkPriceKline(this.extend(request, params));
137913
138189
  }
137914
138190
  else if (price === 'index') {
137915
- method = 'contractPublicGetIndexMarketHistoryIndex';
138191
+ response = await this.contractPublicGetIndexMarketHistoryIndex(this.extend(request, params));
137916
138192
  }
137917
138193
  else if (price === 'premiumIndex') {
137918
138194
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137919
138195
  }
137920
138196
  else {
137921
- method = 'contractPublicGetMarketHistoryKline';
138197
+ response = await this.contractPublicGetMarketHistoryKline(this.extend(request, params));
137922
138198
  }
137923
138199
  }
137924
138200
  else if (market['linear']) {
138201
+ request['contract_code'] = market['id'];
137925
138202
  if (price === 'mark') {
137926
- method = 'contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline';
138203
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline(this.extend(request, params));
137927
138204
  }
137928
138205
  else if (price === 'index') {
137929
138206
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137930
138207
  }
137931
138208
  else if (price === 'premiumIndex') {
137932
- method = 'contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline';
138209
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline(this.extend(request, params));
137933
138210
  }
137934
138211
  else {
137935
- method = 'contractPublicGetLinearSwapExMarketHistoryKline';
138212
+ response = await this.contractPublicGetLinearSwapExMarketHistoryKline(this.extend(request, params));
137936
138213
  }
137937
- fieldName = 'contract_code';
137938
138214
  }
137939
138215
  }
137940
138216
  else if (market['swap']) {
138217
+ request['contract_code'] = market['id'];
137941
138218
  if (market['inverse']) {
137942
138219
  if (price === 'mark') {
137943
- method = 'contractPublicGetIndexMarketHistorySwapMarkPriceKline';
138220
+ response = await this.contractPublicGetIndexMarketHistorySwapMarkPriceKline(this.extend(request, params));
137944
138221
  }
137945
138222
  else if (price === 'index') {
137946
138223
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137947
138224
  }
137948
138225
  else if (price === 'premiumIndex') {
137949
- method = 'contractPublicGetIndexMarketHistorySwapPremiumIndexKline';
138226
+ response = await this.contractPublicGetIndexMarketHistorySwapPremiumIndexKline(this.extend(request, params));
137950
138227
  }
137951
138228
  else {
137952
- method = 'contractPublicGetSwapExMarketHistoryKline';
138229
+ response = await this.contractPublicGetSwapExMarketHistoryKline(this.extend(request, params));
137953
138230
  }
137954
138231
  }
137955
138232
  else if (market['linear']) {
137956
138233
  if (price === 'mark') {
137957
- method = 'contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline';
138234
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline(this.extend(request, params));
137958
138235
  }
137959
138236
  else if (price === 'index') {
137960
138237
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137961
138238
  }
137962
138239
  else if (price === 'premiumIndex') {
137963
- method = 'contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline';
138240
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline(this.extend(request, params));
137964
138241
  }
137965
138242
  else {
137966
- method = 'contractPublicGetLinearSwapExMarketHistoryKline';
138243
+ response = await this.contractPublicGetLinearSwapExMarketHistoryKline(this.extend(request, params));
137967
138244
  }
137968
138245
  }
137969
- fieldName = 'contract_code';
137970
138246
  }
137971
- if (market['contract']) {
138247
+ else {
138248
+ if (since !== undefined) {
138249
+ request['from'] = this.parseToInt(since / 1000);
138250
+ }
137972
138251
  if (limit !== undefined) {
137973
- request['size'] = limit; // when using limit from and to are ignored
137974
- // https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data
138252
+ request['size'] = limit; // max 2000
137975
138253
  }
137976
- else {
137977
- limit = 2000; // only used for from/to calculation
138254
+ request['symbol'] = market['id'];
138255
+ if (timeframe === '1M' || timeframe === '1y') {
138256
+ // for some reason 1M and 1Y does not work with the regular endpoint
138257
+ // https://github.com/ccxt/ccxt/issues/18006
138258
+ response = await this.spotPublicGetMarketHistoryKline(this.extend(request, params));
137978
138259
  }
137979
- if (price === undefined) {
137980
- const duration = this.parseTimeframe(timeframe);
137981
- if (since === undefined) {
137982
- const now = this.seconds();
137983
- request['from'] = now - duration * (limit - 1);
137984
- request['to'] = now;
137985
- }
137986
- else {
137987
- const start = this.parseToInt(since / 1000);
137988
- request['from'] = start;
137989
- request['to'] = this.sum(start, duration * (limit - 1));
137990
- }
138260
+ else {
138261
+ response = await this.spotPublicGetMarketHistoryCandles(this.extend(request, params));
137991
138262
  }
137992
138263
  }
137993
- request[fieldName] = market['id'];
137994
- const response = await this[method](this.extend(request, params));
137995
138264
  //
137996
138265
  // {
137997
138266
  // "status":"ok",
@@ -138608,58 +138877,57 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
138608
138877
  // 'pair': 'BTC-USDT',
138609
138878
  // 'contract_type': 'this_week', // swap, this_week, next_week, quarter, next_ quarter
138610
138879
  };
138611
- let method = undefined;
138880
+ let response = undefined;
138612
138881
  if (marketType === 'spot') {
138613
138882
  const clientOrderId = this.safeString(params, 'clientOrderId');
138614
- method = 'spotPrivateGetV1OrderOrdersOrderId';
138615
138883
  if (clientOrderId !== undefined) {
138616
- method = 'spotPrivateGetV1OrderOrdersGetClientOrder';
138617
138884
  // will be filled below in extend ()
138618
138885
  // they expect clientOrderId instead of client-order-id
138619
138886
  // request['clientOrderId'] = clientOrderId;
138887
+ response = await this.spotPrivateGetV1OrderOrdersGetClientOrder(this.extend(request, params));
138620
138888
  }
138621
138889
  else {
138622
138890
  request['order-id'] = id;
138891
+ response = await this.spotPrivateGetV1OrderOrdersOrderId(this.extend(request, params));
138623
138892
  }
138624
138893
  }
138625
138894
  else {
138626
138895
  if (symbol === undefined) {
138627
138896
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
138628
138897
  }
138898
+ const clientOrderId = this.safeString2(params, 'client_order_id', 'clientOrderId');
138899
+ if (clientOrderId === undefined) {
138900
+ request['order_id'] = id;
138901
+ }
138902
+ else {
138903
+ request['client_order_id'] = clientOrderId;
138904
+ params = this.omit(params, ['client_order_id', 'clientOrderId']);
138905
+ }
138629
138906
  request['contract_code'] = market['id'];
138630
138907
  if (market['linear']) {
138631
138908
  let marginMode = undefined;
138632
138909
  [marginMode, params] = this.handleMarginModeAndParams('fetchOrder', params);
138633
138910
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
138634
138911
  if (marginMode === 'isolated') {
138635
- method = 'contractPrivatePostLinearSwapApiV1SwapOrderInfo';
138912
+ response = await this.contractPrivatePostLinearSwapApiV1SwapOrderInfo(this.extend(request, params));
138636
138913
  }
138637
138914
  else if (marginMode === 'cross') {
138638
- method = 'contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo';
138915
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo(this.extend(request, params));
138639
138916
  }
138640
138917
  }
138641
138918
  else if (market['inverse']) {
138642
138919
  if (marketType === 'future') {
138643
- method = 'contractPrivatePostApiV1ContractOrderInfo';
138644
138920
  request['symbol'] = market['settleId'];
138921
+ response = await this.contractPrivatePostApiV1ContractOrderInfo(this.extend(request, params));
138645
138922
  }
138646
138923
  else if (marketType === 'swap') {
138647
- method = 'contractPrivatePostSwapApiV1SwapOrderInfo';
138924
+ response = await this.contractPrivatePostSwapApiV1SwapOrderInfo(this.extend(request, params));
138648
138925
  }
138649
138926
  else {
138650
138927
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchOrder() does not support ' + marketType + ' markets');
138651
138928
  }
138652
138929
  }
138653
- const clientOrderId = this.safeString2(params, 'client_order_id', 'clientOrderId');
138654
- if (clientOrderId === undefined) {
138655
- request['order_id'] = id;
138656
- }
138657
- else {
138658
- request['client_order_id'] = clientOrderId;
138659
- params = this.omit(params, ['client_order_id', 'clientOrderId']);
138660
- }
138661
138930
  }
138662
- const response = await this[method](this.extend(request, params));
138663
138931
  //
138664
138932
  // spot
138665
138933
  //
@@ -141358,7 +141626,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141358
141626
  };
141359
141627
  let subType = undefined;
141360
141628
  [subType, params] = this.handleSubTypeAndParams('transfer', undefined, params);
141361
- let method = undefined;
141362
141629
  let fromAccountId = this.convertTypeToAccount(fromAccount);
141363
141630
  let toAccountId = this.convertTypeToAccount(toAccount);
141364
141631
  const toCross = toAccountId === 'cross';
@@ -141371,28 +141638,28 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141371
141638
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' transfer () cannot make a transfer between ' + fromAccount + ' and ' + toAccount);
141372
141639
  }
141373
141640
  const fromOrToFuturesAccount = (fromAccountId === 'futures') || (toAccountId === 'futures');
141641
+ let response = undefined;
141374
141642
  if (fromOrToFuturesAccount) {
141375
141643
  let type = fromAccountId + '-to-' + toAccountId;
141376
141644
  type = this.safeString(params, 'type', type);
141377
141645
  request['type'] = type;
141378
- method = 'spotPrivatePostV1FuturesTransfer';
141646
+ response = await this.spotPrivatePostV1FuturesTransfer(this.extend(request, params));
141379
141647
  }
141380
141648
  else if (fromSpot && toCross) {
141381
- method = 'privatePostCrossMarginTransferIn';
141649
+ response = await this.privatePostCrossMarginTransferIn(this.extend(request, params));
141382
141650
  }
141383
141651
  else if (fromCross && toSpot) {
141384
- method = 'privatePostCrossMarginTransferOut';
141652
+ response = await this.privatePostCrossMarginTransferOut(this.extend(request, params));
141385
141653
  }
141386
141654
  else if (fromSpot && toIsolated) {
141387
141655
  request['symbol'] = toAccountId;
141388
- method = 'privatePostDwTransferInMargin';
141656
+ response = await this.privatePostDwTransferInMargin(this.extend(request, params));
141389
141657
  }
141390
141658
  else if (fromIsolated && toSpot) {
141391
141659
  request['symbol'] = fromAccountId;
141392
- method = 'privatePostDwTransferOutMargin';
141660
+ response = await this.privatePostDwTransferOutMargin(this.extend(request, params));
141393
141661
  }
141394
141662
  else {
141395
- method = 'v2PrivatePostAccountTransfer';
141396
141663
  if (subType === 'linear') {
141397
141664
  if ((fromAccountId === 'swap') || (fromAccount === 'linear-swap')) {
141398
141665
  fromAccountId = 'linear-swap';
@@ -141413,8 +141680,8 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141413
141680
  }
141414
141681
  request['from'] = fromSpot ? 'spot' : fromAccountId;
141415
141682
  request['to'] = toSpot ? 'spot' : toAccountId;
141683
+ response = await this.v2PrivatePostAccountTransfer(this.extend(request, params));
141416
141684
  }
141417
- const response = await this[method](this.extend(request, params));
141418
141685
  //
141419
141686
  // {
141420
141687
  // "code": "200",
@@ -141541,17 +141808,16 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141541
141808
  const request = {
141542
141809
  'contract_code': market['id'],
141543
141810
  };
141544
- let method = undefined;
141811
+ let response = undefined;
141545
141812
  if (market['inverse']) {
141546
- method = 'contractPublicGetSwapApiV1SwapHistoricalFundingRate';
141813
+ response = await this.contractPublicGetSwapApiV1SwapHistoricalFundingRate(this.extend(request, params));
141547
141814
  }
141548
141815
  else if (market['linear']) {
141549
- method = 'contractPublicGetLinearSwapApiV1SwapHistoricalFundingRate';
141816
+ response = await this.contractPublicGetLinearSwapApiV1SwapHistoricalFundingRate(this.extend(request, params));
141550
141817
  }
141551
141818
  else {
141552
141819
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchFundingRateHistory() supports inverse and linear swaps only');
141553
141820
  }
141554
- const response = await this[method](this.extend(request, params));
141555
141821
  //
141556
141822
  // {
141557
141823
  // "status": "ok",
@@ -141647,20 +141913,19 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141647
141913
  */
141648
141914
  await this.loadMarkets();
141649
141915
  const market = this.market(symbol);
141650
- let method = undefined;
141916
+ const request = {
141917
+ 'contract_code': market['id'],
141918
+ };
141919
+ let response = undefined;
141651
141920
  if (market['inverse']) {
141652
- method = 'contractPublicGetSwapApiV1SwapFundingRate';
141921
+ response = await this.contractPublicGetSwapApiV1SwapFundingRate(this.extend(request, params));
141653
141922
  }
141654
141923
  else if (market['linear']) {
141655
- method = 'contractPublicGetLinearSwapApiV1SwapFundingRate';
141924
+ response = await this.contractPublicGetLinearSwapApiV1SwapFundingRate(this.extend(request, params));
141656
141925
  }
141657
141926
  else {
141658
141927
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchFundingRate() supports inverse and linear swaps only');
141659
141928
  }
141660
- const request = {
141661
- 'contract_code': market['id'],
141662
- };
141663
- const response = await this[method](this.extend(request, params));
141664
141929
  //
141665
141930
  // {
141666
141931
  // "status": "ok",
@@ -141697,12 +141962,17 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141697
141962
  const request = {
141698
141963
  // 'contract_code': market['id'],
141699
141964
  };
141700
- const method = this.getSupportedMapping(subType, {
141701
- 'linear': 'contractPublicGetLinearSwapApiV1SwapBatchFundingRate',
141702
- 'inverse': 'contractPublicGetSwapApiV1SwapBatchFundingRate',
141703
- });
141704
141965
  params = this.omit(params, 'subType');
141705
- const response = await this[method](this.extend(request, params));
141966
+ let response = undefined;
141967
+ if (subType === 'linear') {
141968
+ response = await this.contractPublicGetLinearSwapApiV1SwapBatchFundingRate(this.extend(request, params));
141969
+ }
141970
+ else if (subType === 'inverse') {
141971
+ response = await this.contractPublicGetSwapApiV1SwapBatchFundingRate(this.extend(request, params));
141972
+ }
141973
+ else {
141974
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchFundingRates() not support this market type');
141975
+ }
141706
141976
  //
141707
141977
  // {
141708
141978
  // "status": "ok",
@@ -141749,22 +142019,21 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141749
142019
  request['size'] = limit;
141750
142020
  }
141751
142021
  let market = undefined;
141752
- let method = undefined;
142022
+ let response = undefined;
141753
142023
  if (marginMode === 'isolated') {
141754
- method = 'privateGetMarginLoanOrders';
141755
142024
  if (symbol !== undefined) {
141756
142025
  market = this.market(symbol);
141757
142026
  request['symbol'] = market['id'];
141758
142027
  }
142028
+ response = await this.privateGetMarginLoanOrders(this.extend(request, params));
141759
142029
  }
141760
142030
  else { // Cross
141761
- method = 'privateGetCrossMarginLoanOrders';
141762
142031
  if (code !== undefined) {
141763
142032
  const currency = this.currency(code);
141764
142033
  request['currency'] = currency['id'];
141765
142034
  }
142035
+ response = await this.privateGetCrossMarginLoanOrders(this.extend(request, params));
141766
142036
  }
141767
- const response = await this[method](this.extend(request, params));
141768
142037
  //
141769
142038
  // {
141770
142039
  // "status":"ok",
@@ -142027,17 +142296,16 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142027
142296
  await this.loadMarkets();
142028
142297
  const market = this.market(symbol);
142029
142298
  const [marketType, query] = this.handleMarketTypeAndParams('fetchFundingHistory', market, params);
142030
- let method = undefined;
142031
142299
  const request = {
142032
142300
  'type': '30,31',
142033
142301
  };
142034
142302
  if (since !== undefined) {
142035
142303
  request['start_date'] = since;
142036
142304
  }
142305
+ let response = undefined;
142037
142306
  if (marketType === 'swap') {
142038
142307
  request['contract'] = market['id'];
142039
142308
  if (market['linear']) {
142040
- method = 'contractPrivatePostLinearSwapApiV3SwapFinancialRecordExact';
142041
142309
  //
142042
142310
  // {
142043
142311
  // "status": "ok",
@@ -142069,9 +142337,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142069
142337
  else {
142070
142338
  request['mar_acct'] = market['quoteId'];
142071
142339
  }
142340
+ response = await this.contractPrivatePostLinearSwapApiV3SwapFinancialRecordExact(this.extend(request, query));
142072
142341
  }
142073
142342
  else {
142074
- method = 'contractPrivatePostSwapApiV3SwapFinancialRecordExact';
142075
142343
  //
142076
142344
  // {
142077
142345
  // "code": 200,
@@ -142092,13 +142360,13 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142092
142360
  // "ts": 1604312615051
142093
142361
  // }
142094
142362
  //
142363
+ response = await this.contractPrivatePostSwapApiV3SwapFinancialRecordExact(this.extend(request, query));
142095
142364
  }
142096
142365
  }
142097
142366
  else {
142098
- method = 'contractPrivatePostApiV3ContractFinancialRecordExact';
142099
142367
  request['symbol'] = market['id'];
142368
+ response = await this.contractPrivatePostApiV3ContractFinancialRecordExact(this.extend(request, query));
142100
142369
  }
142101
- const response = await this[method](this.extend(request, query));
142102
142370
  const data = this.safeValue(response, 'data', []);
142103
142371
  return this.parseIncomes(data, market, since, limit);
142104
142372
  }
@@ -142118,15 +142386,29 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142118
142386
  await this.loadMarkets();
142119
142387
  const market = this.market(symbol);
142120
142388
  const [marketType, query] = this.handleMarketTypeAndParams('setLeverage', market, params);
142121
- let method = undefined;
142389
+ const request = {
142390
+ 'lever_rate': leverage,
142391
+ };
142392
+ if (marketType === 'future' && market['inverse']) {
142393
+ request['symbol'] = market['settleId'];
142394
+ }
142395
+ else {
142396
+ request['contract_code'] = market['id'];
142397
+ }
142398
+ let response = undefined;
142122
142399
  if (market['linear']) {
142123
142400
  let marginMode = undefined;
142124
142401
  [marginMode, params] = this.handleMarginModeAndParams('setLeverage', params);
142125
142402
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
142126
- method = this.getSupportedMapping(marginMode, {
142127
- 'isolated': 'contractPrivatePostLinearSwapApiV1SwapSwitchLeverRate',
142128
- 'cross': 'contractPrivatePostLinearSwapApiV1SwapCrossSwitchLeverRate',
142129
- });
142403
+ if (marginMode === 'isolated') {
142404
+ response = await this.contractPrivatePostLinearSwapApiV1SwapSwitchLeverRate(this.extend(request, query));
142405
+ }
142406
+ else if (marginMode === 'cross') {
142407
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossSwitchLeverRate(this.extend(request, query));
142408
+ }
142409
+ else {
142410
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' setLeverage() not support this market type');
142411
+ }
142130
142412
  //
142131
142413
  // {
142132
142414
  // "status": "ok",
@@ -142140,10 +142422,15 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142140
142422
  //
142141
142423
  }
142142
142424
  else {
142143
- method = this.getSupportedMapping(marketType, {
142144
- 'future': 'contractPrivatePostApiV1ContractSwitchLeverRate',
142145
- 'swap': 'contractPrivatePostSwapApiV1SwapSwitchLeverRate',
142146
- });
142425
+ if (marketType === 'future') {
142426
+ response = await this.contractPrivatePostApiV1ContractSwitchLeverRate(this.extend(request, query));
142427
+ }
142428
+ else if (marketType === 'swap') {
142429
+ response = await this.contractPrivatePostSwapApiV1SwapSwitchLeverRate(this.extend(request, query));
142430
+ }
142431
+ else {
142432
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' setLeverage() not support this market type');
142433
+ }
142147
142434
  //
142148
142435
  // future
142149
142436
  // {
@@ -142161,16 +142448,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142161
142448
  // }
142162
142449
  //
142163
142450
  }
142164
- const request = {
142165
- 'lever_rate': leverage,
142166
- };
142167
- if (marketType === 'future' && market['inverse']) {
142168
- request['symbol'] = market['settleId'];
142169
- }
142170
- else {
142171
- request['contract_code'] = market['id'];
142172
- }
142173
- const response = await this[method](this.extend(request, query));
142174
142451
  return response;
142175
142452
  }
142176
142453
  parseIncome(income, market = undefined) {
@@ -142318,12 +142595,17 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142318
142595
  if (marketType === 'spot') {
142319
142596
  marketType = 'future';
142320
142597
  }
142321
- let method = undefined;
142598
+ let response = undefined;
142322
142599
  if (subType === 'linear') {
142323
- method = this.getSupportedMapping(marginMode, {
142324
- 'isolated': 'contractPrivatePostLinearSwapApiV1SwapPositionInfo',
142325
- 'cross': 'contractPrivatePostLinearSwapApiV1SwapCrossPositionInfo',
142326
- });
142600
+ if (marginMode === 'isolated') {
142601
+ response = await this.contractPrivatePostLinearSwapApiV1SwapPositionInfo(params);
142602
+ }
142603
+ else if (marginMode === 'cross') {
142604
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossPositionInfo(params);
142605
+ }
142606
+ else {
142607
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchPositions() not support this market type');
142608
+ }
142327
142609
  //
142328
142610
  // {
142329
142611
  // "status": "ok",
@@ -142353,10 +142635,15 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142353
142635
  //
142354
142636
  }
142355
142637
  else {
142356
- method = this.getSupportedMapping(marketType, {
142357
- 'future': 'contractPrivatePostApiV1ContractPositionInfo',
142358
- 'swap': 'contractPrivatePostSwapApiV1SwapPositionInfo',
142359
- });
142638
+ if (marketType === 'future') {
142639
+ response = await this.contractPrivatePostApiV1ContractPositionInfo(params);
142640
+ }
142641
+ else if (marketType === 'swap') {
142642
+ response = await this.contractPrivatePostSwapApiV1SwapPositionInfo(params);
142643
+ }
142644
+ else {
142645
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchPositions() not support this market type');
142646
+ }
142360
142647
  //
142361
142648
  // future
142362
142649
  // {
@@ -142408,7 +142695,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142408
142695
  // }
142409
142696
  //
142410
142697
  }
142411
- const response = await this[method](params);
142412
142698
  const data = this.safeValue(response, 'data', []);
142413
142699
  const timestamp = this.safeInteger(response, 'ts');
142414
142700
  const result = [];
@@ -142437,12 +142723,27 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142437
142723
  [marginMode, params] = this.handleMarginModeAndParams('fetchPosition', params);
142438
142724
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
142439
142725
  const [marketType, query] = this.handleMarketTypeAndParams('fetchPosition', market, params);
142440
- let method = undefined;
142726
+ const request = {};
142727
+ if (market['future'] && market['inverse']) {
142728
+ request['symbol'] = market['settleId'];
142729
+ }
142730
+ else {
142731
+ if (marginMode === 'cross') {
142732
+ request['margin_account'] = 'USDT'; // only allowed value
142733
+ }
142734
+ request['contract_code'] = market['id'];
142735
+ }
142736
+ let response = undefined;
142441
142737
  if (market['linear']) {
142442
- method = this.getSupportedMapping(marginMode, {
142443
- 'isolated': 'contractPrivatePostLinearSwapApiV1SwapAccountPositionInfo',
142444
- 'cross': 'contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfo',
142445
- });
142738
+ if (marginMode === 'isolated') {
142739
+ response = await this.contractPrivatePostLinearSwapApiV1SwapAccountPositionInfo(this.extend(request, query));
142740
+ }
142741
+ else if (marginMode === 'cross') {
142742
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfo(this.extend(request, query));
142743
+ }
142744
+ else {
142745
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchPosition() not support this market type');
142746
+ }
142446
142747
  //
142447
142748
  // isolated
142448
142749
  //
@@ -142562,10 +142863,15 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142562
142863
  //
142563
142864
  }
142564
142865
  else {
142565
- method = this.getSupportedMapping(marketType, {
142566
- 'future': 'contractPrivatePostApiV1ContractAccountPositionInfo',
142567
- 'swap': 'contractPrivatePostSwapApiV1SwapAccountPositionInfo',
142568
- });
142866
+ if (marketType === 'future') {
142867
+ response = await this.contractPrivatePostApiV1ContractAccountPositionInfo(this.extend(request, query));
142868
+ }
142869
+ else if (marketType === 'swap') {
142870
+ response = await this.contractPrivatePostSwapApiV1SwapAccountPositionInfo(this.extend(request, query));
142871
+ }
142872
+ else {
142873
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' setLeverage() not support this market type');
142874
+ }
142569
142875
  //
142570
142876
  // future, swap
142571
142877
  //
@@ -142636,17 +142942,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142636
142942
  // }
142637
142943
  //
142638
142944
  }
142639
- const request = {};
142640
- if (market['future'] && market['inverse']) {
142641
- request['symbol'] = market['settleId'];
142642
- }
142643
- else {
142644
- if (marginMode === 'cross') {
142645
- request['margin_account'] = 'USDT'; // only allowed value
142646
- }
142647
- request['contract_code'] = market['id'];
142648
- }
142649
- const response = await this[method](this.extend(request, query));
142650
142945
  const data = this.safeValue(response, 'data');
142651
142946
  let account = undefined;
142652
142947
  if (marginMode === 'cross') {
@@ -142977,26 +143272,28 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142977
143272
  'period': timeframes[timeframe],
142978
143273
  'amount_type': amountType,
142979
143274
  };
142980
- let method = undefined;
143275
+ if (limit !== undefined) {
143276
+ request['size'] = limit;
143277
+ }
143278
+ let response = undefined;
142981
143279
  if (market['future']) {
142982
143280
  request['contract_type'] = this.safeString(market['info'], 'contract_type');
142983
143281
  request['symbol'] = market['baseId']; // currency code on coin-m futures
142984
- method = 'contractPublicGetApiV1ContractHisOpenInterest'; // coin-m futures
143282
+ // coin-m futures
143283
+ response = await this.contractPublicGetApiV1ContractHisOpenInterest(this.extend(request, params));
142985
143284
  }
142986
143285
  else if (market['linear']) {
142987
143286
  request['contract_type'] = 'swap';
142988
143287
  request['contract_code'] = market['id'];
142989
143288
  request['contract_code'] = market['id'];
142990
- method = 'contractPublicGetLinearSwapApiV1SwapHisOpenInterest'; // USDT-M
143289
+ // USDT-M
143290
+ response = await this.contractPublicGetLinearSwapApiV1SwapHisOpenInterest(this.extend(request, params));
142991
143291
  }
142992
143292
  else {
142993
143293
  request['contract_code'] = market['id'];
142994
- method = 'contractPublicGetSwapApiV1SwapHisOpenInterest'; // coin-m swaps
142995
- }
142996
- if (limit !== undefined) {
142997
- request['size'] = limit;
143294
+ // coin-m swaps
143295
+ response = await this.contractPublicGetSwapApiV1SwapHisOpenInterest(this.extend(request, params));
142998
143296
  }
142999
- const response = await this[method](this.extend(request, params));
143000
143297
  //
143001
143298
  // contractPublicGetlinearSwapApiV1SwapHisOpenInterest
143002
143299
  // {
@@ -143084,20 +143381,22 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
143084
143381
  const request = {
143085
143382
  'contract_code': market['id'],
143086
143383
  };
143087
- let method = undefined;
143384
+ let response = undefined;
143088
143385
  if (market['future']) {
143089
143386
  request['contract_type'] = this.safeString(market['info'], 'contract_type');
143090
143387
  request['symbol'] = market['baseId'];
143091
- method = 'contractPublicGetApiV1ContractOpenInterest'; // COIN-M futures
143388
+ // COIN-M futures
143389
+ response = await this.contractPublicGetApiV1ContractOpenInterest(this.extend(request, params));
143092
143390
  }
143093
143391
  else if (market['linear']) {
143094
143392
  request['contract_type'] = 'swap';
143095
- method = 'contractPublicGetLinearSwapApiV1SwapOpenInterest'; // USDT-M
143393
+ // USDT-M
143394
+ response = await this.contractPublicGetLinearSwapApiV1SwapOpenInterest(this.extend(request, params));
143096
143395
  }
143097
143396
  else {
143098
- method = 'contractPublicGetSwapApiV1SwapOpenInterest'; // COIN-M swaps
143397
+ // COIN-M swaps
143398
+ response = await this.contractPublicGetSwapApiV1SwapOpenInterest(this.extend(request, params));
143099
143399
  }
143100
- const response = await this[method](this.extend(request, params));
143101
143400
  //
143102
143401
  // USDT-M contractPublicGetLinearSwapApiV1SwapOpenInterest
143103
143402
  //
@@ -143447,16 +143746,18 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
143447
143746
  if (until !== undefined) {
143448
143747
  request['end_at'] = until;
143449
143748
  }
143450
- let method = 'contractPublicGetApiV1ContractSettlementRecords';
143749
+ let response = undefined;
143451
143750
  if (market['swap']) {
143452
143751
  if (market['linear']) {
143453
- method = 'contractPublicGetLinearSwapApiV1SwapSettlementRecords';
143752
+ response = await this.contractPublicGetLinearSwapApiV1SwapSettlementRecords(this.extend(request, params));
143454
143753
  }
143455
143754
  else {
143456
- method = 'contractPublicGetSwapApiV1SwapSettlementRecords';
143755
+ response = await this.contractPublicGetSwapApiV1SwapSettlementRecords(this.extend(request, params));
143457
143756
  }
143458
143757
  }
143459
- const response = await this[method](this.extend(request, params));
143758
+ else {
143759
+ response = await this.contractPublicGetApiV1ContractSettlementRecords(this.extend(request, params));
143760
+ }
143460
143761
  //
143461
143762
  // linear swap, coin-m swap
143462
143763
  //
@@ -161600,6 +161901,8 @@ class kuna extends _abstract_kuna_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
161600
161901
  'fetchWithdrawal': true,
161601
161902
  'fetchWithdrawals': true,
161602
161903
  'reduceMargin': false,
161904
+ 'repayCrossMargin': false,
161905
+ 'repayIsolatedMargin': false,
161603
161906
  'setLeverage': false,
161604
161907
  'setMargin': false,
161605
161908
  'setMarginMode': false,
@@ -171404,6 +171707,8 @@ class mexc extends _abstract_mexc_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
171404
171707
  'fetchWithdrawal': undefined,
171405
171708
  'fetchWithdrawals': true,
171406
171709
  'reduceMargin': true,
171710
+ 'repayCrossMargin': false,
171711
+ 'repayIsolatedMargin': false,
171407
171712
  'setLeverage': true,
171408
171713
  'setMarginMode': undefined,
171409
171714
  'setPositionMode': true,
@@ -183138,7 +183443,7 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
183138
183443
  }
183139
183444
  if (isMarketOrder || marketIOC) {
183140
183445
  request['ordType'] = 'market';
183141
- if ((side === 'buy')) {
183446
+ if (side === 'buy') {
183142
183447
  // spot market buy: "sz" can refer either to base currency units or to quote currency units
183143
183448
  // see documentation: https://www.okx.com/docs-v5/en/#rest-api-trade-place-order
183144
183449
  if (tgtCcy === 'quote_ccy') {
@@ -183171,6 +183476,9 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
183171
183476
  request['sz'] = this.amountToPrecision(symbol, amount);
183172
183477
  }
183173
183478
  }
183479
+ else {
183480
+ request['sz'] = this.amountToPrecision(symbol, amount);
183481
+ }
183174
183482
  }
183175
183483
  else {
183176
183484
  request['sz'] = this.amountToPrecision(symbol, amount);
@@ -194067,7 +194375,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194067
194375
  'setMarginMode': true,
194068
194376
  'setPositionMode': true,
194069
194377
  'transfer': true,
194070
- 'withdraw': undefined,
194378
+ 'withdraw': true,
194071
194379
  },
194072
194380
  'urls': {
194073
194381
  'logo': 'https://user-images.githubusercontent.com/1294454/85225056-221eb600-b3d7-11ea-930d-564d2690e3f6.jpg',
@@ -194206,6 +194514,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194206
194514
  'assets/spots/sub-accounts/transfer': 5,
194207
194515
  'assets/futures/sub-accounts/transfer': 5,
194208
194516
  'assets/quote': 5, // ?fromCurrency=<currency>&toCurrency=<currency>&amountEv=<amount>
194517
+ // deposit/withdraw
194209
194518
  },
194210
194519
  'post': {
194211
194520
  // spot
@@ -194449,6 +194758,16 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194449
194758
  'spot': 'spot',
194450
194759
  'swap': 'future',
194451
194760
  },
194761
+ 'stableCoins': [
194762
+ 'BUSD',
194763
+ 'FEI',
194764
+ 'TUSD',
194765
+ 'USD',
194766
+ 'USDC',
194767
+ 'USDD',
194768
+ 'USDP',
194769
+ 'USDT',
194770
+ ],
194452
194771
  'transfer': {
194453
194772
  'fillResponseFromRequest': true,
194454
194773
  },
@@ -198538,6 +198857,48 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
198538
198857
  const sorted = this.sortBy(result, 'timestamp');
198539
198858
  return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
198540
198859
  }
198860
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
198861
+ /**
198862
+ * @method
198863
+ * @name phemex#withdraw
198864
+ * @description make a withdrawal
198865
+ * @see https://phemex-docs.github.io/#create-withdraw-request
198866
+ * @param {string} code unified currency code
198867
+ * @param {float} amount the amount to withdraw
198868
+ * @param {string} address the address to withdraw to
198869
+ * @param {string} tag
198870
+ * @param {object} [params] extra parameters specific to the phemex api endpoint
198871
+ * @param {string} [params.network] unified network code
198872
+ * @returns {object} a [transaction structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#transaction-structure}
198873
+ */
198874
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
198875
+ await this.loadMarkets();
198876
+ this.checkAddress(address);
198877
+ const currency = this.currency(code);
198878
+ let networkCode = undefined;
198879
+ [networkCode, params] = this.handleNetworkCodeAndParams(params);
198880
+ let networkId = this.networkCodeToId(networkCode);
198881
+ const stableCoins = this.safeValue(this.options, 'stableCoins');
198882
+ if (networkId === undefined) {
198883
+ if (!(this.inArray(code, stableCoins))) {
198884
+ networkId = currency['id'];
198885
+ }
198886
+ else {
198887
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ArgumentsRequired(this.id + ' withdraw () requires an extra argument params["network"]');
198888
+ }
198889
+ }
198890
+ const request = {
198891
+ 'currency': currency['id'],
198892
+ 'address': address,
198893
+ 'amount': amount,
198894
+ 'chainName': networkId.toUpperCase(),
198895
+ };
198896
+ if (tag !== undefined) {
198897
+ request['tag'] = tag;
198898
+ }
198899
+ const response = await this.privatePostPhemexWithdrawWalletsApiCreateWithdraw(this.extend(request, params));
198900
+ return this.parseTransaction(response, currency);
198901
+ }
198541
198902
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
198542
198903
  if (response === undefined) {
198543
198904
  return undefined; // fallback to default error handler
@@ -198606,6 +198967,9 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
198606
198967
  'cancelAllOrders': true,
198607
198968
  'cancelOrder': true,
198608
198969
  'createDepositAddress': true,
198970
+ 'createMarketBuyOrderWithCost': true,
198971
+ 'createMarketOrderWithCost': false,
198972
+ 'createMarketSellOrderWithCost': false,
198609
198973
  'createOrder': true,
198610
198974
  'editOrder': true,
198611
198975
  'fetchBalance': true,
@@ -198799,6 +199163,7 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
198799
199163
  'UST': 'USTC',
198800
199164
  },
198801
199165
  'options': {
199166
+ 'createMarketBuyOrderRequiresPrice': true,
198802
199167
  'networks': {
198803
199168
  'BEP20': 'BSC',
198804
199169
  'ERC20': 'ETH',
@@ -199822,6 +200187,7 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
199822
200187
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
199823
200188
  * @param {object} [params] extra parameters specific to the exchange API endpoint
199824
200189
  * @param {float} [params.triggerPrice] *spot only* The price at which a trigger order is triggered at
200190
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
199825
200191
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
199826
200192
  */
199827
200193
  await this.loadMarkets();
@@ -199857,7 +200223,6 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
199857
200223
  return this.parseOrder(response, market);
199858
200224
  }
199859
200225
  orderRequest(symbol, type, side, amount, request, price = undefined, params = {}) {
199860
- const market = this.market(symbol);
199861
200226
  let upperCaseType = type.toUpperCase();
199862
200227
  const isMarket = upperCaseType === 'MARKET';
199863
200228
  const isPostOnly = this.isPostOnly(isMarket, upperCaseType === 'LIMIT_MAKER', params);
@@ -199873,7 +200238,29 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
199873
200238
  request['type'] = upperCaseType;
199874
200239
  if (isMarket) {
199875
200240
  if (side === 'buy') {
199876
- request['amount'] = this.currencyToPrecision(market['quote'], amount);
200241
+ let quoteAmount = undefined;
200242
+ let createMarketBuyOrderRequiresPrice = true;
200243
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
200244
+ const cost = this.safeNumber(params, 'cost');
200245
+ params = this.omit(params, 'cost');
200246
+ if (cost !== undefined) {
200247
+ quoteAmount = this.costToPrecision(symbol, cost);
200248
+ }
200249
+ else if (createMarketBuyOrderRequiresPrice) {
200250
+ if (price === undefined) {
200251
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
200252
+ }
200253
+ else {
200254
+ const amountString = this.numberToString(amount);
200255
+ const priceString = this.numberToString(price);
200256
+ const costRequest = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
200257
+ quoteAmount = this.costToPrecision(symbol, costRequest);
200258
+ }
200259
+ }
200260
+ else {
200261
+ quoteAmount = this.costToPrecision(symbol, amount);
200262
+ }
200263
+ request['amount'] = quoteAmount;
199877
200264
  }
199878
200265
  else {
199879
200266
  request['quantity'] = this.amountToPrecision(symbol, amount);
@@ -204918,7 +205305,7 @@ class binance extends _binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
204918
205305
  const subscribe = {
204919
205306
  'id': requestId,
204920
205307
  };
204921
- const trades = await this.watch(url, subParams, this.extend(request, query), subParams, subscribe);
205308
+ const trades = await this.watchMultiple(url, subParams, this.extend(request, query), subParams, subscribe);
204922
205309
  if (this.newUpdates) {
204923
205310
  const first = this.safeValue(trades, 0);
204924
205311
  const tradeSymbol = this.safeString(first, 'symbol');
@@ -206398,11 +206785,11 @@ class binance extends _binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
206398
206785
  this.setBalanceCache(client, type);
206399
206786
  this.setPositionsCache(client, type);
206400
206787
  const message = undefined;
206401
- const newOrder = await this.watch(url, messageHash, message, type);
206788
+ const orders = await this.watch(url, messageHash, message, type);
206402
206789
  if (this.newUpdates) {
206403
- return newOrder;
206790
+ limit = orders.getLimit(symbol, limit);
206404
206791
  }
206405
- return this.filterBySymbolSinceLimit(this.orders, symbol, since, limit, true);
206792
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
206406
206793
  }
206407
206794
  parseWsOrder(order, market = undefined) {
206408
206795
  //
@@ -207063,8 +207450,8 @@ class binance extends _binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
207063
207450
  cachedOrders.append(parsed);
207064
207451
  const messageHash = 'orders';
207065
207452
  const symbolSpecificMessageHash = 'orders:' + symbol;
207066
- client.resolve(parsed, messageHash);
207067
- client.resolve(parsed, symbolSpecificMessageHash);
207453
+ client.resolve(cachedOrders, messageHash);
207454
+ client.resolve(cachedOrders, symbolSpecificMessageHash);
207068
207455
  }
207069
207456
  }
207070
207457
  handleAcountUpdate(client, message) {
@@ -247136,6 +247523,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
247136
247523
  * @param {object} [params] extra parameters specific to the poloniex api endpoint
247137
247524
  * @param {string} [params.timeInForce] GTC (default), IOC, FOK
247138
247525
  * @param {string} [params.clientOrderId] Maximum 64-character length.*
247526
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
247139
247527
  *
247140
247528
  * EXCHANGE SPECIFIC PARAMETERS
247141
247529
  * @param {string} [params.amount] quote units for the order
@@ -247159,25 +247547,29 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
247159
247547
  'type': type.toUpperCase(),
247160
247548
  };
247161
247549
  if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) {
247162
- let quoteAmount = this.safeString(params, 'amount');
247163
- if ((quoteAmount === undefined) && (this.options['createMarketBuyOrderRequiresPrice'])) {
247164
- const cost = this.safeNumber(params, 'cost');
247165
- params = this.omit(params, 'cost');
247166
- if (price === undefined && cost === undefined) {
247167
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.ArgumentsRequired(this.id + ' createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options["createMarketBuyOrderRequiresPrice"] = false to supply the cost in the amount argument (the exchange-specific behaviour)');
247550
+ let quoteAmount = undefined;
247551
+ let createMarketBuyOrderRequiresPrice = true;
247552
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
247553
+ const cost = this.safeNumber(params, 'cost');
247554
+ params = this.omit(params, 'cost');
247555
+ if (cost !== undefined) {
247556
+ quoteAmount = this.costToPrecision(symbol, cost);
247557
+ }
247558
+ else if (createMarketBuyOrderRequiresPrice) {
247559
+ if (price === undefined) {
247560
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
247168
247561
  }
247169
247562
  else {
247170
247563
  const amountString = this.numberToString(amount);
247171
247564
  const priceString = this.numberToString(price);
247172
- const quote = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
247173
- amount = (cost !== undefined) ? cost : this.parseNumber(quote);
247174
- quoteAmount = this.costToPrecision(symbol, amount);
247565
+ const costRequest = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
247566
+ quoteAmount = this.costToPrecision(symbol, costRequest);
247175
247567
  }
247176
247568
  }
247177
247569
  else {
247178
247570
  quoteAmount = this.costToPrecision(symbol, amount);
247179
247571
  }
247180
- request['amount'] = this.amountToPrecision(market['symbol'], quoteAmount);
247572
+ request['amount'] = quoteAmount;
247181
247573
  }
247182
247574
  else {
247183
247575
  request['quantity'] = this.amountToPrecision(market['symbol'], amount);
@@ -265041,6 +265433,8 @@ class tokocrypto extends _abstract_tokocrypto_js__WEBPACK_IMPORTED_MODULE_0__/*
265041
265433
  'fetchWithdrawals': true,
265042
265434
  'fetchWithdrawalWhitelist': false,
265043
265435
  'reduceMargin': false,
265436
+ 'repayCrossMargin': false,
265437
+ 'repayIsolatedMargin': false,
265044
265438
  'setLeverage': false,
265045
265439
  'setMargin': false,
265046
265440
  'setMarginMode': false,
@@ -272046,6 +272440,8 @@ class wazirx extends _abstract_wazirx_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
272046
272440
  'fetchTransfers': false,
272047
272441
  'fetchWithdrawals': false,
272048
272442
  'reduceMargin': false,
272443
+ 'repayCrossMargin': false,
272444
+ 'repayIsolatedMargin': false,
272049
272445
  'setLeverage': false,
272050
272446
  'setMargin': false,
272051
272447
  'setMarginMode': false,
@@ -272993,6 +273389,8 @@ class whitebit extends _abstract_whitebit_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
272993
273389
  'fetchTradingFee': false,
272994
273390
  'fetchTradingFees': true,
272995
273391
  'fetchTransactionFees': true,
273392
+ 'repayCrossMargin': false,
273393
+ 'repayIsolatedMargin': false,
272996
273394
  'setLeverage': true,
272997
273395
  'transfer': true,
272998
273396
  'withdraw': true,
@@ -287416,7 +287814,7 @@ SOFTWARE.
287416
287814
 
287417
287815
  //-----------------------------------------------------------------------------
287418
287816
  // this is updated by vss.js when building
287419
- const version = '4.1.89';
287817
+ const version = '4.1.90';
287420
287818
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange */ .e.ccxtVersion = version;
287421
287819
  //-----------------------------------------------------------------------------
287422
287820