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
package/dist/cjs/ccxt.js CHANGED
@@ -168,7 +168,7 @@ var woo$1 = require('./src/pro/woo.js');
168
168
 
169
169
  //-----------------------------------------------------------------------------
170
170
  // this is updated by vss.js when building
171
- const version = '4.1.88';
171
+ const version = '4.1.90';
172
172
  Exchange["default"].ccxtVersion = version;
173
173
  const exchanges = {
174
174
  'ace': ace,
@@ -3697,7 +3697,7 @@ class Exchange {
3697
3697
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3698
3698
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3699
3699
  */
3700
- if (this.options['createMarketOrderWithCost'] || (this.options['createMarketBuyOrderWithCost'] && this.options['createMarketSellOrderWithCost'])) {
3700
+ if (this.has['createMarketOrderWithCost'] || (this.has['createMarketBuyOrderWithCost'] && this.has['createMarketSellOrderWithCost'])) {
3701
3701
  return await this.createOrder(symbol, 'market', side, cost, 1, params);
3702
3702
  }
3703
3703
  throw new errors.NotSupported(this.id + ' createMarketOrderWithCost() is not supported yet');
@@ -3712,7 +3712,7 @@ class Exchange {
3712
3712
  * @param {object} [params] extra parameters specific to the exchange API endpoint
3713
3713
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3714
3714
  */
3715
- if (this.options['createMarketBuyOrderRequiresPrice'] || this.options['createMarketBuyOrderWithCost']) {
3715
+ if (this.options['createMarketBuyOrderRequiresPrice'] || this.has['createMarketBuyOrderWithCost']) {
3716
3716
  return await this.createOrder(symbol, 'market', 'buy', cost, 1, params);
3717
3717
  }
3718
3718
  throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() is not supported yet');
@@ -31,6 +31,7 @@ class bigone extends bigone$1 {
31
31
  'cancelAllOrders': true,
32
32
  'cancelOrder': true,
33
33
  'createMarketBuyOrderWithCost': true,
34
+ 'createMarketOrderWithCost': false,
34
35
  'createMarketSellOrderWithCost': false,
35
36
  'createOrder': true,
36
37
  'createPostOnlyOrder': true,
@@ -1158,13 +1159,18 @@ class bigone extends bigone$1 {
1158
1159
  /**
1159
1160
  * @method
1160
1161
  * @name bigone#createMarketBuyOrderWithCost
1161
- * @see https://open.big.one/docs/spot_orders.html#create-order
1162
1162
  * @description create a market buy order by providing the symbol and cost
1163
+ * @see https://open.big.one/docs/spot_orders.html#create-order
1163
1164
  * @param {string} symbol unified symbol of the market to create an order in
1164
1165
  * @param {float} cost how much you want to trade in units of the quote currency
1165
1166
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1166
1167
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1167
1168
  */
1169
+ await this.loadMarkets();
1170
+ const market = this.market(symbol);
1171
+ if (!market['spot']) {
1172
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1173
+ }
1168
1174
  params['createMarketBuyOrderRequiresPrice'] = false;
1169
1175
  return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1170
1176
  }
@@ -1183,6 +1189,7 @@ class bigone extends bigone$1 {
1183
1189
  * @param {float} [params.triggerPrice] the price at which a trigger order is triggered at
1184
1190
  * @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
1185
1191
  * @param {string} [params.timeInForce] "GTC", "IOC", or "PO"
1192
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
1186
1193
  *
1187
1194
  * EXCHANGE SPECIFIC PARAMETERS
1188
1195
  * @param {string} operator *stop order only* GTE or LTE (default)
@@ -74,6 +74,8 @@ class bitforex extends bitforex$1 {
74
74
  'fetchWithdrawal': false,
75
75
  'fetchWithdrawals': false,
76
76
  'reduceMargin': false,
77
+ 'repayCrossMargin': false,
78
+ 'repayIsolatedMargin': false,
77
79
  'setLeverage': false,
78
80
  'setMargin': false,
79
81
  'setMarginMode': false,
@@ -3855,7 +3855,7 @@ class bitget extends bitget$1 {
3855
3855
  if (feeCostString !== undefined) {
3856
3856
  // swap
3857
3857
  fee = {
3858
- 'cost': feeCostString,
3858
+ 'cost': this.parseNumber(Precise["default"].stringAbs(feeCostString)),
3859
3859
  'currency': market['settle'],
3860
3860
  };
3861
3861
  }
@@ -3863,10 +3863,17 @@ class bitget extends bitget$1 {
3863
3863
  if (feeDetail !== undefined) {
3864
3864
  const parsedFeeDetail = JSON.parse(feeDetail);
3865
3865
  const feeValues = Object.values(parsedFeeDetail);
3866
- const first = this.safeValue(feeValues, 0);
3866
+ let feeObject = undefined;
3867
+ for (let i = 0; i < feeValues.length; i++) {
3868
+ const feeValue = feeValues[i];
3869
+ if (this.safeValue(feeValue, 'feeCoinCode') !== undefined) {
3870
+ feeObject = feeValue;
3871
+ break;
3872
+ }
3873
+ }
3867
3874
  fee = {
3868
- 'cost': this.safeString(first, 'totalFee'),
3869
- 'currency': this.safeCurrencyCode(this.safeString(first, 'feeCoinCode')),
3875
+ 'cost': this.parseNumber(Precise["default"].stringAbs(this.safeString(feeObject, 'totalFee'))),
3876
+ 'currency': this.safeCurrencyCode(this.safeString(feeObject, 'feeCoinCode')),
3870
3877
  };
3871
3878
  }
3872
3879
  let postOnly = undefined;
@@ -38,6 +38,8 @@ class bitmex extends bitmex$1 {
38
38
  'cancelAllOrders': true,
39
39
  'cancelOrder': true,
40
40
  'cancelOrders': true,
41
+ 'closeAllPositions': false,
42
+ 'closePosition': true,
41
43
  'createOrder': true,
42
44
  'createReduceOnlyOrder': true,
43
45
  'editOrder': true,
@@ -906,47 +906,6 @@ class blockchaincom extends blockchaincom$1 {
906
906
  'fee': fee,
907
907
  };
908
908
  }
909
- async fetchWithdrawalWhitelist(params = {}) {
910
- /**
911
- * @method
912
- * @name blockchaincom#fetchWithdrawalWhitelist
913
- * @description fetch the list of withdrawal addresses on the whitelist
914
- * @param {object} [params] extra parameters specific to the exchange API endpoint
915
- * @returns {object} dictionary with keys beneficiaryId, name, currency
916
- */
917
- await this.loadMarkets();
918
- const response = await this.privateGetWhitelist();
919
- const result = [];
920
- for (let i = 0; i < response.length; i++) {
921
- const entry = response[i];
922
- result.push({
923
- 'beneficiaryId': this.safeString(entry, 'whitelistId'),
924
- 'name': this.safeString(entry, 'name'),
925
- 'currency': this.safeString(entry, 'currency'),
926
- 'info': entry,
927
- });
928
- }
929
- return result;
930
- }
931
- async fetchWithdrawalWhitelistByCurrency(code, params = {}) {
932
- await this.loadMarkets();
933
- const currency = this.currency(code);
934
- const request = {
935
- 'currency': currency['id'],
936
- };
937
- const response = await this.privateGetWhitelistCurrency(this.extend(request, params));
938
- const result = [];
939
- for (let i = 0; i < response.length; i++) {
940
- const entry = response[i];
941
- result.push({
942
- 'beneficiaryId': this.safeString(entry, 'whitelistId'),
943
- 'name': this.safeString(entry, 'name'),
944
- 'currency': this.safeString(entry, 'currency'),
945
- 'info': entry,
946
- });
947
- }
948
- return result;
949
- }
950
909
  async withdraw(code, amount, address, tag = undefined, params = {}) {
951
910
  /**
952
911
  * @method
@@ -944,6 +944,7 @@ class bybit extends bybit$1 {
944
944
  },
945
945
  'precisionMode': number.TICK_SIZE,
946
946
  'options': {
947
+ 'fetchMarkets': ['spot', 'linear', 'inverse', 'option'],
947
948
  'enableUnifiedMargin': undefined,
948
949
  'enableUnifiedAccount': undefined,
949
950
  'createMarketBuyOrderRequiresPrice': true,
@@ -1449,21 +1450,35 @@ class bybit extends bybit$1 {
1449
1450
  if (this.options['adjustForTimeDifference']) {
1450
1451
  await this.loadTimeDifference();
1451
1452
  }
1452
- const promisesUnresolved = [
1453
- this.fetchSpotMarkets(params),
1454
- this.fetchFutureMarkets({ 'category': 'linear' }),
1455
- this.fetchFutureMarkets({ 'category': 'inverse' }),
1456
- this.fetchOptionMarkets({ 'baseCoin': 'BTC' }),
1457
- this.fetchOptionMarkets({ 'baseCoin': 'ETH' }),
1458
- this.fetchOptionMarkets({ 'baseCoin': 'SOL' }),
1459
- ];
1453
+ const promisesUnresolved = [];
1454
+ const fetchMarkets = this.safeValue(this.options, 'fetchMarkets', ['spot', 'linear', 'inverse']);
1455
+ for (let i = 0; i < fetchMarkets.length; i++) {
1456
+ const marketType = fetchMarkets[i];
1457
+ if (marketType === 'spot') {
1458
+ promisesUnresolved.push(this.fetchSpotMarkets(params));
1459
+ }
1460
+ else if (marketType === 'linear') {
1461
+ promisesUnresolved.push(this.fetchFutureMarkets({ 'category': 'linear' }));
1462
+ }
1463
+ else if (marketType === 'inverse') {
1464
+ promisesUnresolved.push(this.fetchFutureMarkets({ 'category': 'inverse' }));
1465
+ }
1466
+ else if (marketType === 'option') {
1467
+ promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'BTC' }));
1468
+ promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'ETH' }));
1469
+ promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'SOL' }));
1470
+ }
1471
+ else {
1472
+ throw new errors.ExchangeError(this.id + ' fetchMarkets() this.options fetchMarkets "' + marketType + '" is not a supported market type');
1473
+ }
1474
+ }
1460
1475
  const promises = await Promise.all(promisesUnresolved);
1461
- const spotMarkets = promises[0];
1462
- const linearMarkets = promises[1];
1463
- const inverseMarkets = promises[2];
1464
- const btcOptionMarkets = promises[3];
1465
- const ethOptionMarkets = promises[4];
1466
- const solOptionMarkets = promises[5];
1476
+ const spotMarkets = this.safeValue(promises, 0, []);
1477
+ const linearMarkets = this.safeValue(promises, 1, []);
1478
+ const inverseMarkets = this.safeValue(promises, 2, []);
1479
+ const btcOptionMarkets = this.safeValue(promises, 3, []);
1480
+ const ethOptionMarkets = this.safeValue(promises, 4, []);
1481
+ const solOptionMarkets = this.safeValue(promises, 5, []);
1467
1482
  const futureMarkets = this.arrayConcat(linearMarkets, inverseMarkets);
1468
1483
  let optionMarkets = this.arrayConcat(btcOptionMarkets, ethOptionMarkets);
1469
1484
  optionMarkets = this.arrayConcat(optionMarkets, solOptionMarkets);
@@ -46,6 +46,8 @@ class coinex extends coinex$1 {
46
46
  'cancelOrders': true,
47
47
  'createDepositAddress': true,
48
48
  'createMarketBuyOrderWithCost': true,
49
+ 'createMarketOrderWithCost': false,
50
+ 'createMarketSellOrderWithCost': false,
49
51
  'createOrder': true,
50
52
  'createOrders': true,
51
53
  'createReduceOnlyOrder': true,
@@ -1926,13 +1928,19 @@ class coinex extends coinex$1 {
1926
1928
  async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1927
1929
  /**
1928
1930
  * @method
1929
- * @name coinex#createMarketBuyWithCost
1931
+ * @name coinex#createMarketBuyOrderWithCost
1930
1932
  * @description create a market buy order by providing the symbol and cost
1933
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_order
1931
1934
  * @param {string} symbol unified symbol of the market to create an order in
1932
1935
  * @param {float} cost how much you want to trade in units of the quote currency
1933
1936
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1934
1937
  * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1935
1938
  */
1939
+ await this.loadMarkets();
1940
+ const market = this.market(symbol);
1941
+ if (!market['spot']) {
1942
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1943
+ }
1936
1944
  params['createMarketBuyOrderRequiresPrice'] = false;
1937
1945
  return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1938
1946
  }
@@ -2098,6 +2106,11 @@ class coinex extends coinex$1 {
2098
2106
  * @method
2099
2107
  * @name coinex#createOrder
2100
2108
  * @description create a trade order
2109
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade001_limit_order
2110
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade003_market_order
2111
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade004_IOC_order
2112
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade005_stop_limit_order
2113
+ * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot003_trade006_stop_market_order
2101
2114
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http017_put_limit
2102
2115
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http018_put_market
2103
2116
  * @see https://viabtc.github.io/coinex_api_en_doc/futures/#docsfutures001_http019_put_limit_stop
@@ -106,6 +106,8 @@ class coinlist extends coinlist$1 {
106
106
  'fetchWithdrawals': false,
107
107
  'fetchWithdrawalWhitelist': false,
108
108
  'reduceMargin': false,
109
+ 'repayCrossMargin': false,
110
+ 'repayIsolatedMargin': false,
109
111
  'setLeverage': false,
110
112
  'setMargin': false,
111
113
  'setMarginMode': false,
@@ -108,6 +108,8 @@ class coinsph extends coinsph$1 {
108
108
  'fetchWithdrawals': true,
109
109
  'fetchWithdrawalWhitelist': false,
110
110
  'reduceMargin': false,
111
+ 'repayCrossMargin': false,
112
+ 'repayIsolatedMargin': false,
111
113
  'setLeverage': false,
112
114
  'setMargin': false,
113
115
  'setMarginMode': false,
@@ -96,6 +96,8 @@ class cryptocom extends cryptocom$1 {
96
96
  'fetchVolatilityHistory': false,
97
97
  'fetchWithdrawals': true,
98
98
  'reduceMargin': false,
99
+ 'repayCrossMargin': false,
100
+ 'repayIsolatedMargin': false,
99
101
  'setLeverage': false,
100
102
  'setMarginMode': false,
101
103
  'setPositionMode': false,
@@ -76,9 +76,14 @@ class gate extends gate$1 {
76
76
  'future': true,
77
77
  'option': true,
78
78
  'addMargin': true,
79
+ 'borrowCrossMargin': true,
80
+ 'borrowIsolatedMargin': true,
79
81
  'cancelAllOrders': true,
80
82
  'cancelOrder': true,
83
+ 'createMarketBuyOrderWithCost': true,
81
84
  'createMarketOrder': true,
85
+ 'createMarketOrderWithCost': false,
86
+ 'createMarketSellOrderWithCost': false,
82
87
  'createOrder': true,
83
88
  'createOrders': true,
84
89
  'createPostOnlyOrder': true,
@@ -140,6 +145,8 @@ class gate extends gate$1 {
140
145
  'fetchVolatilityHistory': false,
141
146
  'fetchWithdrawals': true,
142
147
  'reduceMargin': true,
148
+ 'repayCrossMargin': true,
149
+ 'repayIsolatedMargin': true,
143
150
  'setLeverage': true,
144
151
  'setMarginMode': false,
145
152
  'setPositionMode': true,
@@ -3758,6 +3765,7 @@ class gate extends gate$1 {
3758
3765
  * @param {bool} [params.close] *contract only* Set as true to close the position, with size set to 0
3759
3766
  * @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
3760
3767
  * @param {int} [params.price_type] *contract only* 0 latest deal price, 1 mark price, 2 index price
3768
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
3761
3769
  * @returns {object|undefined} [An order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3762
3770
  */
3763
3771
  await this.loadMarkets();
@@ -3955,9 +3963,15 @@ class gate extends gate$1 {
3955
3963
  }
3956
3964
  }
3957
3965
  if (contract) {
3958
- const amountToPrecision = this.amountToPrecision(symbol, amount);
3959
- const signedAmount = (side === 'sell') ? Precise["default"].stringNeg(amountToPrecision) : amountToPrecision;
3960
- amount = parseInt(signedAmount);
3966
+ const isClose = this.safeValue(params, 'close');
3967
+ if (isClose) {
3968
+ amount = 0;
3969
+ }
3970
+ else {
3971
+ const amountToPrecision = this.amountToPrecision(symbol, amount);
3972
+ const signedAmount = (side === 'sell') ? Precise["default"].stringNeg(amountToPrecision) : amountToPrecision;
3973
+ amount = parseInt(signedAmount);
3974
+ }
3961
3975
  }
3962
3976
  let request = undefined;
3963
3977
  const nonTriggerOrder = !isStopOrder && (trigger === undefined);
@@ -4005,24 +4019,30 @@ class gate extends gate$1 {
4005
4019
  // 'auto_borrow': false, // used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
4006
4020
  // 'auto_repay': false, // automatic repayment for automatic borrow loan generated by cross margin order, diabled by default
4007
4021
  };
4008
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
4009
4022
  if (isMarketOrder && (side === 'buy')) {
4010
- if (createMarketBuyOrderRequiresPrice) {
4023
+ let quoteAmount = undefined;
4024
+ let createMarketBuyOrderRequiresPrice = true;
4025
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
4026
+ const cost = this.safeNumber(params, 'cost');
4027
+ params = this.omit(params, 'cost');
4028
+ if (cost !== undefined) {
4029
+ quoteAmount = this.costToPrecision(symbol, cost);
4030
+ }
4031
+ else if (createMarketBuyOrderRequiresPrice) {
4011
4032
  if (price === undefined) {
4012
- throw new errors.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');
4033
+ throw new errors.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');
4013
4034
  }
4014
4035
  else {
4015
4036
  const amountString = this.numberToString(amount);
4016
4037
  const priceString = this.numberToString(price);
4017
- const cost = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
4018
- request['amount'] = this.costToPrecision(symbol, cost);
4038
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
4039
+ quoteAmount = this.costToPrecision(symbol, costRequest);
4019
4040
  }
4020
4041
  }
4021
4042
  else {
4022
- const cost = this.safeNumber(params, 'cost', amount);
4023
- params = this.omit(params, 'cost');
4024
- request['amount'] = this.costToPrecision(symbol, cost);
4043
+ quoteAmount = this.costToPrecision(symbol, amount);
4025
4044
  }
4045
+ request['amount'] = quoteAmount;
4026
4046
  }
4027
4047
  else {
4028
4048
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -4152,6 +4172,25 @@ class gate extends gate$1 {
4152
4172
  }
4153
4173
  return this.extend(request, params);
4154
4174
  }
4175
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
4176
+ /**
4177
+ * @method
4178
+ * @name gate#createMarketBuyOrderWithCost
4179
+ * @description create a market buy order by providing the symbol and cost
4180
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-an-order
4181
+ * @param {string} symbol unified symbol of the market to create an order in
4182
+ * @param {float} cost how much you want to trade in units of the quote currency
4183
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4184
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4185
+ */
4186
+ await this.loadMarkets();
4187
+ const market = this.market(symbol);
4188
+ if (!market['spot']) {
4189
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
4190
+ }
4191
+ params['createMarketBuyOrderRequiresPrice'] = false;
4192
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
4193
+ }
4155
4194
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
4156
4195
  /**
4157
4196
  * @method
@@ -5737,6 +5776,210 @@ class gate extends gate$1 {
5737
5776
  }
5738
5777
  return tiers;
5739
5778
  }
5779
+ async repayIsolatedMargin(symbol, code, amount, params = {}) {
5780
+ /**
5781
+ * @method
5782
+ * @name gate#repayMargin
5783
+ * @description repay borrowed margin and interest
5784
+ * @see https://www.gate.io/docs/apiv4/en/#repay-a-loan
5785
+ * @param {string} symbol unified market symbol
5786
+ * @param {string} code unified currency code of the currency to repay
5787
+ * @param {float} amount the amount to repay
5788
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5789
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
5790
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
5791
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5792
+ */
5793
+ await this.loadMarkets();
5794
+ const currency = this.currency(code);
5795
+ const request = {
5796
+ 'currency': currency['id'].toUpperCase(),
5797
+ 'amount': this.currencyToPrecision(code, amount),
5798
+ };
5799
+ const market = this.market(symbol);
5800
+ request['currency_pair'] = market['id'];
5801
+ request['type'] = 'repay';
5802
+ const response = await this.privateMarginPostUniLoans(this.extend(request, params));
5803
+ //
5804
+ // empty response
5805
+ //
5806
+ return this.parseMarginLoan(response, currency);
5807
+ }
5808
+ async repayCrossMargin(code, amount, params = {}) {
5809
+ /**
5810
+ * @method
5811
+ * @name gate#repayCrossMargin
5812
+ * @description repay cross margin borrowed margin and interest
5813
+ * @see https://www.gate.io/docs/developers/apiv4/en/#cross-margin-repayments
5814
+ * @param {string} code unified currency code of the currency to repay
5815
+ * @param {float} amount the amount to repay
5816
+ * @param {string} symbol unified market symbol, required for isolated margin
5817
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5818
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
5819
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
5820
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5821
+ */
5822
+ await this.loadMarkets();
5823
+ const currency = this.currency(code);
5824
+ const request = {
5825
+ 'currency': currency['id'].toUpperCase(),
5826
+ 'amount': this.currencyToPrecision(code, amount),
5827
+ };
5828
+ let response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
5829
+ //
5830
+ // [
5831
+ // {
5832
+ // "id": "17",
5833
+ // "create_time": 1620381696159,
5834
+ // "update_time": 1620381696159,
5835
+ // "currency": "EOS",
5836
+ // "amount": "110.553635",
5837
+ // "text": "web",
5838
+ // "status": 2,
5839
+ // "repaid": "110.506649705159",
5840
+ // "repaid_interest": "0.046985294841",
5841
+ // "unpaid_interest": "0.0000074393366667"
5842
+ // }
5843
+ // ]
5844
+ //
5845
+ response = this.safeValue(response, 0);
5846
+ return this.parseMarginLoan(response, currency);
5847
+ }
5848
+ async borrowIsolatedMargin(symbol, code, amount, params = {}) {
5849
+ /**
5850
+ * @method
5851
+ * @name gate#borrowMargin
5852
+ * @description create a loan to borrow margin
5853
+ * @see https://www.gate.io/docs/developers/apiv4/en/#marginuni
5854
+ * @param {string} code unified currency code of the currency to borrow
5855
+ * @param {float} amount the amount to borrow
5856
+ * @param {string} symbol unified market symbol, required for isolated margin
5857
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5858
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
5859
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5860
+ */
5861
+ await this.loadMarkets();
5862
+ const currency = this.currency(code);
5863
+ const request = {
5864
+ 'currency': currency['id'].toUpperCase(),
5865
+ 'amount': this.currencyToPrecision(code, amount),
5866
+ };
5867
+ let response = undefined;
5868
+ const market = this.market(symbol);
5869
+ request['currency_pair'] = market['id'];
5870
+ request['type'] = 'borrow';
5871
+ response = await this.privateMarginPostUniLoans(this.extend(request, params));
5872
+ //
5873
+ // {
5874
+ // "id": "34267567",
5875
+ // "create_time": "1656394778",
5876
+ // "expire_time": "1657258778",
5877
+ // "status": "loaned",
5878
+ // "side": "borrow",
5879
+ // "currency": "USDT",
5880
+ // "rate": "0.0002",
5881
+ // "amount": "100",
5882
+ // "days": 10,
5883
+ // "auto_renew": false,
5884
+ // "currency_pair": "LTC_USDT",
5885
+ // "left": "0",
5886
+ // "repaid": "0",
5887
+ // "paid_interest": "0",
5888
+ // "unpaid_interest": "0.003333333333"
5889
+ // }
5890
+ //
5891
+ return this.parseMarginLoan(response, currency);
5892
+ }
5893
+ async borrowCrossMargin(code, amount, params = {}) {
5894
+ /**
5895
+ * @method
5896
+ * @name gate#borrowMargin
5897
+ * @description create a loan to borrow margin
5898
+ * @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
5899
+ * @param {string} code unified currency code of the currency to borrow
5900
+ * @param {float} amount the amount to borrow
5901
+ * @param {string} symbol unified market symbol, required for isolated margin
5902
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5903
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
5904
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5905
+ */
5906
+ await this.loadMarkets();
5907
+ const currency = this.currency(code);
5908
+ const request = {
5909
+ 'currency': currency['id'].toUpperCase(),
5910
+ 'amount': this.currencyToPrecision(code, amount),
5911
+ };
5912
+ const response = await this.privateMarginPostCrossLoans(this.extend(request, params));
5913
+ //
5914
+ // {
5915
+ // "id": "17",
5916
+ // "create_time": 1620381696159,
5917
+ // "update_time": 1620381696159,
5918
+ // "currency": "EOS",
5919
+ // "amount": "110.553635",
5920
+ // "text": "web",
5921
+ // "status": 2,
5922
+ // "repaid": "110.506649705159",
5923
+ // "repaid_interest": "0.046985294841",
5924
+ // "unpaid_interest": "0.0000074393366667"
5925
+ // }
5926
+ //
5927
+ return this.parseMarginLoan(response, currency);
5928
+ }
5929
+ parseMarginLoan(info, currency = undefined) {
5930
+ //
5931
+ // Cross
5932
+ //
5933
+ // {
5934
+ // "id": "17",
5935
+ // "create_time": 1620381696159,
5936
+ // "update_time": 1620381696159,
5937
+ // "currency": "EOS",
5938
+ // "amount": "110.553635",
5939
+ // "text": "web",
5940
+ // "status": 2,
5941
+ // "repaid": "110.506649705159",
5942
+ // "repaid_interest": "0.046985294841",
5943
+ // "unpaid_interest": "0.0000074393366667"
5944
+ // }
5945
+ //
5946
+ // Isolated
5947
+ //
5948
+ // {
5949
+ // "id": "34267567",
5950
+ // "create_time": "1656394778",
5951
+ // "expire_time": "1657258778",
5952
+ // "status": "loaned",
5953
+ // "side": "borrow",
5954
+ // "currency": "USDT",
5955
+ // "rate": "0.0002",
5956
+ // "amount": "100",
5957
+ // "days": 10,
5958
+ // "auto_renew": false,
5959
+ // "currency_pair": "LTC_USDT",
5960
+ // "left": "0",
5961
+ // "repaid": "0",
5962
+ // "paid_interest": "0",
5963
+ // "unpaid_interest": "0.003333333333"
5964
+ // }
5965
+ //
5966
+ const marginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
5967
+ let timestamp = this.safeInteger(info, 'create_time');
5968
+ if (marginMode === 'isolated') {
5969
+ timestamp = this.safeTimestamp(info, 'create_time');
5970
+ }
5971
+ const currencyId = this.safeString(info, 'currency');
5972
+ const marketId = this.safeString(info, 'currency_pair');
5973
+ return {
5974
+ 'id': this.safeInteger(info, 'id'),
5975
+ 'currency': this.safeCurrencyCode(currencyId, currency),
5976
+ 'amount': this.safeNumber(info, 'amount'),
5977
+ 'symbol': this.safeSymbol(marketId, undefined, '_', 'margin'),
5978
+ 'timestamp': timestamp,
5979
+ 'datetime': this.iso8601(timestamp),
5980
+ 'info': info,
5981
+ };
5982
+ }
5740
5983
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
5741
5984
  const authentication = api[0]; // public, private
5742
5985
  const type = api[1]; // spot, margin, future, delivery
@@ -6746,6 +6989,28 @@ class gate extends gate$1 {
6746
6989
  'info': greeks,
6747
6990
  };
6748
6991
  }
6992
+ async closePosition(symbol, side = undefined, params = {}) {
6993
+ /**
6994
+ * @method
6995
+ * @name gate#closePositions
6996
+ * @description closes open positions for a market
6997
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order
6998
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order-2
6999
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-an-options-order
7000
+ * @param {string} symbol Unified CCXT market symbol
7001
+ * @param {string} side 'buy' or 'sell'
7002
+ * @param {object} [params] extra parameters specific to the okx api endpoint
7003
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7004
+ */
7005
+ const request = {
7006
+ 'close': true,
7007
+ };
7008
+ params = this.extend(request, params);
7009
+ if (side === undefined) {
7010
+ side = ''; // side is not used but needs to be present, otherwise crashes in php
7011
+ }
7012
+ return await this.createOrder(symbol, 'market', side, 0, undefined, params);
7013
+ }
6749
7014
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
6750
7015
  if (response === undefined) {
6751
7016
  return undefined;