ccxt 4.1.88 → 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 (63) hide show
  1. package/CHANGELOG.md +8309 -5710
  2. package/README.md +3 -3
  3. package/changelog.js +101 -0
  4. package/dist/ccxt.browser.js +963 -387
  5. package/dist/ccxt.browser.min.js +3 -3
  6. package/dist/cjs/ccxt.js +1 -1
  7. package/dist/cjs/src/base/Exchange.js +2 -2
  8. package/dist/cjs/src/bigone.js +8 -1
  9. package/dist/cjs/src/bitforex.js +2 -0
  10. package/dist/cjs/src/bitget.js +11 -4
  11. package/dist/cjs/src/bitmex.js +2 -0
  12. package/dist/cjs/src/blockchaincom.js +0 -41
  13. package/dist/cjs/src/bybit.js +29 -14
  14. package/dist/cjs/src/coinex.js +14 -1
  15. package/dist/cjs/src/coinlist.js +2 -0
  16. package/dist/cjs/src/coinsph.js +2 -0
  17. package/dist/cjs/src/cryptocom.js +2 -0
  18. package/dist/cjs/src/gate.js +276 -11
  19. package/dist/cjs/src/htx.js +264 -219
  20. package/dist/cjs/src/kuna.js +2 -0
  21. package/dist/cjs/src/mexc.js +2 -0
  22. package/dist/cjs/src/okcoin.js +61 -17
  23. package/dist/cjs/src/phemex.js +159 -30
  24. package/dist/cjs/src/poloniex.js +28 -2
  25. package/dist/cjs/src/pro/binance.js +6 -6
  26. package/dist/cjs/src/pro/poloniex.js +15 -10
  27. package/dist/cjs/src/tokocrypto.js +30 -14
  28. package/dist/cjs/src/wazirx.js +2 -0
  29. package/dist/cjs/src/whitebit.js +2 -0
  30. package/dist/cjs/src/woo.js +41 -14
  31. package/js/ccxt.d.ts +1 -1
  32. package/js/ccxt.js +1 -1
  33. package/js/src/abstract/phemex.d.ts +1 -0
  34. package/js/src/base/Exchange.js +2 -2
  35. package/js/src/bigone.js +9 -2
  36. package/js/src/bitforex.js +2 -0
  37. package/js/src/bitget.js +11 -4
  38. package/js/src/bitmex.js +2 -0
  39. package/js/src/blockchaincom.d.ts +0 -2
  40. package/js/src/blockchaincom.js +0 -41
  41. package/js/src/bybit.js +29 -14
  42. package/js/src/coinex.js +14 -1
  43. package/js/src/coinlist.js +2 -0
  44. package/js/src/coinsph.js +2 -0
  45. package/js/src/cryptocom.js +2 -0
  46. package/js/src/gate.d.ts +47 -0
  47. package/js/src/gate.js +276 -11
  48. package/js/src/htx.js +264 -219
  49. package/js/src/kuna.js +2 -0
  50. package/js/src/mexc.js +2 -0
  51. package/js/src/okcoin.d.ts +1 -0
  52. package/js/src/okcoin.js +62 -18
  53. package/js/src/phemex.d.ts +3 -108
  54. package/js/src/phemex.js +159 -30
  55. package/js/src/poloniex.js +28 -2
  56. package/js/src/pro/binance.js +6 -6
  57. package/js/src/pro/poloniex.js +16 -11
  58. package/js/src/tokocrypto.js +30 -14
  59. package/js/src/wazirx.js +2 -0
  60. package/js/src/whitebit.js +2 -0
  61. package/js/src/woo.d.ts +1 -0
  62. package/js/src/woo.js +42 -15
  63. package/package.json +2 -2
@@ -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');
@@ -15152,6 +15152,7 @@ class bigone extends _abstract_bigone_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
15152
15152
  'cancelAllOrders': true,
15153
15153
  'cancelOrder': true,
15154
15154
  'createMarketBuyOrderWithCost': true,
15155
+ 'createMarketOrderWithCost': false,
15155
15156
  'createMarketSellOrderWithCost': false,
15156
15157
  'createOrder': true,
15157
15158
  'createPostOnlyOrder': true,
@@ -16279,13 +16280,18 @@ class bigone extends _abstract_bigone_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
16279
16280
  /**
16280
16281
  * @method
16281
16282
  * @name bigone#createMarketBuyOrderWithCost
16282
- * @see https://open.big.one/docs/spot_orders.html#create-order
16283
16283
  * @description create a market buy order by providing the symbol and cost
16284
+ * @see https://open.big.one/docs/spot_orders.html#create-order
16284
16285
  * @param {string} symbol unified symbol of the market to create an order in
16285
16286
  * @param {float} cost how much you want to trade in units of the quote currency
16286
16287
  * @param {object} [params] extra parameters specific to the exchange API endpoint
16287
16288
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
16288
16289
  */
16290
+ await this.loadMarkets();
16291
+ const market = this.market(symbol);
16292
+ if (!market['spot']) {
16293
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
16294
+ }
16289
16295
  params['createMarketBuyOrderRequiresPrice'] = false;
16290
16296
  return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
16291
16297
  }
@@ -16304,6 +16310,7 @@ class bigone extends _abstract_bigone_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
16304
16310
  * @param {float} [params.triggerPrice] the price at which a trigger order is triggered at
16305
16311
  * @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
16306
16312
  * @param {string} [params.timeInForce] "GTC", "IOC", or "PO"
16313
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
16307
16314
  *
16308
16315
  * EXCHANGE SPECIFIC PARAMETERS
16309
16316
  * @param {string} operator *stop order only* GTE or LTE (default)
@@ -39411,6 +39418,8 @@ class bitforex extends _abstract_bitforex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
39411
39418
  'fetchWithdrawal': false,
39412
39419
  'fetchWithdrawals': false,
39413
39420
  'reduceMargin': false,
39421
+ 'repayCrossMargin': false,
39422
+ 'repayIsolatedMargin': false,
39414
39423
  'setLeverage': false,
39415
39424
  'setMargin': false,
39416
39425
  'setMarginMode': false,
@@ -44052,7 +44061,7 @@ class bitget extends _abstract_bitget_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
44052
44061
  if (feeCostString !== undefined) {
44053
44062
  // swap
44054
44063
  fee = {
44055
- 'cost': feeCostString,
44064
+ 'cost': this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringAbs(feeCostString)),
44056
44065
  'currency': market['settle'],
44057
44066
  };
44058
44067
  }
@@ -44060,10 +44069,17 @@ class bitget extends _abstract_bitget_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
44060
44069
  if (feeDetail !== undefined) {
44061
44070
  const parsedFeeDetail = JSON.parse(feeDetail);
44062
44071
  const feeValues = Object.values(parsedFeeDetail);
44063
- 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
+ }
44064
44080
  fee = {
44065
- 'cost': this.safeString(first, 'totalFee'),
44066
- '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')),
44067
44083
  };
44068
44084
  }
44069
44085
  let postOnly = undefined;
@@ -53807,6 +53823,8 @@ class bitmex extends _abstract_bitmex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
53807
53823
  'cancelAllOrders': true,
53808
53824
  'cancelOrder': true,
53809
53825
  'cancelOrders': true,
53826
+ 'closeAllPositions': false,
53827
+ 'closePosition': true,
53810
53828
  'createOrder': true,
53811
53829
  'createReduceOnlyOrder': true,
53812
53830
  'editOrder': true,
@@ -70853,47 +70871,6 @@ class blockchaincom extends _abstract_blockchaincom_js__WEBPACK_IMPORTED_MODULE_
70853
70871
  'fee': fee,
70854
70872
  };
70855
70873
  }
70856
- async fetchWithdrawalWhitelist(params = {}) {
70857
- /**
70858
- * @method
70859
- * @name blockchaincom#fetchWithdrawalWhitelist
70860
- * @description fetch the list of withdrawal addresses on the whitelist
70861
- * @param {object} [params] extra parameters specific to the exchange API endpoint
70862
- * @returns {object} dictionary with keys beneficiaryId, name, currency
70863
- */
70864
- await this.loadMarkets();
70865
- const response = await this.privateGetWhitelist();
70866
- const result = [];
70867
- for (let i = 0; i < response.length; i++) {
70868
- const entry = response[i];
70869
- result.push({
70870
- 'beneficiaryId': this.safeString(entry, 'whitelistId'),
70871
- 'name': this.safeString(entry, 'name'),
70872
- 'currency': this.safeString(entry, 'currency'),
70873
- 'info': entry,
70874
- });
70875
- }
70876
- return result;
70877
- }
70878
- async fetchWithdrawalWhitelistByCurrency(code, params = {}) {
70879
- await this.loadMarkets();
70880
- const currency = this.currency(code);
70881
- const request = {
70882
- 'currency': currency['id'],
70883
- };
70884
- const response = await this.privateGetWhitelistCurrency(this.extend(request, params));
70885
- const result = [];
70886
- for (let i = 0; i < response.length; i++) {
70887
- const entry = response[i];
70888
- result.push({
70889
- 'beneficiaryId': this.safeString(entry, 'whitelistId'),
70890
- 'name': this.safeString(entry, 'name'),
70891
- 'currency': this.safeString(entry, 'currency'),
70892
- 'info': entry,
70893
- });
70894
- }
70895
- return result;
70896
- }
70897
70874
  async withdraw(code, amount, address, tag = undefined, params = {}) {
70898
70875
  /**
70899
70876
  * @method
@@ -75804,6 +75781,7 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
75804
75781
  },
75805
75782
  'precisionMode': _base_functions_number_js__WEBPACK_IMPORTED_MODULE_2__/* .TICK_SIZE */ .sh,
75806
75783
  'options': {
75784
+ 'fetchMarkets': ['spot', 'linear', 'inverse', 'option'],
75807
75785
  'enableUnifiedMargin': undefined,
75808
75786
  'enableUnifiedAccount': undefined,
75809
75787
  'createMarketBuyOrderRequiresPrice': true,
@@ -76309,21 +76287,35 @@ class bybit extends _abstract_bybit_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"
76309
76287
  if (this.options['adjustForTimeDifference']) {
76310
76288
  await this.loadTimeDifference();
76311
76289
  }
76312
- const promisesUnresolved = [
76313
- this.fetchSpotMarkets(params),
76314
- this.fetchFutureMarkets({ 'category': 'linear' }),
76315
- this.fetchFutureMarkets({ 'category': 'inverse' }),
76316
- this.fetchOptionMarkets({ 'baseCoin': 'BTC' }),
76317
- this.fetchOptionMarkets({ 'baseCoin': 'ETH' }),
76318
- this.fetchOptionMarkets({ 'baseCoin': 'SOL' }),
76319
- ];
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
+ }
76320
76312
  const promises = await Promise.all(promisesUnresolved);
76321
- const spotMarkets = promises[0];
76322
- const linearMarkets = promises[1];
76323
- const inverseMarkets = promises[2];
76324
- const btcOptionMarkets = promises[3];
76325
- const ethOptionMarkets = promises[4];
76326
- 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, []);
76327
76319
  const futureMarkets = this.arrayConcat(linearMarkets, inverseMarkets);
76328
76320
  let optionMarkets = this.arrayConcat(btcOptionMarkets, ethOptionMarkets);
76329
76321
  optionMarkets = this.arrayConcat(optionMarkets, solOptionMarkets);
@@ -90191,6 +90183,8 @@ class coinex extends _abstract_coinex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
90191
90183
  'cancelOrders': true,
90192
90184
  'createDepositAddress': true,
90193
90185
  'createMarketBuyOrderWithCost': true,
90186
+ 'createMarketOrderWithCost': false,
90187
+ 'createMarketSellOrderWithCost': false,
90194
90188
  'createOrder': true,
90195
90189
  'createOrders': true,
90196
90190
  'createReduceOnlyOrder': true,
@@ -92071,13 +92065,19 @@ class coinex extends _abstract_coinex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
92071
92065
  async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
92072
92066
  /**
92073
92067
  * @method
92074
- * @name coinex#createMarketBuyWithCost
92068
+ * @name coinex#createMarketBuyOrderWithCost
92075
92069
  * @description create a market buy order by providing the symbol and cost
92070
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_order
92076
92071
  * @param {string} symbol unified symbol of the market to create an order in
92077
92072
  * @param {float} cost how much you want to trade in units of the quote currency
92078
92073
  * @param {object} [params] extra parameters specific to the exchange API endpoint
92079
92074
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
92080
92075
  */
92076
+ await this.loadMarkets();
92077
+ const market = this.market(symbol);
92078
+ if (!market['spot']) {
92079
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_2__.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
92080
+ }
92081
92081
  params['createMarketBuyOrderRequiresPrice'] = false;
92082
92082
  return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
92083
92083
  }
@@ -92243,6 +92243,11 @@ class coinex extends _abstract_coinex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
92243
92243
  * @method
92244
92244
  * @name coinex#createOrder
92245
92245
  * @description create a trade order
92246
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade001_limit_order
92247
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_order
92248
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade004_IOC_order
92249
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade005_stop_limit_order
92250
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade006_stop_market_order
92246
92251
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http017_put_limit
92247
92252
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http018_put_market
92248
92253
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http019_put_limit_stop
@@ -95625,6 +95630,8 @@ class coinlist extends _abstract_coinlist_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
95625
95630
  'fetchWithdrawals': false,
95626
95631
  'fetchWithdrawalWhitelist': false,
95627
95632
  'reduceMargin': false,
95633
+ 'repayCrossMargin': false,
95634
+ 'repayIsolatedMargin': false,
95628
95635
  'setLeverage': false,
95629
95636
  'setMargin': false,
95630
95637
  'setMarginMode': false,
@@ -99908,6 +99915,8 @@ class coinsph extends _abstract_coinsph_js__WEBPACK_IMPORTED_MODULE_0__/* ["defa
99908
99915
  'fetchWithdrawals': true,
99909
99916
  'fetchWithdrawalWhitelist': false,
99910
99917
  'reduceMargin': false,
99918
+ 'repayCrossMargin': false,
99919
+ 'repayIsolatedMargin': false,
99911
99920
  'setLeverage': false,
99912
99921
  'setMargin': false,
99913
99922
  'setMarginMode': false,
@@ -102378,6 +102387,8 @@ class cryptocom extends _abstract_cryptocom_js__WEBPACK_IMPORTED_MODULE_0__/* ["
102378
102387
  'fetchVolatilityHistory': false,
102379
102388
  'fetchWithdrawals': true,
102380
102389
  'reduceMargin': false,
102390
+ 'repayCrossMargin': false,
102391
+ 'repayIsolatedMargin': false,
102381
102392
  'setLeverage': false,
102382
102393
  'setMarginMode': false,
102383
102394
  'setPositionMode': false,
@@ -120962,9 +120973,14 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
120962
120973
  'future': true,
120963
120974
  'option': true,
120964
120975
  'addMargin': true,
120976
+ 'borrowCrossMargin': true,
120977
+ 'borrowIsolatedMargin': true,
120965
120978
  'cancelAllOrders': true,
120966
120979
  'cancelOrder': true,
120980
+ 'createMarketBuyOrderWithCost': true,
120967
120981
  'createMarketOrder': true,
120982
+ 'createMarketOrderWithCost': false,
120983
+ 'createMarketSellOrderWithCost': false,
120968
120984
  'createOrder': true,
120969
120985
  'createOrders': true,
120970
120986
  'createPostOnlyOrder': true,
@@ -121026,6 +121042,8 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
121026
121042
  'fetchVolatilityHistory': false,
121027
121043
  'fetchWithdrawals': true,
121028
121044
  'reduceMargin': true,
121045
+ 'repayCrossMargin': true,
121046
+ 'repayIsolatedMargin': true,
121029
121047
  'setLeverage': true,
121030
121048
  'setMarginMode': false,
121031
121049
  'setPositionMode': true,
@@ -124644,6 +124662,7 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
124644
124662
  * @param {bool} [params.close] *contract only* Set as true to close the position, with size set to 0
124645
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
124646
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
124647
124666
  * @returns {object|undefined} [An order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
124648
124667
  */
124649
124668
  await this.loadMarkets();
@@ -124841,9 +124860,15 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
124841
124860
  }
124842
124861
  }
124843
124862
  if (contract) {
124844
- const amountToPrecision = this.amountToPrecision(symbol, amount);
124845
- const signedAmount = (side === 'sell') ? _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringNeg(amountToPrecision) : amountToPrecision;
124846
- 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
+ }
124847
124872
  }
124848
124873
  let request = undefined;
124849
124874
  const nonTriggerOrder = !isStopOrder && (trigger === undefined);
@@ -124891,24 +124916,30 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
124891
124916
  // 'auto_borrow': false, // used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
124892
124917
  // 'auto_repay': false, // automatic repayment for automatic borrow loan generated by cross margin order, diabled by default
124893
124918
  };
124894
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
124895
124919
  if (isMarketOrder && (side === 'buy')) {
124896
- 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) {
124897
124929
  if (price === undefined) {
124898
- 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');
124899
124931
  }
124900
124932
  else {
124901
124933
  const amountString = this.numberToString(amount);
124902
124934
  const priceString = this.numberToString(price);
124903
- const cost = this.parseNumber(_base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString));
124904
- 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);
124905
124937
  }
124906
124938
  }
124907
124939
  else {
124908
- const cost = this.safeNumber(params, 'cost', amount);
124909
- params = this.omit(params, 'cost');
124910
- request['amount'] = this.costToPrecision(symbol, cost);
124940
+ quoteAmount = this.costToPrecision(symbol, amount);
124911
124941
  }
124942
+ request['amount'] = quoteAmount;
124912
124943
  }
124913
124944
  else {
124914
124945
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -125038,6 +125069,25 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
125038
125069
  }
125039
125070
  return this.extend(request, params);
125040
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
+ }
125041
125091
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
125042
125092
  /**
125043
125093
  * @method
@@ -126623,6 +126673,210 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
126623
126673
  }
126624
126674
  return tiers;
126625
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
+ }
126626
126880
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
126627
126881
  const authentication = api[0]; // public, private
126628
126882
  const type = api[1]; // spot, margin, future, delivery
@@ -127632,6 +127886,28 @@ class gate extends _abstract_gate_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
127632
127886
  'info': greeks,
127633
127887
  };
127634
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
+ }
127635
127911
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
127636
127912
  if (response === undefined) {
127637
127913
  return undefined;
@@ -136270,30 +136546,32 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136270
136546
  await this.loadMarkets();
136271
136547
  let marketType = undefined;
136272
136548
  [marketType, params] = this.handleMarketTypeAndParams('fetchMyTrades', undefined, params);
136273
- let method = 'statusPublicSpotGetApiV2SummaryJson';
136549
+ let response = undefined;
136274
136550
  if (marketType !== 'spot') {
136275
136551
  const subType = this.safeString(params, 'subType', this.options['defaultSubType']);
136276
136552
  if (marketType === 'swap') {
136277
136553
  if (subType === 'linear') {
136278
- method = 'statusPublicSwapLinearGetApiV2SummaryJson';
136554
+ response = await this.statusPublicSwapLinearGetApiV2SummaryJson();
136279
136555
  }
136280
136556
  else if (subType === 'inverse') {
136281
- method = 'statusPublicSwapInverseGetApiV2SummaryJson';
136557
+ response = await this.statusPublicSwapInverseGetApiV2SummaryJson();
136282
136558
  }
136283
136559
  }
136284
136560
  else if (marketType === 'future') {
136285
136561
  if (subType === 'linear') {
136286
- method = 'statusPublicFutureLinearGetApiV2SummaryJson';
136562
+ response = await this.statusPublicFutureLinearGetApiV2SummaryJson();
136287
136563
  }
136288
136564
  else if (subType === 'inverse') {
136289
- method = 'statusPublicFutureInverseGetApiV2SummaryJson';
136565
+ response = await this.statusPublicFutureInverseGetApiV2SummaryJson();
136290
136566
  }
136291
136567
  }
136292
136568
  else if (marketType === 'contract') {
136293
- method = 'contractPublicGetHeartbeat';
136569
+ response = await this.contractPublicGetHeartbeat();
136294
136570
  }
136295
136571
  }
136296
- const response = await this[method]();
136572
+ else {
136573
+ response = await this.statusPublicSpotGetApiV2SummaryJson();
136574
+ }
136297
136575
  //
136298
136576
  // statusPublicSpotGetApiV2SummaryJson, statusPublicSwapInverseGetApiV2SummaryJson, statusPublicFutureLinearGetApiV2SummaryJson, statusPublicFutureInverseGetApiV2SummaryJson
136299
136577
  //
@@ -136458,7 +136736,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136458
136736
  let status = undefined;
136459
136737
  let updated = undefined;
136460
136738
  let url = undefined;
136461
- if (method === 'contractPublicGetHeartbeat') {
136739
+ if (marketType === 'contract') {
136462
136740
  const statusRaw = this.safeString(response, 'status');
136463
136741
  status = (statusRaw === 'ok') ? 'ok' : 'maintenance'; // 'ok', 'error'
136464
136742
  updated = this.safeString(response, 'ts');
@@ -136492,11 +136770,13 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136492
136770
  const defaultType = this.safeString(this.options, 'defaultType', 'spot');
136493
136771
  let type = this.safeString(options, 'type', defaultType);
136494
136772
  type = this.safeString(params, 'type', type);
136495
- let method = 'spotPublicGetV1CommonTimestamp';
136773
+ let response = undefined;
136496
136774
  if ((type === 'future') || (type === 'swap')) {
136497
- method = 'contractPublicGetApiV1Timestamp';
136775
+ response = await this.contractPublicGetApiV1Timestamp(params);
136776
+ }
136777
+ else {
136778
+ response = await this.spotPublicGetV1CommonTimestamp(params);
136498
136779
  }
136499
- const response = await this[method](params);
136500
136780
  //
136501
136781
  // spot
136502
136782
  //
@@ -136664,7 +136944,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136664
136944
  return allMarkets;
136665
136945
  }
136666
136946
  async fetchMarketsByTypeAndSubType(type, subType, params = {}) {
136667
- let method = 'spotPublicGetV1CommonSymbols';
136668
136947
  const query = this.omit(params, ['type', 'subType']);
136669
136948
  const spot = (type === 'spot');
136670
136949
  const contract = (type !== 'spot');
@@ -136673,25 +136952,28 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
136673
136952
  let linear = undefined;
136674
136953
  let inverse = undefined;
136675
136954
  const request = {};
136955
+ let response = undefined;
136676
136956
  if (contract) {
136677
136957
  linear = (subType === 'linear');
136678
136958
  inverse = (subType === 'inverse');
136679
136959
  if (linear) {
136680
- method = 'contractPublicGetLinearSwapApiV1SwapContractInfo';
136681
136960
  if (future) {
136682
136961
  request['business_type'] = 'futures';
136683
136962
  }
136963
+ response = await this.contractPublicGetLinearSwapApiV1SwapContractInfo(this.extend(request, query));
136684
136964
  }
136685
136965
  else if (inverse) {
136686
136966
  if (future) {
136687
- method = 'contractPublicGetApiV1ContractContractInfo';
136967
+ response = await this.contractPublicGetApiV1ContractContractInfo(this.extend(request, query));
136688
136968
  }
136689
136969
  else if (swap) {
136690
- method = 'contractPublicGetSwapApiV1SwapContractInfo';
136970
+ response = await this.contractPublicGetSwapApiV1SwapContractInfo(this.extend(request, query));
136691
136971
  }
136692
136972
  }
136693
136973
  }
136694
- const response = await this[method](this.extend(request, query));
136974
+ else {
136975
+ response = await this.spotPublicGetV1CommonSymbols(this.extend(request, query));
136976
+ }
136695
136977
  //
136696
136978
  // spot
136697
136979
  //
@@ -137078,23 +137360,25 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137078
137360
  await this.loadMarkets();
137079
137361
  const market = this.market(symbol);
137080
137362
  const request = {};
137081
- let fieldName = 'symbol';
137082
- let method = 'spotPublicGetMarketDetailMerged';
137363
+ let response = undefined;
137083
137364
  if (market['linear']) {
137084
- method = 'contractPublicGetLinearSwapExMarketDetailMerged';
137085
- fieldName = 'contract_code';
137365
+ request['contract_code'] = market['id'];
137366
+ response = await this.contractPublicGetLinearSwapExMarketDetailMerged(this.extend(request, params));
137086
137367
  }
137087
137368
  else if (market['inverse']) {
137088
137369
  if (market['future']) {
137089
- method = 'contractPublicGetMarketDetailMerged';
137370
+ request['symbol'] = market['id'];
137371
+ response = await this.contractPublicGetMarketDetailMerged(this.extend(request, params));
137090
137372
  }
137091
137373
  else if (market['swap']) {
137092
- method = 'contractPublicGetSwapExMarketDetailMerged';
137093
- fieldName = 'contract_code';
137374
+ request['contract_code'] = market['id'];
137375
+ response = await this.contractPublicGetSwapExMarketDetailMerged(this.extend(request, params));
137094
137376
  }
137095
137377
  }
137096
- request[fieldName] = market['id'];
137097
- 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
+ }
137098
137382
  //
137099
137383
  // spot
137100
137384
  //
@@ -137167,7 +137451,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137167
137451
  }
137168
137452
  let type = undefined;
137169
137453
  let subType = undefined;
137170
- let method = 'spotPublicGetMarketTickers';
137171
137454
  [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
137172
137455
  [subType, params] = this.handleSubTypeAndParams('fetchTickers', market, params);
137173
137456
  const request = {};
@@ -137175,24 +137458,27 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137175
137458
  const swap = (type === 'swap');
137176
137459
  const linear = (subType === 'linear');
137177
137460
  const inverse = (subType === 'inverse');
137461
+ params = this.omit(params, ['type', 'subType']);
137462
+ let response = undefined;
137178
137463
  if (future || swap) {
137179
137464
  if (linear) {
137180
- method = 'contractPublicGetLinearSwapExMarketDetailBatchMerged';
137181
137465
  if (future) {
137182
137466
  request['business_type'] = 'futures';
137183
137467
  }
137468
+ response = await this.contractPublicGetLinearSwapExMarketDetailBatchMerged(this.extend(request, params));
137184
137469
  }
137185
137470
  else if (inverse) {
137186
137471
  if (future) {
137187
- method = 'contractPublicGetMarketDetailBatchMerged';
137472
+ response = await this.contractPublicGetMarketDetailBatchMerged(this.extend(request, params));
137188
137473
  }
137189
137474
  else if (swap) {
137190
- method = 'contractPublicGetSwapExMarketDetailBatchMerged';
137475
+ response = await this.contractPublicGetSwapExMarketDetailBatchMerged(this.extend(request, params));
137191
137476
  }
137192
137477
  }
137193
137478
  }
137194
- params = this.omit(params, ['type', 'subType']);
137195
- const response = await this[method](this.extend(request, params));
137479
+ else {
137480
+ response = await this.spotPublicGetMarketTickers(this.extend(request, params));
137481
+ }
137196
137482
  //
137197
137483
  // spot
137198
137484
  //
@@ -137325,19 +137611,19 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137325
137611
  // 'symbol': market['id'], // spot, future
137326
137612
  // 'contract_code': market['id'], // swap
137327
137613
  };
137328
- let fieldName = 'symbol';
137329
- let method = 'spotPublicGetMarketDepth';
137614
+ let response = undefined;
137330
137615
  if (market['linear']) {
137331
- method = 'contractPublicGetLinearSwapExMarketDepth';
137332
- fieldName = 'contract_code';
137616
+ request['contract_code'] = market['id'];
137617
+ response = await this.contractPublicGetLinearSwapExMarketDepth(this.extend(request, params));
137333
137618
  }
137334
137619
  else if (market['inverse']) {
137335
137620
  if (market['future']) {
137336
- method = 'contractPublicGetMarketDepth';
137621
+ request['symbol'] = market['id'];
137622
+ response = await this.contractPublicGetMarketDepth(this.extend(request, params));
137337
137623
  }
137338
137624
  else if (market['swap']) {
137339
- method = 'contractPublicGetSwapExMarketDepth';
137340
- fieldName = 'contract_code';
137625
+ request['contract_code'] = market['id'];
137626
+ response = await this.contractPublicGetSwapExMarketDepth(this.extend(request, params));
137341
137627
  }
137342
137628
  }
137343
137629
  else {
@@ -137353,9 +137639,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137353
137639
  request['depth'] = limit;
137354
137640
  }
137355
137641
  }
137642
+ request['symbol'] = market['id'];
137643
+ response = await this.spotPublicGetMarketDepth(this.extend(request, params));
137356
137644
  }
137357
- request[fieldName] = market['id'];
137358
- const response = await this[method](this.extend(request, params));
137359
137645
  //
137360
137646
  // spot, future, swap
137361
137647
  //
@@ -137606,7 +137892,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137606
137892
  // 'direct': 'prev', // next, prev
137607
137893
  // 'size': limit, // default 20, max 50
137608
137894
  };
137609
- let method = undefined;
137895
+ let response = undefined;
137610
137896
  if (marketType === 'spot') {
137611
137897
  if (symbol !== undefined) {
137612
137898
  market = this.market(symbol);
@@ -137620,7 +137906,7 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137620
137906
  // request['end-time'] = this.sum (since, 172800000); // 48 hours window
137621
137907
  }
137622
137908
  [request, params] = this.handleUntilOption('end-time', request, params);
137623
- method = 'spotPrivateGetV1OrderMatchresults';
137909
+ response = await this.spotPrivateGetV1OrderMatchresults(this.extend(request, params));
137624
137910
  }
137625
137911
  else {
137626
137912
  if (symbol === undefined) {
@@ -137641,26 +137927,25 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137641
137927
  [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
137642
137928
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
137643
137929
  if (marginMode === 'isolated') {
137644
- method = 'contractPrivatePostLinearSwapApiV3SwapMatchresultsExact';
137930
+ response = await this.contractPrivatePostLinearSwapApiV3SwapMatchresultsExact(this.extend(request, params));
137645
137931
  }
137646
137932
  else if (marginMode === 'cross') {
137647
- method = 'contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact';
137933
+ response = await this.contractPrivatePostLinearSwapApiV3SwapCrossMatchresultsExact(this.extend(request, params));
137648
137934
  }
137649
137935
  }
137650
137936
  else if (market['inverse']) {
137651
137937
  if (marketType === 'future') {
137652
- method = 'contractPrivatePostApiV3ContractMatchresultsExact';
137653
137938
  request['symbol'] = market['settleId'];
137939
+ response = await this.contractPrivatePostApiV3ContractMatchresultsExact(this.extend(request, params));
137654
137940
  }
137655
137941
  else if (marketType === 'swap') {
137656
- method = 'contractPrivatePostSwapApiV3SwapMatchresultsExact';
137942
+ response = await this.contractPrivatePostSwapApiV3SwapMatchresultsExact(this.extend(request, params));
137657
137943
  }
137658
137944
  else {
137659
137945
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchMyTrades() does not support ' + marketType + ' markets');
137660
137946
  }
137661
137947
  }
137662
137948
  }
137663
- const response = await this[method](this.extend(request, params));
137664
137949
  //
137665
137950
  // spot
137666
137951
  //
@@ -137754,31 +138039,33 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137754
138039
  // 'symbol': market['id'], // spot, future
137755
138040
  // 'contract_code': market['id'], // swap
137756
138041
  };
137757
- let fieldName = 'symbol';
137758
- let method = 'spotPublicGetMarketHistoryTrade';
138042
+ if (limit !== undefined) {
138043
+ request['size'] = Math.min(limit, 2000); // max 2000
138044
+ }
138045
+ let response = undefined;
137759
138046
  if (market['future']) {
137760
138047
  if (market['inverse']) {
137761
- method = 'contractPublicGetMarketHistoryTrade';
138048
+ request['symbol'] = market['id'];
138049
+ response = await this.contractPublicGetMarketHistoryTrade(this.extend(request, params));
137762
138050
  }
137763
138051
  else if (market['linear']) {
137764
- method = 'contractPublicGetLinearSwapExMarketHistoryTrade';
137765
- fieldName = 'contract_code';
138052
+ request['contract_code'] = market['id'];
138053
+ response = await this.contractPublicGetLinearSwapExMarketHistoryTrade(this.extend(request, params));
137766
138054
  }
137767
138055
  }
137768
138056
  else if (market['swap']) {
138057
+ request['contract_code'] = market['id'];
137769
138058
  if (market['inverse']) {
137770
- method = 'contractPublicGetSwapExMarketHistoryTrade';
138059
+ response = await this.contractPublicGetSwapExMarketHistoryTrade(this.extend(request, params));
137771
138060
  }
137772
138061
  else if (market['linear']) {
137773
- method = 'contractPublicGetLinearSwapExMarketHistoryTrade';
138062
+ response = await this.contractPublicGetLinearSwapExMarketHistoryTrade(this.extend(request, params));
137774
138063
  }
137775
- fieldName = 'contract_code';
137776
138064
  }
137777
- request[fieldName] = market['id'];
137778
- if (limit !== undefined) {
137779
- request['size'] = Math.min(limit, 2000); // max 2000
138065
+ else {
138066
+ request['symbol'] = market['id'];
138067
+ response = await this.spotPublicGetMarketHistoryTrade(this.extend(request, params));
137780
138068
  }
137781
- const response = await this[method](this.extend(request, params));
137782
138069
  //
137783
138070
  // {
137784
138071
  // "status": "ok",
@@ -137869,109 +138156,111 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
137869
138156
  // 'from': parseInt ((since / 1000).toString ()), spot only
137870
138157
  // 'to': this.seconds (), spot only
137871
138158
  };
137872
- let fieldName = 'symbol';
137873
138159
  const price = this.safeString(params, 'price');
137874
138160
  params = this.omit(params, 'price');
137875
- let method = 'spotPublicGetMarketHistoryCandles';
137876
- if (market['spot']) {
137877
- if (timeframe === '1M' || timeframe === '1y') {
137878
- // for some reason 1M and 1Y does not work with the regular endpoint
137879
- // https://github.com/ccxt/ccxt/issues/18006
137880
- 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
137881
138165
  }
137882
- if (since !== undefined) {
137883
- request['from'] = this.parseToInt(since / 1000);
138166
+ else {
138167
+ limit = 2000; // only used for from/to calculation
137884
138168
  }
137885
- if (limit !== undefined) {
137886
- 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
+ }
137887
138181
  }
137888
138182
  }
137889
- else if (market['future']) {
138183
+ let response = undefined;
138184
+ if (market['future']) {
137890
138185
  if (market['inverse']) {
138186
+ request['symbol'] = market['id'];
137891
138187
  if (price === 'mark') {
137892
- method = 'contractPublicGetIndexMarketHistoryMarkPriceKline';
138188
+ response = await this.contractPublicGetIndexMarketHistoryMarkPriceKline(this.extend(request, params));
137893
138189
  }
137894
138190
  else if (price === 'index') {
137895
- method = 'contractPublicGetIndexMarketHistoryIndex';
138191
+ response = await this.contractPublicGetIndexMarketHistoryIndex(this.extend(request, params));
137896
138192
  }
137897
138193
  else if (price === 'premiumIndex') {
137898
138194
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137899
138195
  }
137900
138196
  else {
137901
- method = 'contractPublicGetMarketHistoryKline';
138197
+ response = await this.contractPublicGetMarketHistoryKline(this.extend(request, params));
137902
138198
  }
137903
138199
  }
137904
138200
  else if (market['linear']) {
138201
+ request['contract_code'] = market['id'];
137905
138202
  if (price === 'mark') {
137906
- method = 'contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline';
138203
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline(this.extend(request, params));
137907
138204
  }
137908
138205
  else if (price === 'index') {
137909
138206
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137910
138207
  }
137911
138208
  else if (price === 'premiumIndex') {
137912
- method = 'contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline';
138209
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline(this.extend(request, params));
137913
138210
  }
137914
138211
  else {
137915
- method = 'contractPublicGetLinearSwapExMarketHistoryKline';
138212
+ response = await this.contractPublicGetLinearSwapExMarketHistoryKline(this.extend(request, params));
137916
138213
  }
137917
- fieldName = 'contract_code';
137918
138214
  }
137919
138215
  }
137920
138216
  else if (market['swap']) {
138217
+ request['contract_code'] = market['id'];
137921
138218
  if (market['inverse']) {
137922
138219
  if (price === 'mark') {
137923
- method = 'contractPublicGetIndexMarketHistorySwapMarkPriceKline';
138220
+ response = await this.contractPublicGetIndexMarketHistorySwapMarkPriceKline(this.extend(request, params));
137924
138221
  }
137925
138222
  else if (price === 'index') {
137926
138223
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137927
138224
  }
137928
138225
  else if (price === 'premiumIndex') {
137929
- method = 'contractPublicGetIndexMarketHistorySwapPremiumIndexKline';
138226
+ response = await this.contractPublicGetIndexMarketHistorySwapPremiumIndexKline(this.extend(request, params));
137930
138227
  }
137931
138228
  else {
137932
- method = 'contractPublicGetSwapExMarketHistoryKline';
138229
+ response = await this.contractPublicGetSwapExMarketHistoryKline(this.extend(request, params));
137933
138230
  }
137934
138231
  }
137935
138232
  else if (market['linear']) {
137936
138233
  if (price === 'mark') {
137937
- method = 'contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline';
138234
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapMarkPriceKline(this.extend(request, params));
137938
138235
  }
137939
138236
  else if (price === 'index') {
137940
138237
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' ' + market['type'] + ' has no api endpoint for ' + price + ' kline data');
137941
138238
  }
137942
138239
  else if (price === 'premiumIndex') {
137943
- method = 'contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline';
138240
+ response = await this.contractPublicGetIndexMarketHistoryLinearSwapPremiumIndexKline(this.extend(request, params));
137944
138241
  }
137945
138242
  else {
137946
- method = 'contractPublicGetLinearSwapExMarketHistoryKline';
138243
+ response = await this.contractPublicGetLinearSwapExMarketHistoryKline(this.extend(request, params));
137947
138244
  }
137948
138245
  }
137949
- fieldName = 'contract_code';
137950
138246
  }
137951
- if (market['contract']) {
138247
+ else {
138248
+ if (since !== undefined) {
138249
+ request['from'] = this.parseToInt(since / 1000);
138250
+ }
137952
138251
  if (limit !== undefined) {
137953
- request['size'] = limit; // when using limit from and to are ignored
137954
- // https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data
138252
+ request['size'] = limit; // max 2000
137955
138253
  }
137956
- else {
137957
- 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));
137958
138259
  }
137959
- if (price === undefined) {
137960
- const duration = this.parseTimeframe(timeframe);
137961
- if (since === undefined) {
137962
- const now = this.seconds();
137963
- request['from'] = now - duration * (limit - 1);
137964
- request['to'] = now;
137965
- }
137966
- else {
137967
- const start = this.parseToInt(since / 1000);
137968
- request['from'] = start;
137969
- request['to'] = this.sum(start, duration * (limit - 1));
137970
- }
138260
+ else {
138261
+ response = await this.spotPublicGetMarketHistoryCandles(this.extend(request, params));
137971
138262
  }
137972
138263
  }
137973
- request[fieldName] = market['id'];
137974
- const response = await this[method](this.extend(request, params));
137975
138264
  //
137976
138265
  // {
137977
138266
  // "status":"ok",
@@ -138588,58 +138877,57 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
138588
138877
  // 'pair': 'BTC-USDT',
138589
138878
  // 'contract_type': 'this_week', // swap, this_week, next_week, quarter, next_ quarter
138590
138879
  };
138591
- let method = undefined;
138880
+ let response = undefined;
138592
138881
  if (marketType === 'spot') {
138593
138882
  const clientOrderId = this.safeString(params, 'clientOrderId');
138594
- method = 'spotPrivateGetV1OrderOrdersOrderId';
138595
138883
  if (clientOrderId !== undefined) {
138596
- method = 'spotPrivateGetV1OrderOrdersGetClientOrder';
138597
138884
  // will be filled below in extend ()
138598
138885
  // they expect clientOrderId instead of client-order-id
138599
138886
  // request['clientOrderId'] = clientOrderId;
138887
+ response = await this.spotPrivateGetV1OrderOrdersGetClientOrder(this.extend(request, params));
138600
138888
  }
138601
138889
  else {
138602
138890
  request['order-id'] = id;
138891
+ response = await this.spotPrivateGetV1OrderOrdersOrderId(this.extend(request, params));
138603
138892
  }
138604
138893
  }
138605
138894
  else {
138606
138895
  if (symbol === undefined) {
138607
138896
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
138608
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
+ }
138609
138906
  request['contract_code'] = market['id'];
138610
138907
  if (market['linear']) {
138611
138908
  let marginMode = undefined;
138612
138909
  [marginMode, params] = this.handleMarginModeAndParams('fetchOrder', params);
138613
138910
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
138614
138911
  if (marginMode === 'isolated') {
138615
- method = 'contractPrivatePostLinearSwapApiV1SwapOrderInfo';
138912
+ response = await this.contractPrivatePostLinearSwapApiV1SwapOrderInfo(this.extend(request, params));
138616
138913
  }
138617
138914
  else if (marginMode === 'cross') {
138618
- method = 'contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo';
138915
+ response = await this.contractPrivatePostLinearSwapApiV1SwapCrossOrderInfo(this.extend(request, params));
138619
138916
  }
138620
138917
  }
138621
138918
  else if (market['inverse']) {
138622
138919
  if (marketType === 'future') {
138623
- method = 'contractPrivatePostApiV1ContractOrderInfo';
138624
138920
  request['symbol'] = market['settleId'];
138921
+ response = await this.contractPrivatePostApiV1ContractOrderInfo(this.extend(request, params));
138625
138922
  }
138626
138923
  else if (marketType === 'swap') {
138627
- method = 'contractPrivatePostSwapApiV1SwapOrderInfo';
138924
+ response = await this.contractPrivatePostSwapApiV1SwapOrderInfo(this.extend(request, params));
138628
138925
  }
138629
138926
  else {
138630
138927
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchOrder() does not support ' + marketType + ' markets');
138631
138928
  }
138632
138929
  }
138633
- const clientOrderId = this.safeString2(params, 'client_order_id', 'clientOrderId');
138634
- if (clientOrderId === undefined) {
138635
- request['order_id'] = id;
138636
- }
138637
- else {
138638
- request['client_order_id'] = clientOrderId;
138639
- params = this.omit(params, ['client_order_id', 'clientOrderId']);
138640
- }
138641
138930
  }
138642
- const response = await this[method](this.extend(request, params));
138643
138931
  //
138644
138932
  // spot
138645
138933
  //
@@ -141338,7 +141626,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141338
141626
  };
141339
141627
  let subType = undefined;
141340
141628
  [subType, params] = this.handleSubTypeAndParams('transfer', undefined, params);
141341
- let method = undefined;
141342
141629
  let fromAccountId = this.convertTypeToAccount(fromAccount);
141343
141630
  let toAccountId = this.convertTypeToAccount(toAccount);
141344
141631
  const toCross = toAccountId === 'cross';
@@ -141351,28 +141638,28 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141351
141638
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.BadRequest(this.id + ' transfer () cannot make a transfer between ' + fromAccount + ' and ' + toAccount);
141352
141639
  }
141353
141640
  const fromOrToFuturesAccount = (fromAccountId === 'futures') || (toAccountId === 'futures');
141641
+ let response = undefined;
141354
141642
  if (fromOrToFuturesAccount) {
141355
141643
  let type = fromAccountId + '-to-' + toAccountId;
141356
141644
  type = this.safeString(params, 'type', type);
141357
141645
  request['type'] = type;
141358
- method = 'spotPrivatePostV1FuturesTransfer';
141646
+ response = await this.spotPrivatePostV1FuturesTransfer(this.extend(request, params));
141359
141647
  }
141360
141648
  else if (fromSpot && toCross) {
141361
- method = 'privatePostCrossMarginTransferIn';
141649
+ response = await this.privatePostCrossMarginTransferIn(this.extend(request, params));
141362
141650
  }
141363
141651
  else if (fromCross && toSpot) {
141364
- method = 'privatePostCrossMarginTransferOut';
141652
+ response = await this.privatePostCrossMarginTransferOut(this.extend(request, params));
141365
141653
  }
141366
141654
  else if (fromSpot && toIsolated) {
141367
141655
  request['symbol'] = toAccountId;
141368
- method = 'privatePostDwTransferInMargin';
141656
+ response = await this.privatePostDwTransferInMargin(this.extend(request, params));
141369
141657
  }
141370
141658
  else if (fromIsolated && toSpot) {
141371
141659
  request['symbol'] = fromAccountId;
141372
- method = 'privatePostDwTransferOutMargin';
141660
+ response = await this.privatePostDwTransferOutMargin(this.extend(request, params));
141373
141661
  }
141374
141662
  else {
141375
- method = 'v2PrivatePostAccountTransfer';
141376
141663
  if (subType === 'linear') {
141377
141664
  if ((fromAccountId === 'swap') || (fromAccount === 'linear-swap')) {
141378
141665
  fromAccountId = 'linear-swap';
@@ -141393,8 +141680,8 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141393
141680
  }
141394
141681
  request['from'] = fromSpot ? 'spot' : fromAccountId;
141395
141682
  request['to'] = toSpot ? 'spot' : toAccountId;
141683
+ response = await this.v2PrivatePostAccountTransfer(this.extend(request, params));
141396
141684
  }
141397
- const response = await this[method](this.extend(request, params));
141398
141685
  //
141399
141686
  // {
141400
141687
  // "code": "200",
@@ -141521,17 +141808,16 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141521
141808
  const request = {
141522
141809
  'contract_code': market['id'],
141523
141810
  };
141524
- let method = undefined;
141811
+ let response = undefined;
141525
141812
  if (market['inverse']) {
141526
- method = 'contractPublicGetSwapApiV1SwapHistoricalFundingRate';
141813
+ response = await this.contractPublicGetSwapApiV1SwapHistoricalFundingRate(this.extend(request, params));
141527
141814
  }
141528
141815
  else if (market['linear']) {
141529
- method = 'contractPublicGetLinearSwapApiV1SwapHistoricalFundingRate';
141816
+ response = await this.contractPublicGetLinearSwapApiV1SwapHistoricalFundingRate(this.extend(request, params));
141530
141817
  }
141531
141818
  else {
141532
141819
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchFundingRateHistory() supports inverse and linear swaps only');
141533
141820
  }
141534
- const response = await this[method](this.extend(request, params));
141535
141821
  //
141536
141822
  // {
141537
141823
  // "status": "ok",
@@ -141627,20 +141913,19 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141627
141913
  */
141628
141914
  await this.loadMarkets();
141629
141915
  const market = this.market(symbol);
141630
- let method = undefined;
141916
+ const request = {
141917
+ 'contract_code': market['id'],
141918
+ };
141919
+ let response = undefined;
141631
141920
  if (market['inverse']) {
141632
- method = 'contractPublicGetSwapApiV1SwapFundingRate';
141921
+ response = await this.contractPublicGetSwapApiV1SwapFundingRate(this.extend(request, params));
141633
141922
  }
141634
141923
  else if (market['linear']) {
141635
- method = 'contractPublicGetLinearSwapApiV1SwapFundingRate';
141924
+ response = await this.contractPublicGetLinearSwapApiV1SwapFundingRate(this.extend(request, params));
141636
141925
  }
141637
141926
  else {
141638
141927
  throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' fetchFundingRate() supports inverse and linear swaps only');
141639
141928
  }
141640
- const request = {
141641
- 'contract_code': market['id'],
141642
- };
141643
- const response = await this[method](this.extend(request, params));
141644
141929
  //
141645
141930
  // {
141646
141931
  // "status": "ok",
@@ -141677,12 +141962,17 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141677
141962
  const request = {
141678
141963
  // 'contract_code': market['id'],
141679
141964
  };
141680
- const method = this.getSupportedMapping(subType, {
141681
- 'linear': 'contractPublicGetLinearSwapApiV1SwapBatchFundingRate',
141682
- 'inverse': 'contractPublicGetSwapApiV1SwapBatchFundingRate',
141683
- });
141684
141965
  params = this.omit(params, 'subType');
141685
- 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
+ }
141686
141976
  //
141687
141977
  // {
141688
141978
  // "status": "ok",
@@ -141729,22 +142019,21 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
141729
142019
  request['size'] = limit;
141730
142020
  }
141731
142021
  let market = undefined;
141732
- let method = undefined;
142022
+ let response = undefined;
141733
142023
  if (marginMode === 'isolated') {
141734
- method = 'privateGetMarginLoanOrders';
141735
142024
  if (symbol !== undefined) {
141736
142025
  market = this.market(symbol);
141737
142026
  request['symbol'] = market['id'];
141738
142027
  }
142028
+ response = await this.privateGetMarginLoanOrders(this.extend(request, params));
141739
142029
  }
141740
142030
  else { // Cross
141741
- method = 'privateGetCrossMarginLoanOrders';
141742
142031
  if (code !== undefined) {
141743
142032
  const currency = this.currency(code);
141744
142033
  request['currency'] = currency['id'];
141745
142034
  }
142035
+ response = await this.privateGetCrossMarginLoanOrders(this.extend(request, params));
141746
142036
  }
141747
- const response = await this[method](this.extend(request, params));
141748
142037
  //
141749
142038
  // {
141750
142039
  // "status":"ok",
@@ -142007,17 +142296,16 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142007
142296
  await this.loadMarkets();
142008
142297
  const market = this.market(symbol);
142009
142298
  const [marketType, query] = this.handleMarketTypeAndParams('fetchFundingHistory', market, params);
142010
- let method = undefined;
142011
142299
  const request = {
142012
142300
  'type': '30,31',
142013
142301
  };
142014
142302
  if (since !== undefined) {
142015
142303
  request['start_date'] = since;
142016
142304
  }
142305
+ let response = undefined;
142017
142306
  if (marketType === 'swap') {
142018
142307
  request['contract'] = market['id'];
142019
142308
  if (market['linear']) {
142020
- method = 'contractPrivatePostLinearSwapApiV3SwapFinancialRecordExact';
142021
142309
  //
142022
142310
  // {
142023
142311
  // "status": "ok",
@@ -142049,9 +142337,9 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142049
142337
  else {
142050
142338
  request['mar_acct'] = market['quoteId'];
142051
142339
  }
142340
+ response = await this.contractPrivatePostLinearSwapApiV3SwapFinancialRecordExact(this.extend(request, query));
142052
142341
  }
142053
142342
  else {
142054
- method = 'contractPrivatePostSwapApiV3SwapFinancialRecordExact';
142055
142343
  //
142056
142344
  // {
142057
142345
  // "code": 200,
@@ -142072,13 +142360,13 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142072
142360
  // "ts": 1604312615051
142073
142361
  // }
142074
142362
  //
142363
+ response = await this.contractPrivatePostSwapApiV3SwapFinancialRecordExact(this.extend(request, query));
142075
142364
  }
142076
142365
  }
142077
142366
  else {
142078
- method = 'contractPrivatePostApiV3ContractFinancialRecordExact';
142079
142367
  request['symbol'] = market['id'];
142368
+ response = await this.contractPrivatePostApiV3ContractFinancialRecordExact(this.extend(request, query));
142080
142369
  }
142081
- const response = await this[method](this.extend(request, query));
142082
142370
  const data = this.safeValue(response, 'data', []);
142083
142371
  return this.parseIncomes(data, market, since, limit);
142084
142372
  }
@@ -142098,15 +142386,29 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142098
142386
  await this.loadMarkets();
142099
142387
  const market = this.market(symbol);
142100
142388
  const [marketType, query] = this.handleMarketTypeAndParams('setLeverage', market, params);
142101
- 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;
142102
142399
  if (market['linear']) {
142103
142400
  let marginMode = undefined;
142104
142401
  [marginMode, params] = this.handleMarginModeAndParams('setLeverage', params);
142105
142402
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
142106
- method = this.getSupportedMapping(marginMode, {
142107
- 'isolated': 'contractPrivatePostLinearSwapApiV1SwapSwitchLeverRate',
142108
- 'cross': 'contractPrivatePostLinearSwapApiV1SwapCrossSwitchLeverRate',
142109
- });
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
+ }
142110
142412
  //
142111
142413
  // {
142112
142414
  // "status": "ok",
@@ -142120,10 +142422,15 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142120
142422
  //
142121
142423
  }
142122
142424
  else {
142123
- method = this.getSupportedMapping(marketType, {
142124
- 'future': 'contractPrivatePostApiV1ContractSwitchLeverRate',
142125
- 'swap': 'contractPrivatePostSwapApiV1SwapSwitchLeverRate',
142126
- });
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
+ }
142127
142434
  //
142128
142435
  // future
142129
142436
  // {
@@ -142141,16 +142448,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142141
142448
  // }
142142
142449
  //
142143
142450
  }
142144
- const request = {
142145
- 'lever_rate': leverage,
142146
- };
142147
- if (marketType === 'future' && market['inverse']) {
142148
- request['symbol'] = market['settleId'];
142149
- }
142150
- else {
142151
- request['contract_code'] = market['id'];
142152
- }
142153
- const response = await this[method](this.extend(request, query));
142154
142451
  return response;
142155
142452
  }
142156
142453
  parseIncome(income, market = undefined) {
@@ -142298,12 +142595,17 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142298
142595
  if (marketType === 'spot') {
142299
142596
  marketType = 'future';
142300
142597
  }
142301
- let method = undefined;
142598
+ let response = undefined;
142302
142599
  if (subType === 'linear') {
142303
- method = this.getSupportedMapping(marginMode, {
142304
- 'isolated': 'contractPrivatePostLinearSwapApiV1SwapPositionInfo',
142305
- 'cross': 'contractPrivatePostLinearSwapApiV1SwapCrossPositionInfo',
142306
- });
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
+ }
142307
142609
  //
142308
142610
  // {
142309
142611
  // "status": "ok",
@@ -142333,10 +142635,15 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142333
142635
  //
142334
142636
  }
142335
142637
  else {
142336
- method = this.getSupportedMapping(marketType, {
142337
- 'future': 'contractPrivatePostApiV1ContractPositionInfo',
142338
- 'swap': 'contractPrivatePostSwapApiV1SwapPositionInfo',
142339
- });
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
+ }
142340
142647
  //
142341
142648
  // future
142342
142649
  // {
@@ -142388,7 +142695,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142388
142695
  // }
142389
142696
  //
142390
142697
  }
142391
- const response = await this[method](params);
142392
142698
  const data = this.safeValue(response, 'data', []);
142393
142699
  const timestamp = this.safeInteger(response, 'ts');
142394
142700
  const result = [];
@@ -142417,12 +142723,27 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142417
142723
  [marginMode, params] = this.handleMarginModeAndParams('fetchPosition', params);
142418
142724
  marginMode = (marginMode === undefined) ? 'cross' : marginMode;
142419
142725
  const [marketType, query] = this.handleMarketTypeAndParams('fetchPosition', market, params);
142420
- 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;
142421
142737
  if (market['linear']) {
142422
- method = this.getSupportedMapping(marginMode, {
142423
- 'isolated': 'contractPrivatePostLinearSwapApiV1SwapAccountPositionInfo',
142424
- 'cross': 'contractPrivatePostLinearSwapApiV1SwapCrossAccountPositionInfo',
142425
- });
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
+ }
142426
142747
  //
142427
142748
  // isolated
142428
142749
  //
@@ -142542,10 +142863,15 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142542
142863
  //
142543
142864
  }
142544
142865
  else {
142545
- method = this.getSupportedMapping(marketType, {
142546
- 'future': 'contractPrivatePostApiV1ContractAccountPositionInfo',
142547
- 'swap': 'contractPrivatePostSwapApiV1SwapAccountPositionInfo',
142548
- });
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
+ }
142549
142875
  //
142550
142876
  // future, swap
142551
142877
  //
@@ -142616,17 +142942,6 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142616
142942
  // }
142617
142943
  //
142618
142944
  }
142619
- const request = {};
142620
- if (market['future'] && market['inverse']) {
142621
- request['symbol'] = market['settleId'];
142622
- }
142623
- else {
142624
- if (marginMode === 'cross') {
142625
- request['margin_account'] = 'USDT'; // only allowed value
142626
- }
142627
- request['contract_code'] = market['id'];
142628
- }
142629
- const response = await this[method](this.extend(request, query));
142630
142945
  const data = this.safeValue(response, 'data');
142631
142946
  let account = undefined;
142632
142947
  if (marginMode === 'cross') {
@@ -142957,26 +143272,28 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
142957
143272
  'period': timeframes[timeframe],
142958
143273
  'amount_type': amountType,
142959
143274
  };
142960
- let method = undefined;
143275
+ if (limit !== undefined) {
143276
+ request['size'] = limit;
143277
+ }
143278
+ let response = undefined;
142961
143279
  if (market['future']) {
142962
143280
  request['contract_type'] = this.safeString(market['info'], 'contract_type');
142963
143281
  request['symbol'] = market['baseId']; // currency code on coin-m futures
142964
- method = 'contractPublicGetApiV1ContractHisOpenInterest'; // coin-m futures
143282
+ // coin-m futures
143283
+ response = await this.contractPublicGetApiV1ContractHisOpenInterest(this.extend(request, params));
142965
143284
  }
142966
143285
  else if (market['linear']) {
142967
143286
  request['contract_type'] = 'swap';
142968
143287
  request['contract_code'] = market['id'];
142969
143288
  request['contract_code'] = market['id'];
142970
- method = 'contractPublicGetLinearSwapApiV1SwapHisOpenInterest'; // USDT-M
143289
+ // USDT-M
143290
+ response = await this.contractPublicGetLinearSwapApiV1SwapHisOpenInterest(this.extend(request, params));
142971
143291
  }
142972
143292
  else {
142973
143293
  request['contract_code'] = market['id'];
142974
- method = 'contractPublicGetSwapApiV1SwapHisOpenInterest'; // coin-m swaps
142975
- }
142976
- if (limit !== undefined) {
142977
- request['size'] = limit;
143294
+ // coin-m swaps
143295
+ response = await this.contractPublicGetSwapApiV1SwapHisOpenInterest(this.extend(request, params));
142978
143296
  }
142979
- const response = await this[method](this.extend(request, params));
142980
143297
  //
142981
143298
  // contractPublicGetlinearSwapApiV1SwapHisOpenInterest
142982
143299
  // {
@@ -143064,20 +143381,22 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
143064
143381
  const request = {
143065
143382
  'contract_code': market['id'],
143066
143383
  };
143067
- let method = undefined;
143384
+ let response = undefined;
143068
143385
  if (market['future']) {
143069
143386
  request['contract_type'] = this.safeString(market['info'], 'contract_type');
143070
143387
  request['symbol'] = market['baseId'];
143071
- method = 'contractPublicGetApiV1ContractOpenInterest'; // COIN-M futures
143388
+ // COIN-M futures
143389
+ response = await this.contractPublicGetApiV1ContractOpenInterest(this.extend(request, params));
143072
143390
  }
143073
143391
  else if (market['linear']) {
143074
143392
  request['contract_type'] = 'swap';
143075
- method = 'contractPublicGetLinearSwapApiV1SwapOpenInterest'; // USDT-M
143393
+ // USDT-M
143394
+ response = await this.contractPublicGetLinearSwapApiV1SwapOpenInterest(this.extend(request, params));
143076
143395
  }
143077
143396
  else {
143078
- method = 'contractPublicGetSwapApiV1SwapOpenInterest'; // COIN-M swaps
143397
+ // COIN-M swaps
143398
+ response = await this.contractPublicGetSwapApiV1SwapOpenInterest(this.extend(request, params));
143079
143399
  }
143080
- const response = await this[method](this.extend(request, params));
143081
143400
  //
143082
143401
  // USDT-M contractPublicGetLinearSwapApiV1SwapOpenInterest
143083
143402
  //
@@ -143427,16 +143746,18 @@ class htx extends _abstract_htx_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
143427
143746
  if (until !== undefined) {
143428
143747
  request['end_at'] = until;
143429
143748
  }
143430
- let method = 'contractPublicGetApiV1ContractSettlementRecords';
143749
+ let response = undefined;
143431
143750
  if (market['swap']) {
143432
143751
  if (market['linear']) {
143433
- method = 'contractPublicGetLinearSwapApiV1SwapSettlementRecords';
143752
+ response = await this.contractPublicGetLinearSwapApiV1SwapSettlementRecords(this.extend(request, params));
143434
143753
  }
143435
143754
  else {
143436
- method = 'contractPublicGetSwapApiV1SwapSettlementRecords';
143755
+ response = await this.contractPublicGetSwapApiV1SwapSettlementRecords(this.extend(request, params));
143437
143756
  }
143438
143757
  }
143439
- const response = await this[method](this.extend(request, params));
143758
+ else {
143759
+ response = await this.contractPublicGetApiV1ContractSettlementRecords(this.extend(request, params));
143760
+ }
143440
143761
  //
143441
143762
  // linear swap, coin-m swap
143442
143763
  //
@@ -161580,6 +161901,8 @@ class kuna extends _abstract_kuna_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
161580
161901
  'fetchWithdrawal': true,
161581
161902
  'fetchWithdrawals': true,
161582
161903
  'reduceMargin': false,
161904
+ 'repayCrossMargin': false,
161905
+ 'repayIsolatedMargin': false,
161583
161906
  'setLeverage': false,
161584
161907
  'setMargin': false,
161585
161908
  'setMarginMode': false,
@@ -171384,6 +171707,8 @@ class mexc extends _abstract_mexc_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"]
171384
171707
  'fetchWithdrawal': undefined,
171385
171708
  'fetchWithdrawals': true,
171386
171709
  'reduceMargin': true,
171710
+ 'repayCrossMargin': false,
171711
+ 'repayIsolatedMargin': false,
171387
171712
  'setLeverage': true,
171388
171713
  'setMarginMode': undefined,
171389
171714
  'setPositionMode': true,
@@ -181726,8 +182051,17 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
181726
182051
  'future': true,
181727
182052
  'option': undefined,
181728
182053
  'cancelOrder': true,
182054
+ 'createMarketBuyOrderWithCost': true,
182055
+ 'createMarketOrderWithCost': false,
182056
+ 'createMarketSellOrderWithCost': false,
181729
182057
  'createOrder': true,
181730
182058
  'fetchBalance': true,
182059
+ 'fetchBorrowInterest': false,
182060
+ 'fetchBorrowRate': false,
182061
+ 'fetchBorrowRateHistories': false,
182062
+ 'fetchBorrowRateHistory': false,
182063
+ 'fetchBorrowRates': false,
182064
+ 'fetchBorrowRatesPerSymbol': false,
181731
182065
  'fetchClosedOrders': true,
181732
182066
  'fetchCurrencies': true,
181733
182067
  'fetchDepositAddress': true,
@@ -181749,6 +182083,10 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
181749
182083
  'fetchTrades': true,
181750
182084
  'fetchTransactions': undefined,
181751
182085
  'fetchWithdrawals': true,
182086
+ 'reduceMargin': false,
182087
+ 'repayCrossMargin': false,
182088
+ 'repayIsolatedMargin': false,
182089
+ 'setMargin': false,
181752
182090
  'transfer': true,
181753
182091
  'withdraw': true,
181754
182092
  },
@@ -182948,6 +183286,26 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
182948
183286
  }
182949
183287
  return this.safeBalance(result);
182950
183288
  }
183289
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
183290
+ /**
183291
+ * @method
183292
+ * @name okcoin#createMarketBuyOrderWithCost
183293
+ * @description create a market buy order by providing the symbol and cost
183294
+ * @see https://www.okcoin.com/docs-v5/en/#rest-api-trade-place-order
183295
+ * @param {string} symbol unified symbol of the market to create an order in
183296
+ * @param {float} cost how much you want to trade in units of the quote currency
183297
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
183298
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
183299
+ */
183300
+ await this.loadMarkets();
183301
+ const market = this.market(symbol);
183302
+ if (!market['spot']) {
183303
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
183304
+ }
183305
+ params['createMarketBuyOrderRequiresPrice'] = false;
183306
+ params['tgtCcy'] = 'quote_ccy';
183307
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
183308
+ }
182951
183309
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
182952
183310
  /**
182953
183311
  * @method
@@ -182974,6 +183332,7 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
182974
183332
  * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
182975
183333
  * @param {float} [params.stopLoss.price] used for stop loss limit orders, not used for stop loss market price orders
182976
183334
  * @param {string} [params.stopLoss.type] 'market' or 'limit' used to specify the stop loss price type
183335
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
182977
183336
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
182978
183337
  */
182979
183338
  await this.loadMarkets();
@@ -183022,7 +183381,7 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
183022
183381
  'ordType': type,
183023
183382
  // 'ordType': type, // privatePostTradeOrder: market, limit, post_only, fok, ioc, optimal_limit_ioc
183024
183383
  // 'ordType': type, // privatePostTradeOrderAlgo: conditional, oco, trigger, move_order_stop, iceberg, twap
183025
- 'sz': this.amountToPrecision(symbol, amount),
183384
+ // 'sz': this.amountToPrecision (symbol, amount),
183026
183385
  // 'px': this.priceToPrecision (symbol, price), // limit orders only
183027
183386
  // 'reduceOnly': false,
183028
183387
  //
@@ -183084,35 +183443,45 @@ class okcoin extends _abstract_okcoin_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
183084
183443
  }
183085
183444
  if (isMarketOrder || marketIOC) {
183086
183445
  request['ordType'] = 'market';
183087
- if ((side === 'buy')) {
183446
+ if (side === 'buy') {
183088
183447
  // spot market buy: "sz" can refer either to base currency units or to quote currency units
183089
183448
  // see documentation: https://www.okx.com/docs-v5/en/#rest-api-trade-place-order
183090
183449
  if (tgtCcy === 'quote_ccy') {
183091
183450
  // quote_ccy: sz refers to units of quote currency
183092
- let notional = this.safeNumber2(params, 'cost', 'sz');
183093
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
183094
- if (createMarketBuyOrderRequiresPrice) {
183095
- if (price !== undefined) {
183096
- if (notional === undefined) {
183097
- const amountString = this.numberToString(amount);
183098
- const priceString = this.numberToString(price);
183099
- const quoteAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
183100
- notional = this.parseNumber(quoteAmount);
183101
- }
183451
+ let quoteAmount = undefined;
183452
+ let createMarketBuyOrderRequiresPrice = true;
183453
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
183454
+ const cost = this.safeNumber2(params, 'cost', 'sz');
183455
+ params = this.omit(params, ['cost', 'sz']);
183456
+ if (cost !== undefined) {
183457
+ quoteAmount = this.costToPrecision(symbol, cost);
183458
+ }
183459
+ else if (createMarketBuyOrderRequiresPrice) {
183460
+ if (price === undefined) {
183461
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.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');
183102
183462
  }
183103
- else if (notional === undefined) {
183104
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder(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 and supply the total cost value in the 'amount' argument or in the 'cost' unified extra parameter or in exchange-specific 'sz' extra parameter (the exchange-specific behaviour)");
183463
+ else {
183464
+ const amountString = this.numberToString(amount);
183465
+ const priceString = this.numberToString(price);
183466
+ const costRequest = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
183467
+ quoteAmount = this.costToPrecision(symbol, costRequest);
183105
183468
  }
183106
183469
  }
183107
183470
  else {
183108
- notional = (notional === undefined) ? amount : notional;
183471
+ quoteAmount = this.costToPrecision(symbol, amount);
183109
183472
  }
183110
- request['sz'] = this.costToPrecision(symbol, notional);
183111
- params = this.omit(params, ['cost', 'sz']);
183473
+ request['sz'] = quoteAmount;
183474
+ }
183475
+ else {
183476
+ request['sz'] = this.amountToPrecision(symbol, amount);
183112
183477
  }
183113
183478
  }
183479
+ else {
183480
+ request['sz'] = this.amountToPrecision(symbol, amount);
183481
+ }
183114
183482
  }
183115
183483
  else {
183484
+ request['sz'] = this.amountToPrecision(symbol, amount);
183116
183485
  if ((!trigger) && (!conditional)) {
183117
183486
  request['px'] = this.priceToPrecision(symbol, price);
183118
183487
  }
@@ -194006,7 +194375,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194006
194375
  'setMarginMode': true,
194007
194376
  'setPositionMode': true,
194008
194377
  'transfer': true,
194009
- 'withdraw': undefined,
194378
+ 'withdraw': true,
194010
194379
  },
194011
194380
  'urls': {
194012
194381
  'logo': 'https://user-images.githubusercontent.com/1294454/85225056-221eb600-b3d7-11ea-930d-564d2690e3f6.jpg',
@@ -194080,6 +194449,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194080
194449
  },
194081
194450
  'v2': {
194082
194451
  'get': {
194452
+ 'public/products': 5,
194083
194453
  'md/v2/orderbook': 5,
194084
194454
  'md/v2/trade': 5,
194085
194455
  'md/v2/ticker/24hr': 5,
@@ -194144,6 +194514,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194144
194514
  'assets/spots/sub-accounts/transfer': 5,
194145
194515
  'assets/futures/sub-accounts/transfer': 5,
194146
194516
  'assets/quote': 5, // ?fromCurrency=<currency>&toCurrency=<currency>&amountEv=<amount>
194517
+ // deposit/withdraw
194147
194518
  },
194148
194519
  'post': {
194149
194520
  // spot
@@ -194387,6 +194758,16 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194387
194758
  'spot': 'spot',
194388
194759
  'swap': 'future',
194389
194760
  },
194761
+ 'stableCoins': [
194762
+ 'BUSD',
194763
+ 'FEI',
194764
+ 'TUSD',
194765
+ 'USD',
194766
+ 'USDC',
194767
+ 'USDD',
194768
+ 'USDP',
194769
+ 'USDT',
194770
+ ],
194390
194771
  'transfer': {
194391
194772
  'fillResponseFromRequest': true,
194392
194773
  },
@@ -194406,6 +194787,8 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194406
194787
  //
194407
194788
  // {
194408
194789
  // "symbol":"BTCUSD",
194790
+ // "code":"1",
194791
+ // "type":"Perpetual",
194409
194792
  // "displaySymbol":"BTC / USD",
194410
194793
  // "indexSymbol":".BTC",
194411
194794
  // "markSymbol":".MBTC",
@@ -194423,9 +194806,10 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194423
194806
  // "minPriceEp":5000,
194424
194807
  // "maxPriceEp":10000000000,
194425
194808
  // "maxOrderQty":1000000,
194426
- // "type":"Perpetual",
194427
194809
  // "status":"Listed",
194428
194810
  // "tipOrderQty":1000000,
194811
+ // "listTime":"1574650800000",
194812
+ // "majorSymbol":true,
194429
194813
  // "steps":"50",
194430
194814
  // "riskLimits":[
194431
194815
  // {"limit":100,"initialMargin":"1.0%","initialMarginEr":1000000,"maintenanceMargin":"0.5%","maintenanceMarginEr":500000},
@@ -194483,7 +194867,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194483
194867
  // "1.0"
194484
194868
  contractSize = this.parseNumber(contractSizeString);
194485
194869
  }
194486
- return {
194870
+ return this.safeMarketStructure({
194487
194871
  'id': id,
194488
194872
  'symbol': base + '/' + quote + ':' + settle,
194489
194873
  'base': base,
@@ -194536,24 +194920,26 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194536
194920
  },
194537
194921
  'created': undefined,
194538
194922
  'info': market,
194539
- };
194923
+ });
194540
194924
  }
194541
194925
  parseSpotMarket(market) {
194542
194926
  //
194543
194927
  // {
194544
194928
  // "symbol":"sBTCUSDT",
194545
194929
  // "code":1001,
194930
+ // "type":"Spot",
194546
194931
  // "displaySymbol":"BTC / USDT",
194547
194932
  // "quoteCurrency":"USDT",
194548
194933
  // "priceScale":8,
194549
194934
  // "ratioScale":8,
194550
194935
  // "pricePrecision":2,
194551
- // "type":"Spot",
194552
194936
  // "baseCurrency":"BTC",
194553
194937
  // "baseTickSize":"0.000001 BTC",
194554
194938
  // "baseTickSizeEv":100,
194555
194939
  // "quoteTickSize":"0.01 USDT",
194556
194940
  // "quoteTickSizeEv":1000000,
194941
+ // "baseQtyPrecision":6,
194942
+ // "quoteQtyPrecision":2,
194557
194943
  // "minOrderValue":"10 USDT",
194558
194944
  // "minOrderValueEv":1000000000,
194559
194945
  // "maxBaseOrderSize":"1000 BTC",
@@ -194564,13 +194950,13 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194564
194950
  // "defaultTakerFeeEr":100000,
194565
194951
  // "defaultMakerFee":"0.001",
194566
194952
  // "defaultMakerFeeEr":100000,
194567
- // "baseQtyPrecision":6,
194568
- // "quoteQtyPrecision":2,
194953
+ // "description":"BTCUSDT is a BTC/USDT spot trading pair. Minimum order value is 1 USDT",
194569
194954
  // "status":"Listed",
194570
194955
  // "tipOrderQty":2,
194571
- // "description":"BTCUSDT is a BTC/USDT spot trading pair. Minimum order value is 1 USDT",
194956
+ // "listTime":1589338800000,
194957
+ // "buyPriceUpperLimitPct":110,
194958
+ // "sellPriceLowerLimitPct":90,
194572
194959
  // "leverage":5
194573
- // "valueScale":8,
194574
194960
  // },
194575
194961
  //
194576
194962
  const type = this.safeStringLower(market, 'type');
@@ -194582,7 +194968,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194582
194968
  const status = this.safeString(market, 'status');
194583
194969
  const precisionAmount = this.parseSafeNumber(this.safeString(market, 'baseTickSize'));
194584
194970
  const precisionPrice = this.parseSafeNumber(this.safeString(market, 'quoteTickSize'));
194585
- return {
194971
+ return this.safeMarketStructure({
194586
194972
  'id': id,
194587
194973
  'symbol': base + '/' + quote,
194588
194974
  'base': base,
@@ -194635,7 +195021,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194635
195021
  },
194636
195022
  'created': undefined,
194637
195023
  'info': market,
194638
- };
195024
+ });
194639
195025
  }
194640
195026
  async fetchMarkets(params = {}) {
194641
195027
  /**
@@ -194645,21 +195031,22 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194645
195031
  * @param {object} [params] extra parameters specific to the exchange API endpoint
194646
195032
  * @returns {object[]} an array of objects representing market data
194647
195033
  */
194648
- const v2Products = await this.publicGetCfgV2Products(params);
195034
+ const v2Products = await this.v2GetPublicProducts(params);
194649
195035
  //
194650
195036
  // {
194651
195037
  // "code":0,
194652
- // "msg":"OK",
195038
+ // "msg":"",
194653
195039
  // "data":{
194654
- // "ratioScale":8,
194655
195040
  // "currencies":[
194656
- // {"code":1,"currency":"BTC","valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"name":"Bitcoin"},
194657
- // {"code":2,"currency":"USD","valueScale":4,"minValueEv":1,"maxValueEv":500000000000000,"name":"USD"},
194658
- // {"code":3,"currency":"USDT","valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"name":"TetherUS"},
195041
+ // {"currency":"BTC","name":"Bitcoin","code":1,"valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"needAddrTag":0,"status":"Listed","displayCurrency":"BTC","inAssetsDisplay":1,"perpetual":0,"stableCoin":0,"assetsPrecision":8},
195042
+ // {"currency":"USD","name":"USD","code":2,"valueScale":4,"minValueEv":1,"maxValueEv":5000000000000000000,"needAddrTag":0,"status":"Listed","displayCurrency":"USD","inAssetsDisplay":1,"perpetual":0,"stableCoin":0,"assetsPrecision":2},
195043
+ // {"currency":"USDT","name":"TetherUS","code":3,"valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"needAddrTag":0,"status":"Listed","displayCurrency":"USDT","inAssetsDisplay":1,"perpetual":2,"stableCoin":1,"assetsPrecision":8},
194659
195044
  // ],
194660
195045
  // "products":[
194661
195046
  // {
194662
195047
  // "symbol":"BTCUSD",
195048
+ // "code":1,
195049
+ // "type":"Perpetual"
194663
195050
  // "displaySymbol":"BTC / USD",
194664
195051
  // "indexSymbol":".BTC",
194665
195052
  // "markSymbol":".MBTC",
@@ -194677,22 +195064,31 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194677
195064
  // "minPriceEp":5000,
194678
195065
  // "maxPriceEp":10000000000,
194679
195066
  // "maxOrderQty":1000000,
194680
- // "type":"Perpetual"
195067
+ // "description":"BTC/USD perpetual contracts are priced on the .BTC Index. Each contract is worth 1 USD. Funding fees are paid and received every 8 hours at UTC time: 00:00, 08:00 and 16:00.",
195068
+ // "status":"Listed",
195069
+ // "tipOrderQty":1000000,
195070
+ // "listTime":1574650800000,
195071
+ // "majorSymbol":true,
195072
+ // "defaultLeverage":"-10",
195073
+ // "fundingInterval":28800,
195074
+ // "maxLeverage":100
194681
195075
  // },
194682
195076
  // {
194683
195077
  // "symbol":"sBTCUSDT",
194684
195078
  // "code":1001,
195079
+ // "type":"Spot",
194685
195080
  // "displaySymbol":"BTC / USDT",
194686
195081
  // "quoteCurrency":"USDT",
194687
195082
  // "priceScale":8,
194688
195083
  // "ratioScale":8,
194689
195084
  // "pricePrecision":2,
194690
- // "type":"Spot",
194691
195085
  // "baseCurrency":"BTC",
194692
195086
  // "baseTickSize":"0.000001 BTC",
194693
195087
  // "baseTickSizeEv":100,
194694
195088
  // "quoteTickSize":"0.01 USDT",
194695
195089
  // "quoteTickSizeEv":1000000,
195090
+ // "baseQtyPrecision":6,
195091
+ // "quoteQtyPrecision":2,
194696
195092
  // "minOrderValue":"10 USDT",
194697
195093
  // "minOrderValueEv":1000000000,
194698
195094
  // "maxBaseOrderSize":"1000 BTC",
@@ -194703,14 +195099,51 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194703
195099
  // "defaultTakerFeeEr":100000,
194704
195100
  // "defaultMakerFee":"0.001",
194705
195101
  // "defaultMakerFeeEr":100000,
194706
- // "baseQtyPrecision":6,
194707
- // "quoteQtyPrecision":2,
195102
+ // "description":"BTCUSDT is a BTC/USDT spot trading pair. Minimum order value is 1 USDT",
194708
195103
  // "status":"Listed",
194709
195104
  // "tipOrderQty":2,
194710
- // "description":"BTCUSDT is a BTC/USDT spot trading pair. Minimum order value is 1 USDT",
195105
+ // "listTime":1589338800000,
195106
+ // "buyPriceUpperLimitPct":110,
195107
+ // "sellPriceLowerLimitPct":90,
194711
195108
  // "leverage":5
194712
195109
  // },
194713
195110
  // ],
195111
+ // "perpProductsV2":[
195112
+ // {
195113
+ // "symbol":"BTCUSDT",
195114
+ // "code":41541,
195115
+ // "type":"PerpetualV2",
195116
+ // "displaySymbol":"BTC / USDT",
195117
+ // "indexSymbol":".BTCUSDT",
195118
+ // "markSymbol":".MBTCUSDT",
195119
+ // "fundingRateSymbol":".BTCUSDTFR",
195120
+ // "fundingRate8hSymbol":".BTCUSDTFR8H",
195121
+ // "contractUnderlyingAssets":"BTC",
195122
+ // "settleCurrency":"USDT",
195123
+ // "quoteCurrency":"USDT",
195124
+ // "tickSize":"0.1",
195125
+ // "priceScale":0,
195126
+ // "ratioScale":0,
195127
+ // "pricePrecision":1,
195128
+ // "baseCurrency":"BTC",
195129
+ // "description":"BTC/USDT perpetual contracts are priced on the .BTCUSDT Index. Each contract is worth 1 BTC. Funding fees are paid and received every 8 hours at UTC time: 00:00, 08:00 and 16:00.",
195130
+ // "status":"Listed",
195131
+ // "tipOrderQty":0,
195132
+ // "listTime":1668225600000,
195133
+ // "majorSymbol":true,
195134
+ // "defaultLeverage":"-10",
195135
+ // "fundingInterval":28800,
195136
+ // "maxLeverage":100,
195137
+ // "maxOrderQtyRq":"1000",
195138
+ // "maxPriceRp":"2000000000",
195139
+ // "minOrderValueRv":"1",
195140
+ // "minPriceRp":"1000.0",
195141
+ // "qtyPrecision":3,
195142
+ // "qtyStepSize":"0.001",
195143
+ // "tipOrderQtyRq":"200",
195144
+ // "maxOpenPosLeverage":100.0
195145
+ // },
195146
+ // ],
194714
195147
  // "riskLimits":[
194715
195148
  // {
194716
195149
  // "symbol":"BTCUSD",
@@ -194726,7 +195159,25 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194726
195159
  // {"initialMargin":"1.0%","initialMarginEr":1000000,"options":[1,2,3,5,10,25,50,100]},
194727
195160
  // {"initialMargin":"1.5%","initialMarginEr":1500000,"options":[1,2,3,5,10,25,50,66]},
194728
195161
  // {"initialMargin":"2.0%","initialMarginEr":2000000,"options":[1,2,3,5,10,25,33,50]},
194729
- // ]
195162
+ // ],
195163
+ // "riskLimitsV2":[
195164
+ // {
195165
+ // "symbol":"BTCUSDT",
195166
+ // "steps":"2000K",
195167
+ // "riskLimits":[
195168
+ // {"limit":2000000,"initialMarginRr":"0.01","maintenanceMarginRr":"0.005"},,
195169
+ // {"limit":4000000,"initialMarginRr":"0.015","maintenanceMarginRr":"0.0075"},
195170
+ // {"limit":6000000,"initialMarginRr":"0.02","maintenanceMarginRr":"0.01"},
195171
+ // ]
195172
+ // },
195173
+ // ],
195174
+ // "leveragesV2":[
195175
+ // {"options":[1.0,2.0,3.0,5.0,10.0,25.0,50.0,100.0],"initialMarginRr":"0.01"},
195176
+ // {"options":[1.0,2.0,3.0,5.0,10.0,25.0,50.0,66.67],"initialMarginRr":"0.015"},
195177
+ // {"options":[1.0,2.0,3.0,5.0,10.0,25.0,33.0,50.0],"initialMarginRr":"0.02"},
195178
+ // ],
195179
+ // "ratioScale":8,
195180
+ // "md5Checksum":"5c6604814d3c1bafbe602c3d11a7e8bf",
194730
195181
  // }
194731
195182
  // }
194732
195183
  //
@@ -194768,8 +195219,12 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194768
195219
  // }
194769
195220
  //
194770
195221
  const v2ProductsData = this.safeValue(v2Products, 'data', {});
194771
- const products = this.safeValue(v2ProductsData, 'products', []);
194772
- const riskLimits = this.safeValue(v2ProductsData, 'riskLimits', []);
195222
+ let products = this.safeValue(v2ProductsData, 'products', []);
195223
+ const perpetualProductsV2 = this.safeValue(v2ProductsData, 'perpProductsV2', []);
195224
+ products = this.arrayConcat(products, perpetualProductsV2);
195225
+ let riskLimits = this.safeValue(v2ProductsData, 'riskLimits', []);
195226
+ const riskLimitsV2 = this.safeValue(v2ProductsData, 'riskLimitsV2', []);
195227
+ riskLimits = this.arrayConcat(riskLimits, riskLimitsV2);
194773
195228
  const currencies = this.safeValue(v2ProductsData, 'currencies', []);
194774
195229
  const riskLimitsById = this.indexBy(riskLimits, 'symbol');
194775
195230
  const v1ProductsById = this.indexBy(v1ProductsData, 'symbol');
@@ -194805,7 +195260,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194805
195260
  * @param {object} [params] extra parameters specific to the exchange API endpoint
194806
195261
  * @returns {object} an associative dictionary of currencies
194807
195262
  */
194808
- const response = await this.publicGetCfgV2Products(params);
195263
+ const response = await this.v2GetPublicProducts(params);
194809
195264
  //
194810
195265
  // {
194811
195266
  // "code":0,
@@ -194813,9 +195268,9 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194813
195268
  // "data":{
194814
195269
  // ...,
194815
195270
  // "currencies":[
194816
- // {"currency":"BTC","valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"name":"Bitcoin"},
194817
- // {"currency":"USD","valueScale":4,"minValueEv":1,"maxValueEv":500000000000000,"name":"USD"},
194818
- // {"currency":"USDT","valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"name":"TetherUS"},
195271
+ // {"currency":"BTC","name":"Bitcoin","code":1,"valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"needAddrTag":0,"status":"Listed","displayCurrency":"BTC","inAssetsDisplay":1,"perpetual":0,"stableCoin":0,"assetsPrecision":8},
195272
+ // {"currency":"USD","name":"USD","code":2,"valueScale":4,"minValueEv":1,"maxValueEv":5000000000000000000,"needAddrTag":0,"status":"Listed","displayCurrency":"USD","inAssetsDisplay":1,"perpetual":0,"stableCoin":0,"assetsPrecision":2},
195273
+ // {"currency":"USDT","name":"TetherUS","code":3,"valueScale":8,"minValueEv":1,"maxValueEv":5000000000000000000,"needAddrTag":0,"status":"Listed","displayCurrency":"USDT","inAssetsDisplay":1,"perpetual":2,"stableCoin":1,"assetsPrecision":8},
194819
195274
  // ],
194820
195275
  // ...
194821
195276
  // }
@@ -194828,6 +195283,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194828
195283
  const id = this.safeString(currency, 'currency');
194829
195284
  const name = this.safeString(currency, 'name');
194830
195285
  const code = this.safeCurrencyCode(id);
195286
+ const status = this.safeString(currency, 'status');
194831
195287
  const valueScaleString = this.safeString(currency, 'valueScale');
194832
195288
  const valueScale = parseInt(valueScaleString);
194833
195289
  const minValueEv = this.safeString(currency, 'minValueEv');
@@ -194846,7 +195302,7 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
194846
195302
  'info': currency,
194847
195303
  'code': code,
194848
195304
  'name': name,
194849
- 'active': undefined,
195305
+ 'active': status === 'Listed',
194850
195306
  'deposit': undefined,
194851
195307
  'withdraw': undefined,
194852
195308
  'fee': undefined,
@@ -198401,6 +198857,48 @@ class phemex extends _abstract_phemex_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
198401
198857
  const sorted = this.sortBy(result, 'timestamp');
198402
198858
  return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
198403
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
+ }
198404
198902
  handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
198405
198903
  if (response === undefined) {
198406
198904
  return undefined; // fallback to default error handler
@@ -198469,6 +198967,9 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
198469
198967
  'cancelAllOrders': true,
198470
198968
  'cancelOrder': true,
198471
198969
  'createDepositAddress': true,
198970
+ 'createMarketBuyOrderWithCost': true,
198971
+ 'createMarketOrderWithCost': false,
198972
+ 'createMarketSellOrderWithCost': false,
198472
198973
  'createOrder': true,
198473
198974
  'editOrder': true,
198474
198975
  'fetchBalance': true,
@@ -198662,6 +199163,7 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
198662
199163
  'UST': 'USTC',
198663
199164
  },
198664
199165
  'options': {
199166
+ 'createMarketBuyOrderRequiresPrice': true,
198665
199167
  'networks': {
198666
199168
  'BEP20': 'BSC',
198667
199169
  'ERC20': 'ETH',
@@ -199685,6 +200187,7 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
199685
200187
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
199686
200188
  * @param {object} [params] extra parameters specific to the exchange API endpoint
199687
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
199688
200191
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
199689
200192
  */
199690
200193
  await this.loadMarkets();
@@ -199720,7 +200223,6 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
199720
200223
  return this.parseOrder(response, market);
199721
200224
  }
199722
200225
  orderRequest(symbol, type, side, amount, request, price = undefined, params = {}) {
199723
- const market = this.market(symbol);
199724
200226
  let upperCaseType = type.toUpperCase();
199725
200227
  const isMarket = upperCaseType === 'MARKET';
199726
200228
  const isPostOnly = this.isPostOnly(isMarket, upperCaseType === 'LIMIT_MAKER', params);
@@ -199736,7 +200238,29 @@ class poloniex extends _abstract_poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
199736
200238
  request['type'] = upperCaseType;
199737
200239
  if (isMarket) {
199738
200240
  if (side === 'buy') {
199739
- 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;
199740
200264
  }
199741
200265
  else {
199742
200266
  request['quantity'] = this.amountToPrecision(symbol, amount);
@@ -204781,7 +205305,7 @@ class binance extends _binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
204781
205305
  const subscribe = {
204782
205306
  'id': requestId,
204783
205307
  };
204784
- 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);
204785
205309
  if (this.newUpdates) {
204786
205310
  const first = this.safeValue(trades, 0);
204787
205311
  const tradeSymbol = this.safeString(first, 'symbol');
@@ -206261,11 +206785,11 @@ class binance extends _binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
206261
206785
  this.setBalanceCache(client, type);
206262
206786
  this.setPositionsCache(client, type);
206263
206787
  const message = undefined;
206264
- const newOrder = await this.watch(url, messageHash, message, type);
206788
+ const orders = await this.watch(url, messageHash, message, type);
206265
206789
  if (this.newUpdates) {
206266
- return newOrder;
206790
+ limit = orders.getLimit(symbol, limit);
206267
206791
  }
206268
- return this.filterBySymbolSinceLimit(this.orders, symbol, since, limit, true);
206792
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
206269
206793
  }
206270
206794
  parseWsOrder(order, market = undefined) {
206271
206795
  //
@@ -206926,8 +207450,8 @@ class binance extends _binance_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
206926
207450
  cachedOrders.append(parsed);
206927
207451
  const messageHash = 'orders';
206928
207452
  const symbolSpecificMessageHash = 'orders:' + symbol;
206929
- client.resolve(parsed, messageHash);
206930
- client.resolve(parsed, symbolSpecificMessageHash);
207453
+ client.resolve(cachedOrders, messageHash);
207454
+ client.resolve(cachedOrders, symbolSpecificMessageHash);
206931
207455
  }
206932
207456
  }
206933
207457
  handleAcountUpdate(client, message) {
@@ -246999,6 +247523,7 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
246999
247523
  * @param {object} [params] extra parameters specific to the poloniex api endpoint
247000
247524
  * @param {string} [params.timeInForce] GTC (default), IOC, FOK
247001
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
247002
247527
  *
247003
247528
  * EXCHANGE SPECIFIC PARAMETERS
247004
247529
  * @param {string} [params.amount] quote units for the order
@@ -247022,25 +247547,29 @@ class poloniex extends _poloniex_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] *
247022
247547
  'type': type.toUpperCase(),
247023
247548
  };
247024
247549
  if ((uppercaseType === 'MARKET') && (uppercaseSide === 'BUY')) {
247025
- let quoteAmount = this.safeString(params, 'amount');
247026
- if ((quoteAmount === undefined) && (this.options['createMarketBuyOrderRequiresPrice'])) {
247027
- const cost = this.safeNumber(params, 'cost');
247028
- params = this.omit(params, 'cost');
247029
- if (price === undefined && cost === undefined) {
247030
- 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');
247031
247561
  }
247032
247562
  else {
247033
247563
  const amountString = this.numberToString(amount);
247034
247564
  const priceString = this.numberToString(price);
247035
- const quote = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
247036
- amount = (cost !== undefined) ? cost : this.parseNumber(quote);
247037
- 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);
247038
247567
  }
247039
247568
  }
247040
247569
  else {
247041
247570
  quoteAmount = this.costToPrecision(symbol, amount);
247042
247571
  }
247043
- request['amount'] = this.amountToPrecision(market['symbol'], quoteAmount);
247572
+ request['amount'] = quoteAmount;
247044
247573
  }
247045
247574
  else {
247046
247575
  request['quantity'] = this.amountToPrecision(market['symbol'], amount);
@@ -264834,6 +265363,9 @@ class tokocrypto extends _abstract_tokocrypto_js__WEBPACK_IMPORTED_MODULE_0__/*
264834
265363
  'cancelOrder': true,
264835
265364
  'cancelOrders': undefined,
264836
265365
  'createDepositAddress': false,
265366
+ 'createMarketBuyOrderWithCost': true,
265367
+ 'createMarketOrderWithCost': false,
265368
+ 'createMarketSellOrderWithCost': false,
264837
265369
  'createOrder': true,
264838
265370
  'createReduceOnlyOrder': undefined,
264839
265371
  'createStopLimitOrder': true,
@@ -264901,6 +265433,8 @@ class tokocrypto extends _abstract_tokocrypto_js__WEBPACK_IMPORTED_MODULE_0__/*
264901
265433
  'fetchWithdrawals': true,
264902
265434
  'fetchWithdrawalWhitelist': false,
264903
265435
  'reduceMargin': false,
265436
+ 'repayCrossMargin': false,
265437
+ 'repayIsolatedMargin': false,
264904
265438
  'setLeverage': false,
264905
265439
  'setMargin': false,
264906
265440
  'setMarginMode': false,
@@ -266376,6 +266910,7 @@ class tokocrypto extends _abstract_tokocrypto_js__WEBPACK_IMPORTED_MODULE_0__/*
266376
266910
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
266377
266911
  * @param {object} [params] extra parameters specific to the exchange API endpoint
266378
266912
  * @param {float} [params.triggerPrice] the price at which a trigger order would be triggered
266913
+ * @param {float} [params.cost] for spot market buy orders, the quote quantity that can be used as an alternative for the amount
266379
266914
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
266380
266915
  */
266381
266916
  await this.loadMarkets();
@@ -266455,20 +266990,30 @@ class tokocrypto extends _abstract_tokocrypto_js__WEBPACK_IMPORTED_MODULE_0__/*
266455
266990
  // LIMIT_MAKER quantity, price
266456
266991
  //
266457
266992
  if (uppercaseType === 'MARKET') {
266458
- const quoteOrderQtyInner = this.safeValue2(params, 'quoteOrderQty', 'cost');
266459
- if (this.options['createMarketBuyOrderRequiresPrice'] && (side === 'buy') && (price === undefined) && (quoteOrderQtyInner === undefined)) {
266460
- 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');
266461
- }
266462
- const precision = market['precision']['price'];
266463
- if (quoteOrderQtyInner !== undefined) {
266464
- request['quoteOrderQty'] = this.decimalToPrecision(quoteOrderQtyInner, _base_functions_number_js__WEBPACK_IMPORTED_MODULE_1__/* .TRUNCATE */ .tk, precision, this.precisionMode);
266465
- params = this.omit(params, ['quoteOrderQty', 'cost']);
266466
- }
266467
- else if (price !== undefined) {
266468
- const amountString = this.numberToString(amount);
266469
- const priceString = this.numberToString(price);
266470
- const quoteOrderQty = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
266471
- request['quoteOrderQty'] = this.decimalToPrecision(quoteOrderQty, _base_functions_number_js__WEBPACK_IMPORTED_MODULE_1__/* .TRUNCATE */ .tk, precision, this.precisionMode);
266993
+ if (side === 'buy') {
266994
+ const precision = market['precision']['price'];
266995
+ let quoteAmount = undefined;
266996
+ let createMarketBuyOrderRequiresPrice = true;
266997
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
266998
+ const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
266999
+ params = this.omit(params, ['cost', 'quoteOrderQty']);
267000
+ if (cost !== undefined) {
267001
+ quoteAmount = cost;
267002
+ }
267003
+ else if (createMarketBuyOrderRequiresPrice) {
267004
+ if (price === undefined) {
267005
+ 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');
267006
+ }
267007
+ else {
267008
+ const amountString = this.numberToString(amount);
267009
+ const priceString = this.numberToString(price);
267010
+ quoteAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
267011
+ }
267012
+ }
267013
+ else {
267014
+ quoteAmount = amount;
267015
+ }
267016
+ request['quoteOrderQty'] = this.decimalToPrecision(quoteAmount, _base_functions_number_js__WEBPACK_IMPORTED_MODULE_1__/* .TRUNCATE */ .tk, precision, this.precisionMode);
266472
267017
  }
266473
267018
  else {
266474
267019
  quantityIsRequired = true;
@@ -271895,6 +272440,8 @@ class wazirx extends _abstract_wazirx_js__WEBPACK_IMPORTED_MODULE_0__/* ["defaul
271895
272440
  'fetchTransfers': false,
271896
272441
  'fetchWithdrawals': false,
271897
272442
  'reduceMargin': false,
272443
+ 'repayCrossMargin': false,
272444
+ 'repayIsolatedMargin': false,
271898
272445
  'setLeverage': false,
271899
272446
  'setMargin': false,
271900
272447
  'setMarginMode': false,
@@ -272842,6 +273389,8 @@ class whitebit extends _abstract_whitebit_js__WEBPACK_IMPORTED_MODULE_0__/* ["de
272842
273389
  'fetchTradingFee': false,
272843
273390
  'fetchTradingFees': true,
272844
273391
  'fetchTransactionFees': true,
273392
+ 'repayCrossMargin': false,
273393
+ 'repayIsolatedMargin': false,
272845
273394
  'setLeverage': true,
272846
273395
  'transfer': true,
272847
273396
  'withdraw': true,
@@ -275123,7 +275672,10 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
275123
275672
  'closeAllPositions': false,
275124
275673
  'closePosition': false,
275125
275674
  'createDepositAddress': false,
275675
+ 'createMarketBuyOrderWithCost': true,
275126
275676
  'createMarketOrder': false,
275677
+ 'createMarketOrderWithCost': false,
275678
+ 'createMarketSellOrderWithCost': false,
275127
275679
  'createOrder': true,
275128
275680
  'createReduceOnlyOrder': true,
275129
275681
  'createStopLimitOrder': false,
@@ -275825,6 +276377,25 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
275825
276377
  }
275826
276378
  return result;
275827
276379
  }
276380
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
276381
+ /**
276382
+ * @method
276383
+ * @name woo#createMarketBuyOrderWithCost
276384
+ * @description create a market buy order by providing the symbol and cost
276385
+ * @see https://docs.woo.org/#send-order
276386
+ * @param {string} symbol unified symbol of the market to create an order in
276387
+ * @param {float} cost how much you want to trade in units of the quote currency
276388
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
276389
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
276390
+ */
276391
+ await this.loadMarkets();
276392
+ const market = this.market(symbol);
276393
+ if (!market['spot']) {
276394
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
276395
+ }
276396
+ params['createMarketBuyOrderRequiresPrice'] = false;
276397
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
276398
+ }
275828
276399
  async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
275829
276400
  /**
275830
276401
  * @method
@@ -275844,9 +276415,11 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
275844
276415
  * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered (perpetual swap markets only)
275845
276416
  * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
275846
276417
  * @param {float} [params.algoType] 'STOP'or 'TRAILING_STOP' or 'OCO' or 'CLOSE_POSITION'
276418
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
275847
276419
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
275848
276420
  */
275849
276421
  const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
276422
+ params = this.omit(params, ['reduceOnly', 'reduce_only']);
275850
276423
  const orderType = type.toUpperCase();
275851
276424
  await this.loadMarkets();
275852
276425
  const market = this.market(symbol);
@@ -275889,26 +276462,29 @@ class woo extends _abstract_woo_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */
275889
276462
  if (isMarket && !isStop) {
275890
276463
  // for market buy it requires the amount of quote currency to spend
275891
276464
  if (market['spot'] && orderSide === 'BUY') {
275892
- const cost = this.safeNumber(params, 'cost');
275893
- if (this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true)) {
275894
- if (cost === undefined) {
275895
- if (price === undefined) {
275896
- throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.InvalidOrder(this.id + " createOrder() requires the price argument for market buy orders to calculate total order cost. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or alternatively, supply the total cost value in the 'order_amount' in exchange-specific parameters");
275897
- }
275898
- else {
275899
- const amountString = this.numberToString(amount);
275900
- const priceString = this.numberToString(price);
275901
- const orderAmount = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
275902
- request['order_amount'] = this.costToPrecision(symbol, orderAmount);
275903
- }
276465
+ let quoteAmount = undefined;
276466
+ let createMarketBuyOrderRequiresPrice = true;
276467
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
276468
+ const cost = this.safeNumber2(params, 'cost', 'order_amount');
276469
+ params = this.omit(params, ['cost', 'order_amount']);
276470
+ if (cost !== undefined) {
276471
+ quoteAmount = this.costToPrecision(symbol, cost);
276472
+ }
276473
+ else if (createMarketBuyOrderRequiresPrice) {
276474
+ if (price === undefined) {
276475
+ throw new _base_errors_js__WEBPACK_IMPORTED_MODULE_1__.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');
275904
276476
  }
275905
276477
  else {
275906
- request['order_amount'] = this.costToPrecision(symbol, cost);
276478
+ const amountString = this.numberToString(amount);
276479
+ const priceString = this.numberToString(price);
276480
+ const costRequest = _base_Precise_js__WEBPACK_IMPORTED_MODULE_3__/* .Precise */ .O.stringMul(amountString, priceString);
276481
+ quoteAmount = this.costToPrecision(symbol, costRequest);
275907
276482
  }
275908
276483
  }
275909
276484
  else {
275910
- request['order_amount'] = this.costToPrecision(symbol, amount);
276485
+ quoteAmount = this.costToPrecision(symbol, amount);
275911
276486
  }
276487
+ request['order_amount'] = quoteAmount;
275912
276488
  }
275913
276489
  else {
275914
276490
  request['order_quantity'] = this.amountToPrecision(symbol, amount);
@@ -287238,7 +287814,7 @@ SOFTWARE.
287238
287814
 
287239
287815
  //-----------------------------------------------------------------------------
287240
287816
  // this is updated by vss.js when building
287241
- const version = '4.1.88';
287817
+ const version = '4.1.90';
287242
287818
  _src_base_Exchange_js__WEBPACK_IMPORTED_MODULE_0__/* .Exchange */ .e.ccxtVersion = version;
287243
287819
  //-----------------------------------------------------------------------------
287244
287820