ccxt 4.1.89 → 4.1.91

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 (65) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.js +936 -358
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +2 -2
  6. package/dist/cjs/src/binance.js +61 -0
  7. package/dist/cjs/src/bitforex.js +2 -0
  8. package/dist/cjs/src/bitget.js +11 -4
  9. package/dist/cjs/src/bitmex.js +2 -0
  10. package/dist/cjs/src/blockchaincom.js +0 -41
  11. package/dist/cjs/src/bybit.js +29 -14
  12. package/dist/cjs/src/coinlist.js +2 -0
  13. package/dist/cjs/src/coinsph.js +2 -0
  14. package/dist/cjs/src/cryptocom.js +2 -0
  15. package/dist/cjs/src/gate.js +276 -11
  16. package/dist/cjs/src/htx.js +264 -219
  17. package/dist/cjs/src/kucoin.js +1 -0
  18. package/dist/cjs/src/kucoinfutures.js +37 -0
  19. package/dist/cjs/src/kuna.js +2 -0
  20. package/dist/cjs/src/mexc.js +2 -0
  21. package/dist/cjs/src/okcoin.js +4 -1
  22. package/dist/cjs/src/phemex.js +160 -26
  23. package/dist/cjs/src/poloniex.js +28 -2
  24. package/dist/cjs/src/pro/binance.js +6 -6
  25. package/dist/cjs/src/pro/bitmart.js +19 -18
  26. package/dist/cjs/src/pro/poloniex.js +15 -10
  27. package/dist/cjs/src/tokocrypto.js +2 -0
  28. package/dist/cjs/src/wazirx.js +2 -0
  29. package/dist/cjs/src/whitebit.js +2 -0
  30. package/dist/cjs/src/zaif.js +2 -3
  31. package/js/ccxt.d.ts +1 -1
  32. package/js/ccxt.js +1 -1
  33. package/js/src/base/Exchange.js +2 -2
  34. package/js/src/binance.d.ts +3 -0
  35. package/js/src/binance.js +61 -0
  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/coinlist.js +2 -0
  43. package/js/src/coinsph.js +2 -0
  44. package/js/src/cryptocom.js +2 -0
  45. package/js/src/gate.d.ts +47 -0
  46. package/js/src/gate.js +276 -11
  47. package/js/src/htx.js +264 -219
  48. package/js/src/kucoin.js +1 -0
  49. package/js/src/kucoinfutures.d.ts +1 -0
  50. package/js/src/kucoinfutures.js +37 -0
  51. package/js/src/kuna.js +2 -0
  52. package/js/src/mexc.js +2 -0
  53. package/js/src/okcoin.js +4 -1
  54. package/js/src/phemex.d.ts +1 -0
  55. package/js/src/phemex.js +160 -26
  56. package/js/src/poloniex.js +28 -2
  57. package/js/src/pro/binance.js +6 -6
  58. package/js/src/pro/bitmart.d.ts +1 -1
  59. package/js/src/pro/bitmart.js +19 -18
  60. package/js/src/pro/poloniex.js +16 -11
  61. package/js/src/tokocrypto.js +2 -0
  62. package/js/src/wazirx.js +2 -0
  63. package/js/src/whitebit.js +2 -0
  64. package/js/src/zaif.js +2 -3
  65. package/package.json +1 -1
package/js/src/gate.js CHANGED
@@ -79,9 +79,14 @@ export default class gate extends Exchange {
79
79
  'future': true,
80
80
  'option': true,
81
81
  'addMargin': true,
82
+ 'borrowCrossMargin': true,
83
+ 'borrowIsolatedMargin': true,
82
84
  'cancelAllOrders': true,
83
85
  'cancelOrder': true,
86
+ 'createMarketBuyOrderWithCost': true,
84
87
  'createMarketOrder': true,
88
+ 'createMarketOrderWithCost': false,
89
+ 'createMarketSellOrderWithCost': false,
85
90
  'createOrder': true,
86
91
  'createOrders': true,
87
92
  'createPostOnlyOrder': true,
@@ -143,6 +148,8 @@ export default class gate extends Exchange {
143
148
  'fetchVolatilityHistory': false,
144
149
  'fetchWithdrawals': true,
145
150
  'reduceMargin': true,
151
+ 'repayCrossMargin': true,
152
+ 'repayIsolatedMargin': true,
146
153
  'setLeverage': true,
147
154
  'setMarginMode': false,
148
155
  'setPositionMode': true,
@@ -3761,6 +3768,7 @@ export default class gate extends Exchange {
3761
3768
  * @param {bool} [params.close] *contract only* Set as true to close the position, with size set to 0
3762
3769
  * @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
3763
3770
  * @param {int} [params.price_type] *contract only* 0 latest deal price, 1 mark price, 2 index price
3771
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
3764
3772
  * @returns {object|undefined} [An order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3765
3773
  */
3766
3774
  await this.loadMarkets();
@@ -3958,9 +3966,15 @@ export default class gate extends Exchange {
3958
3966
  }
3959
3967
  }
3960
3968
  if (contract) {
3961
- const amountToPrecision = this.amountToPrecision(symbol, amount);
3962
- const signedAmount = (side === 'sell') ? Precise.stringNeg(amountToPrecision) : amountToPrecision;
3963
- amount = parseInt(signedAmount);
3969
+ const isClose = this.safeValue(params, 'close');
3970
+ if (isClose) {
3971
+ amount = 0;
3972
+ }
3973
+ else {
3974
+ const amountToPrecision = this.amountToPrecision(symbol, amount);
3975
+ const signedAmount = (side === 'sell') ? Precise.stringNeg(amountToPrecision) : amountToPrecision;
3976
+ amount = parseInt(signedAmount);
3977
+ }
3964
3978
  }
3965
3979
  let request = undefined;
3966
3980
  const nonTriggerOrder = !isStopOrder && (trigger === undefined);
@@ -4008,24 +4022,30 @@ export default class gate extends Exchange {
4008
4022
  // 'auto_borrow': false, // used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
4009
4023
  // 'auto_repay': false, // automatic repayment for automatic borrow loan generated by cross margin order, diabled by default
4010
4024
  };
4011
- const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
4012
4025
  if (isMarketOrder && (side === 'buy')) {
4013
- if (createMarketBuyOrderRequiresPrice) {
4026
+ let quoteAmount = undefined;
4027
+ let createMarketBuyOrderRequiresPrice = true;
4028
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
4029
+ const cost = this.safeNumber(params, 'cost');
4030
+ params = this.omit(params, 'cost');
4031
+ if (cost !== undefined) {
4032
+ quoteAmount = this.costToPrecision(symbol, cost);
4033
+ }
4034
+ else if (createMarketBuyOrderRequiresPrice) {
4014
4035
  if (price === undefined) {
4015
- throw new 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');
4036
+ throw new 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');
4016
4037
  }
4017
4038
  else {
4018
4039
  const amountString = this.numberToString(amount);
4019
4040
  const priceString = this.numberToString(price);
4020
- const cost = this.parseNumber(Precise.stringMul(amountString, priceString));
4021
- request['amount'] = this.costToPrecision(symbol, cost);
4041
+ const costRequest = Precise.stringMul(amountString, priceString);
4042
+ quoteAmount = this.costToPrecision(symbol, costRequest);
4022
4043
  }
4023
4044
  }
4024
4045
  else {
4025
- const cost = this.safeNumber(params, 'cost', amount);
4026
- params = this.omit(params, 'cost');
4027
- request['amount'] = this.costToPrecision(symbol, cost);
4046
+ quoteAmount = this.costToPrecision(symbol, amount);
4028
4047
  }
4048
+ request['amount'] = quoteAmount;
4029
4049
  }
4030
4050
  else {
4031
4051
  request['amount'] = this.amountToPrecision(symbol, amount);
@@ -4155,6 +4175,25 @@ export default class gate extends Exchange {
4155
4175
  }
4156
4176
  return this.extend(request, params);
4157
4177
  }
4178
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
4179
+ /**
4180
+ * @method
4181
+ * @name gate#createMarketBuyOrderWithCost
4182
+ * @description create a market buy order by providing the symbol and cost
4183
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-an-order
4184
+ * @param {string} symbol unified symbol of the market to create an order in
4185
+ * @param {float} cost how much you want to trade in units of the quote currency
4186
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
4187
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
4188
+ */
4189
+ await this.loadMarkets();
4190
+ const market = this.market(symbol);
4191
+ if (!market['spot']) {
4192
+ throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
4193
+ }
4194
+ params['createMarketBuyOrderRequiresPrice'] = false;
4195
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
4196
+ }
4158
4197
  async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
4159
4198
  /**
4160
4199
  * @method
@@ -5740,6 +5779,210 @@ export default class gate extends Exchange {
5740
5779
  }
5741
5780
  return tiers;
5742
5781
  }
5782
+ async repayIsolatedMargin(symbol, code, amount, params = {}) {
5783
+ /**
5784
+ * @method
5785
+ * @name gate#repayMargin
5786
+ * @description repay borrowed margin and interest
5787
+ * @see https://www.gate.io/docs/apiv4/en/#repay-a-loan
5788
+ * @param {string} symbol unified market symbol
5789
+ * @param {string} code unified currency code of the currency to repay
5790
+ * @param {float} amount the amount to repay
5791
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5792
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
5793
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
5794
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5795
+ */
5796
+ await this.loadMarkets();
5797
+ const currency = this.currency(code);
5798
+ const request = {
5799
+ 'currency': currency['id'].toUpperCase(),
5800
+ 'amount': this.currencyToPrecision(code, amount),
5801
+ };
5802
+ const market = this.market(symbol);
5803
+ request['currency_pair'] = market['id'];
5804
+ request['type'] = 'repay';
5805
+ const response = await this.privateMarginPostUniLoans(this.extend(request, params));
5806
+ //
5807
+ // empty response
5808
+ //
5809
+ return this.parseMarginLoan(response, currency);
5810
+ }
5811
+ async repayCrossMargin(code, amount, params = {}) {
5812
+ /**
5813
+ * @method
5814
+ * @name gate#repayCrossMargin
5815
+ * @description repay cross margin borrowed margin and interest
5816
+ * @see https://www.gate.io/docs/developers/apiv4/en/#cross-margin-repayments
5817
+ * @param {string} code unified currency code of the currency to repay
5818
+ * @param {float} amount the amount to repay
5819
+ * @param {string} symbol unified market symbol, required for isolated margin
5820
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5821
+ * @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
5822
+ * @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
5823
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5824
+ */
5825
+ await this.loadMarkets();
5826
+ const currency = this.currency(code);
5827
+ const request = {
5828
+ 'currency': currency['id'].toUpperCase(),
5829
+ 'amount': this.currencyToPrecision(code, amount),
5830
+ };
5831
+ let response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
5832
+ //
5833
+ // [
5834
+ // {
5835
+ // "id": "17",
5836
+ // "create_time": 1620381696159,
5837
+ // "update_time": 1620381696159,
5838
+ // "currency": "EOS",
5839
+ // "amount": "110.553635",
5840
+ // "text": "web",
5841
+ // "status": 2,
5842
+ // "repaid": "110.506649705159",
5843
+ // "repaid_interest": "0.046985294841",
5844
+ // "unpaid_interest": "0.0000074393366667"
5845
+ // }
5846
+ // ]
5847
+ //
5848
+ response = this.safeValue(response, 0);
5849
+ return this.parseMarginLoan(response, currency);
5850
+ }
5851
+ async borrowIsolatedMargin(symbol, code, amount, params = {}) {
5852
+ /**
5853
+ * @method
5854
+ * @name gate#borrowMargin
5855
+ * @description create a loan to borrow margin
5856
+ * @see https://www.gate.io/docs/developers/apiv4/en/#marginuni
5857
+ * @param {string} code unified currency code of the currency to borrow
5858
+ * @param {float} amount the amount to borrow
5859
+ * @param {string} symbol unified market symbol, required for isolated margin
5860
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5861
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
5862
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5863
+ */
5864
+ await this.loadMarkets();
5865
+ const currency = this.currency(code);
5866
+ const request = {
5867
+ 'currency': currency['id'].toUpperCase(),
5868
+ 'amount': this.currencyToPrecision(code, amount),
5869
+ };
5870
+ let response = undefined;
5871
+ const market = this.market(symbol);
5872
+ request['currency_pair'] = market['id'];
5873
+ request['type'] = 'borrow';
5874
+ response = await this.privateMarginPostUniLoans(this.extend(request, params));
5875
+ //
5876
+ // {
5877
+ // "id": "34267567",
5878
+ // "create_time": "1656394778",
5879
+ // "expire_time": "1657258778",
5880
+ // "status": "loaned",
5881
+ // "side": "borrow",
5882
+ // "currency": "USDT",
5883
+ // "rate": "0.0002",
5884
+ // "amount": "100",
5885
+ // "days": 10,
5886
+ // "auto_renew": false,
5887
+ // "currency_pair": "LTC_USDT",
5888
+ // "left": "0",
5889
+ // "repaid": "0",
5890
+ // "paid_interest": "0",
5891
+ // "unpaid_interest": "0.003333333333"
5892
+ // }
5893
+ //
5894
+ return this.parseMarginLoan(response, currency);
5895
+ }
5896
+ async borrowCrossMargin(code, amount, params = {}) {
5897
+ /**
5898
+ * @method
5899
+ * @name gate#borrowMargin
5900
+ * @description create a loan to borrow margin
5901
+ * @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
5902
+ * @param {string} code unified currency code of the currency to borrow
5903
+ * @param {float} amount the amount to borrow
5904
+ * @param {string} symbol unified market symbol, required for isolated margin
5905
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
5906
+ * @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
5907
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5908
+ */
5909
+ await this.loadMarkets();
5910
+ const currency = this.currency(code);
5911
+ const request = {
5912
+ 'currency': currency['id'].toUpperCase(),
5913
+ 'amount': this.currencyToPrecision(code, amount),
5914
+ };
5915
+ const response = await this.privateMarginPostCrossLoans(this.extend(request, params));
5916
+ //
5917
+ // {
5918
+ // "id": "17",
5919
+ // "create_time": 1620381696159,
5920
+ // "update_time": 1620381696159,
5921
+ // "currency": "EOS",
5922
+ // "amount": "110.553635",
5923
+ // "text": "web",
5924
+ // "status": 2,
5925
+ // "repaid": "110.506649705159",
5926
+ // "repaid_interest": "0.046985294841",
5927
+ // "unpaid_interest": "0.0000074393366667"
5928
+ // }
5929
+ //
5930
+ return this.parseMarginLoan(response, currency);
5931
+ }
5932
+ parseMarginLoan(info, currency = undefined) {
5933
+ //
5934
+ // Cross
5935
+ //
5936
+ // {
5937
+ // "id": "17",
5938
+ // "create_time": 1620381696159,
5939
+ // "update_time": 1620381696159,
5940
+ // "currency": "EOS",
5941
+ // "amount": "110.553635",
5942
+ // "text": "web",
5943
+ // "status": 2,
5944
+ // "repaid": "110.506649705159",
5945
+ // "repaid_interest": "0.046985294841",
5946
+ // "unpaid_interest": "0.0000074393366667"
5947
+ // }
5948
+ //
5949
+ // Isolated
5950
+ //
5951
+ // {
5952
+ // "id": "34267567",
5953
+ // "create_time": "1656394778",
5954
+ // "expire_time": "1657258778",
5955
+ // "status": "loaned",
5956
+ // "side": "borrow",
5957
+ // "currency": "USDT",
5958
+ // "rate": "0.0002",
5959
+ // "amount": "100",
5960
+ // "days": 10,
5961
+ // "auto_renew": false,
5962
+ // "currency_pair": "LTC_USDT",
5963
+ // "left": "0",
5964
+ // "repaid": "0",
5965
+ // "paid_interest": "0",
5966
+ // "unpaid_interest": "0.003333333333"
5967
+ // }
5968
+ //
5969
+ const marginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
5970
+ let timestamp = this.safeInteger(info, 'create_time');
5971
+ if (marginMode === 'isolated') {
5972
+ timestamp = this.safeTimestamp(info, 'create_time');
5973
+ }
5974
+ const currencyId = this.safeString(info, 'currency');
5975
+ const marketId = this.safeString(info, 'currency_pair');
5976
+ return {
5977
+ 'id': this.safeInteger(info, 'id'),
5978
+ 'currency': this.safeCurrencyCode(currencyId, currency),
5979
+ 'amount': this.safeNumber(info, 'amount'),
5980
+ 'symbol': this.safeSymbol(marketId, undefined, '_', 'margin'),
5981
+ 'timestamp': timestamp,
5982
+ 'datetime': this.iso8601(timestamp),
5983
+ 'info': info,
5984
+ };
5985
+ }
5743
5986
  sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
5744
5987
  const authentication = api[0]; // public, private
5745
5988
  const type = api[1]; // spot, margin, future, delivery
@@ -6749,6 +6992,28 @@ export default class gate extends Exchange {
6749
6992
  'info': greeks,
6750
6993
  };
6751
6994
  }
6995
+ async closePosition(symbol, side = undefined, params = {}) {
6996
+ /**
6997
+ * @method
6998
+ * @name gate#closePositions
6999
+ * @description closes open positions for a market
7000
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order
7001
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order-2
7002
+ * @see https://www.gate.io/docs/developers/apiv4/en/#create-an-options-order
7003
+ * @param {string} symbol Unified CCXT market symbol
7004
+ * @param {string} side 'buy' or 'sell'
7005
+ * @param {object} [params] extra parameters specific to the okx api endpoint
7006
+ * @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
7007
+ */
7008
+ const request = {
7009
+ 'close': true,
7010
+ };
7011
+ params = this.extend(request, params);
7012
+ if (side === undefined) {
7013
+ side = ''; // side is not used but needs to be present, otherwise crashes in php
7014
+ }
7015
+ return await this.createOrder(symbol, 'market', side, 0, undefined, params);
7016
+ }
6752
7017
  handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
6753
7018
  if (response === undefined) {
6754
7019
  return undefined;