ccxt 4.3.28 → 4.3.30

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 (46) hide show
  1. package/README.md +3 -3
  2. package/dist/ccxt.browser.min.js +30 -0
  3. package/dist/ccxt.browser.min.js.LICENSE.txt +12 -0
  4. package/dist/cjs/ccxt.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +6 -0
  6. package/dist/cjs/src/base/ws/OrderBookSide.js +4 -4
  7. package/dist/cjs/src/bingx.js +98 -84
  8. package/dist/cjs/src/bitmart.js +72 -0
  9. package/dist/cjs/src/coinex.js +260 -311
  10. package/dist/cjs/src/kucoin.js +1 -0
  11. package/dist/cjs/src/pro/bitfinex.js +4 -4
  12. package/dist/cjs/src/pro/bitfinex2.js +2 -2
  13. package/dist/cjs/src/pro/bitmex.js +3 -3
  14. package/dist/cjs/src/pro/blockchaincom.js +2 -2
  15. package/dist/cjs/src/pro/cryptocom.js +4 -4
  16. package/dist/cjs/src/pro/deribit.js +9 -9
  17. package/dist/cjs/src/pro/idex.js +1 -1
  18. package/dist/cjs/src/pro/luno.js +4 -5
  19. package/dist/cjs/src/pro/mexc.js +2 -2
  20. package/dist/cjs/src/whitebit.js +55 -5
  21. package/js/ccxt.d.ts +1 -1
  22. package/js/ccxt.js +1 -1
  23. package/js/src/abstract/bingx.d.ts +7 -0
  24. package/js/src/abstract/bitmart.d.ts +1 -0
  25. package/js/src/base/Exchange.js +6 -0
  26. package/js/src/base/ws/Cache.d.ts +1 -1
  27. package/js/src/base/ws/OrderBookSide.d.ts +4 -5
  28. package/js/src/base/ws/OrderBookSide.js +4 -4
  29. package/js/src/bingx.js +98 -84
  30. package/js/src/bitmart.d.ts +2 -1
  31. package/js/src/bitmart.js +72 -0
  32. package/js/src/coinex.d.ts +5 -6
  33. package/js/src/coinex.js +260 -311
  34. package/js/src/kucoin.js +1 -0
  35. package/js/src/pro/bitfinex.js +4 -4
  36. package/js/src/pro/bitfinex2.js +2 -2
  37. package/js/src/pro/bitmex.js +3 -3
  38. package/js/src/pro/blockchaincom.js +2 -2
  39. package/js/src/pro/cryptocom.js +4 -4
  40. package/js/src/pro/deribit.js +9 -9
  41. package/js/src/pro/idex.js +1 -1
  42. package/js/src/pro/luno.js +4 -5
  43. package/js/src/pro/mexc.js +2 -2
  44. package/js/src/whitebit.d.ts +2 -0
  45. package/js/src/whitebit.js +55 -5
  46. package/package.json +4 -2
@@ -76,7 +76,7 @@ class coinex extends coinex$1 {
76
76
  'fetchFundingRates': true,
77
77
  'fetchIndexOHLCV': false,
78
78
  'fetchIsolatedBorrowRate': true,
79
- 'fetchIsolatedBorrowRates': true,
79
+ 'fetchIsolatedBorrowRates': false,
80
80
  'fetchLeverage': 'emulated',
81
81
  'fetchLeverages': true,
82
82
  'fetchLeverageTiers': true,
@@ -4779,113 +4779,106 @@ class coinex extends coinex$1 {
4779
4779
  //
4780
4780
  // fetchDeposits
4781
4781
  //
4782
- // {
4783
- // "coin_deposit_id": 32555985,
4784
- // "create_time": 1673325495,
4785
- // "amount": "12.71",
4786
- // "amount_display": "12.71",
4787
- // "diff_amount": "0",
4788
- // "min_amount": "0",
4789
- // "actual_amount": "12.71",
4790
- // "actual_amount_display": "12.71",
4791
- // "confirmations": 35,
4792
- // "tx_id": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
4793
- // "tx_id_display": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
4794
- // "coin_address": "0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
4795
- // "coin_address_display": "0xe7a3****f4b738",
4796
- // "add_explorer": "https://bscscan.com/address/0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
4797
- // "coin_type": "USDT",
4798
- // "smart_contract_name": "BSC",
4799
- // "transfer_method": "onchain",
4800
- // "status": "finish",
4801
- // "status_display": "finish",
4802
- // "remark": "",
4803
- // "explorer": "https://bscscan.com/tx/0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56"
4804
- // }
4782
+ // {
4783
+ // "deposit_id": 5173806,
4784
+ // "created_at": 1714021652557,
4785
+ // "tx_id": "d9f47d2550397c635cb89a8963118f8fe78ef048bc8b6f0caaeaa7dc6",
4786
+ // "tx_id_display": "",
4787
+ // "ccy": "USDT",
4788
+ // "chain": "TRC20",
4789
+ // "deposit_method": "ON_CHAIN",
4790
+ // "amount": "30",
4791
+ // "actual_amount": "",
4792
+ // "to_address": "TYewD2pVWDUwfNr9A",
4793
+ // "confirmations": 20,
4794
+ // "status": "FINISHED",
4795
+ // "tx_explorer_url": "https://tronscan.org/#/transaction",
4796
+ // "to_addr_explorer_url": "https://tronscan.org/#/address",
4797
+ // "remark": ""
4798
+ // }
4805
4799
  //
4806
4800
  // fetchWithdrawals
4807
4801
  //
4808
- // {
4809
- // "coin_withdraw_id": 20076836,
4810
- // "create_time": 1673325776,
4811
- // "actual_amount": "0.029",
4812
- // "actual_amount_display": "0.029",
4813
- // "amount": "0.03",
4814
- // "amount_display": "0.03",
4815
- // "coin_address": "MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
4816
- // "app_coin_address_display": "MBh****pAb",
4817
- // "coin_address_display": "MBhJcc****UdJpAb",
4818
- // "add_explorer": "https://explorer.viawallet.com/ltc/address/MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
4819
- // "coin_type": "LTC",
4820
- // "confirmations": 7,
4821
- // "explorer": "https://explorer.viawallet.com/ltc/tx/a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9",
4822
- // "fee": "0",
4823
- // "remark": "",
4824
- // "smart_contract_name": "",
4825
- // "status": "finish",
4826
- // "status_display": "finish",
4827
- // "transfer_method": "onchain",
4828
- // "tx_fee": "0.001",
4829
- // "tx_id": "a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9"
4830
- // }
4802
+ // {
4803
+ // "withdraw_id": 259364,
4804
+ // "created_at": 1701323541548,
4805
+ // "withdraw_method": "ON_CHAIN",
4806
+ // "ccy": "USDT",
4807
+ // "amount": "23.845744",
4808
+ // "actual_amount": "22.445744",
4809
+ // "chain": "TRC20",
4810
+ // "tx_fee": "1.4",
4811
+ // "fee_asset": "USDT",
4812
+ // "fee_amount": "1.4",
4813
+ // "to_address": "T8t5i2454dhdhnnnGdi49vMbihvY",
4814
+ // "memo": "",
4815
+ // "tx_id": "1237623941964de9954ed2e36640228d78765c1026",
4816
+ // "confirmations": 18,
4817
+ // "explorer_address_url": "https://tronscan.org/#/address",
4818
+ // "explorer_tx_url": "https://tronscan.org/#/transaction",
4819
+ // "remark": "",
4820
+ // "status": "finished"
4821
+ // }
4831
4822
  //
4832
- const id = this.safeString2(transaction, 'coin_withdraw_id', 'coin_deposit_id');
4833
- const address = this.safeString(transaction, 'coin_address');
4834
- let tag = this.safeString(transaction, 'remark'); // set but unused
4823
+ const address = this.safeString(transaction, 'to_address');
4824
+ let tag = this.safeString(transaction, 'memo');
4835
4825
  if (tag !== undefined) {
4836
4826
  if (tag.length < 1) {
4837
4827
  tag = undefined;
4838
4828
  }
4839
4829
  }
4840
- let txid = this.safeValue(transaction, 'tx_id');
4830
+ let remark = this.safeString(transaction, 'remark');
4831
+ if (remark !== undefined) {
4832
+ if (remark.length < 1) {
4833
+ remark = undefined;
4834
+ }
4835
+ }
4836
+ let txid = this.safeString(transaction, 'tx_id');
4841
4837
  if (txid !== undefined) {
4842
4838
  if (txid.length < 1) {
4843
4839
  txid = undefined;
4844
4840
  }
4845
4841
  }
4846
- const currencyId = this.safeString(transaction, 'coin_type');
4842
+ const currencyId = this.safeString(transaction, 'ccy');
4847
4843
  const code = this.safeCurrencyCode(currencyId, currency);
4848
- const timestamp = this.safeTimestamp(transaction, 'create_time');
4849
- const type = ('coin_withdraw_id' in transaction) ? 'withdrawal' : 'deposit';
4850
- const status = this.parseTransactionStatus(this.safeString(transaction, 'status'));
4851
- const networkId = this.safeString(transaction, 'smart_contract_name');
4852
- const amount = this.safeNumber(transaction, 'actual_amount');
4844
+ const timestamp = this.safeInteger(transaction, 'created_at');
4845
+ const type = ('withdraw_id' in transaction) ? 'withdrawal' : 'deposit';
4846
+ const networkId = this.safeString(transaction, 'chain');
4853
4847
  let feeCost = this.safeString(transaction, 'tx_fee');
4854
- const transferMethod = this.safeString(transaction, 'transfer_method');
4848
+ const transferMethod = this.safeStringLower2(transaction, 'withdraw_method', 'deposit_method');
4855
4849
  const internal = transferMethod === 'local';
4856
- let addressTo = undefined;
4857
- let addressFrom = undefined;
4850
+ let amount = this.safeNumber(transaction, 'actual_amount');
4851
+ if (amount === undefined) {
4852
+ amount = this.safeNumber(transaction, 'amount');
4853
+ }
4858
4854
  if (type === 'deposit') {
4859
4855
  feeCost = '0';
4860
- addressTo = address;
4861
- }
4862
- else {
4863
- addressFrom = address;
4864
4856
  }
4857
+ const feeCurrencyId = this.safeString(transaction, 'fee_asset');
4865
4858
  const fee = {
4866
4859
  'cost': this.parseNumber(feeCost),
4867
- 'currency': code,
4860
+ 'currency': this.safeCurrencyCode(feeCurrencyId),
4868
4861
  };
4869
4862
  return {
4870
4863
  'info': transaction,
4871
- 'id': id,
4864
+ 'id': this.safeString2(transaction, 'withdraw_id', 'deposit_id'),
4872
4865
  'txid': txid,
4873
4866
  'timestamp': timestamp,
4874
4867
  'datetime': this.iso8601(timestamp),
4875
4868
  'network': this.networkIdToCode(networkId),
4876
4869
  'address': address,
4877
- 'addressTo': undefined,
4870
+ 'addressTo': address,
4878
4871
  'addressFrom': undefined,
4879
4872
  'tag': tag,
4880
- 'tagTo': addressTo,
4881
- 'tagFrom': addressFrom,
4873
+ 'tagTo': undefined,
4874
+ 'tagFrom': undefined,
4882
4875
  'type': type,
4883
- 'amount': this.parseNumber(amount),
4876
+ 'amount': amount,
4884
4877
  'currency': code,
4885
- 'status': status,
4878
+ 'status': this.parseTransactionStatus(this.safeString(transaction, 'status')),
4886
4879
  'updated': undefined,
4887
4880
  'fee': fee,
4888
- 'comment': undefined,
4881
+ 'comment': remark,
4889
4882
  'internal': internal,
4890
4883
  };
4891
4884
  }
@@ -5032,66 +5025,57 @@ class coinex extends coinex$1 {
5032
5025
  * @method
5033
5026
  * @name coinex#fetchWithdrawals
5034
5027
  * @description fetch all withdrawals made from an account
5035
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account026_withdraw_list
5036
- * @param {string} code unified currency code
5028
+ * @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-withdrawal-history
5029
+ * @param {string} [code] unified currency code
5037
5030
  * @param {int} [since] the earliest time in ms to fetch withdrawals for
5038
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
5031
+ * @param {int} [limit] the maximum number of withdrawal structures to retrieve
5039
5032
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5040
5033
  * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
5041
5034
  */
5035
+ await this.loadMarkets();
5042
5036
  const request = {};
5043
5037
  let currency = undefined;
5044
5038
  if (code !== undefined) {
5045
- await this.loadMarkets();
5046
5039
  currency = this.currency(code);
5047
- request['coin_type'] = currency['id'];
5040
+ request['ccy'] = currency['id'];
5048
5041
  }
5049
5042
  if (limit !== undefined) {
5050
- request['Limit'] = limit;
5043
+ request['limit'] = limit;
5051
5044
  }
5052
- const response = await this.v1PrivateGetBalanceCoinWithdraw(this.extend(request, params));
5045
+ const response = await this.v2PrivateGetAssetsWithdraw(this.extend(request, params));
5053
5046
  //
5054
- // {
5055
- // "code": 0,
5056
- // "data": {
5057
- // "has_next": false,
5058
- // "curr_page": 1,
5059
- // "count": 1,
5060
- // "data": [
5061
- // {
5062
- // "coin_withdraw_id": 20076836,
5063
- // "create_time": 1673325776,
5064
- // "actual_amount": "0.029",
5065
- // "actual_amount_display": "0.029",
5066
- // "amount": "0.03",
5067
- // "amount_display": "0.03",
5068
- // "coin_address": "MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
5069
- // "app_coin_address_display": "MBh****pAb",
5070
- // "coin_address_display": "MBhJcc****UdJpAb",
5071
- // "add_explorer": "https://explorer.viawallet.com/ltc/address/MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
5072
- // "coin_type": "LTC",
5073
- // "confirmations": 7,
5074
- // "explorer": "https://explorer.viawallet.com/ltc/tx/a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9",
5075
- // "fee": "0",
5076
- // "remark": "",
5077
- // "smart_contract_name": "",
5078
- // "status": "finish",
5079
- // "status_display": "finish",
5080
- // "transfer_method": "onchain",
5081
- // "tx_fee": "0.001",
5082
- // "tx_id": "a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9"
5083
- // }
5084
- // ],
5085
- // "total": 1,
5086
- // "total_page": 1
5087
- // },
5088
- // "message": "Success"
5089
- // }
5047
+ // {
5048
+ // "data": [
5049
+ // {
5050
+ // "withdraw_id": 259364,
5051
+ // "created_at": 1701323541548,
5052
+ // "withdraw_method": "ON_CHAIN",
5053
+ // "ccy": "USDT",
5054
+ // "amount": "23.845744",
5055
+ // "actual_amount": "22.445744",
5056
+ // "chain": "TRC20",
5057
+ // "tx_fee": "1.4",
5058
+ // "fee_asset": "USDT",
5059
+ // "fee_amount": "1.4",
5060
+ // "to_address": "T8t5i2454dhdhnnnGdi49vMbihvY",
5061
+ // "memo": "",
5062
+ // "tx_id": "1237623941964de9954ed2e36640228d78765c1026",
5063
+ // "confirmations": 18,
5064
+ // "explorer_address_url": "https://tronscan.org/#/address",
5065
+ // "explorer_tx_url": "https://tronscan.org/#/transaction",
5066
+ // "remark": "",
5067
+ // "status": "finished"
5068
+ // },
5069
+ // ],
5070
+ // "pagination": {
5071
+ // "total": 9,
5072
+ // "has_next": true
5073
+ // },
5074
+ // "code": 0,
5075
+ // "message": "OK"
5076
+ // }
5090
5077
  //
5091
- let data = this.safeValue(response, 'data');
5092
- if (!Array.isArray(data)) {
5093
- data = this.safeValue(data, 'data', []);
5094
- }
5078
+ const data = this.safeList(response, 'data', []);
5095
5079
  return this.parseTransactions(data, currency, since, limit);
5096
5080
  }
5097
5081
  async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
@@ -5099,95 +5083,85 @@ class coinex extends coinex$1 {
5099
5083
  * @method
5100
5084
  * @name coinex#fetchDeposits
5101
5085
  * @description fetch all deposits made to an account
5102
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account009_deposit_list
5103
- * @param {string} code unified currency code
5086
+ * @see https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-deposit-history
5087
+ * @param {string} [code] unified currency code
5104
5088
  * @param {int} [since] the earliest time in ms to fetch deposits for
5105
- * @param {int} [limit] the maximum number of deposits structures to retrieve
5089
+ * @param {int} [limit] the maximum number of deposit structures to retrieve
5106
5090
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5107
5091
  * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
5108
5092
  */
5093
+ await this.loadMarkets();
5109
5094
  const request = {};
5110
5095
  let currency = undefined;
5111
5096
  if (code !== undefined) {
5112
- await this.loadMarkets();
5113
5097
  currency = this.currency(code);
5114
- request['coin_type'] = currency['id'];
5098
+ request['ccy'] = currency['id'];
5115
5099
  }
5116
5100
  if (limit !== undefined) {
5117
- request['Limit'] = limit;
5101
+ request['limit'] = limit;
5118
5102
  }
5119
- const response = await this.v1PrivateGetBalanceCoinDeposit(this.extend(request, params));
5103
+ const response = await this.v2PrivateGetAssetsDepositHistory(this.extend(request, params));
5120
5104
  //
5121
- // {
5122
- // "code": 0,
5123
- // "data": {
5124
- // "has_next": false,
5125
- // "curr_page": 1,
5126
- // "count": 1,
5127
- // "data": [
5128
- // {
5129
- // "coin_deposit_id": 32555985,
5130
- // "create_time": 1673325495,
5131
- // "amount": "12.71",
5132
- // "amount_display": "12.71",
5133
- // "diff_amount": "0",
5134
- // "min_amount": "0",
5135
- // "actual_amount": "12.71",
5136
- // "actual_amount_display": "12.71",
5137
- // "confirmations": 35,
5138
- // "tx_id": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
5139
- // "tx_id_display": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
5140
- // "coin_address": "0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
5141
- // "coin_address_display": "0xe7a3****f4b738",
5142
- // "add_explorer": "https://bscscan.com/address/0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
5143
- // "coin_type": "USDT",
5144
- // "smart_contract_name": "BSC",
5145
- // "transfer_method": "onchain",
5146
- // "status": "finish",
5147
- // "status_display": "finish",
5148
- // "remark": "",
5149
- // "explorer": "https://bscscan.com/tx/0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56"
5150
- // }
5151
- // ],
5152
- // "total": 1,
5153
- // "total_page": 1
5154
- // },
5155
- // "message": "Success"
5156
- // }
5105
+ // {
5106
+ // "data": [
5107
+ // {
5108
+ // "deposit_id": 5173806,
5109
+ // "created_at": 1714021652557,
5110
+ // "tx_id": "d9f47d2550397c635cb89a8963118f8fe78ef048bc8b6f0caaeaa7dc6",
5111
+ // "tx_id_display": "",
5112
+ // "ccy": "USDT",
5113
+ // "chain": "TRC20",
5114
+ // "deposit_method": "ON_CHAIN",
5115
+ // "amount": "30",
5116
+ // "actual_amount": "",
5117
+ // "to_address": "TYewD2pVWDUwfNr9A",
5118
+ // "confirmations": 20,
5119
+ // "status": "FINISHED",
5120
+ // "tx_explorer_url": "https://tronscan.org/#/transaction",
5121
+ // "to_addr_explorer_url": "https://tronscan.org/#/address",
5122
+ // "remark": ""
5123
+ // },
5124
+ // ],
5125
+ // "paginatation": {
5126
+ // "total": 8,
5127
+ // "has_next": true
5128
+ // },
5129
+ // "code": 0,
5130
+ // "message": "OK"
5131
+ // }
5157
5132
  //
5158
- let data = this.safeValue(response, 'data');
5159
- if (!Array.isArray(data)) {
5160
- data = this.safeValue(data, 'data', []);
5161
- }
5133
+ const data = this.safeList(response, 'data', []);
5162
5134
  return this.parseTransactions(data, currency, since, limit);
5163
5135
  }
5164
5136
  parseIsolatedBorrowRate(info, market = undefined) {
5165
5137
  //
5166
5138
  // {
5167
5139
  // "market": "BTCUSDT",
5140
+ // "ccy": "USDT",
5168
5141
  // "leverage": 10,
5169
- // "BTC": {
5170
- // "min_amount": "0.002",
5171
- // "max_amount": "200",
5172
- // "day_rate": "0.001"
5173
- // },
5174
- // "USDT": {
5175
- // "min_amount": "60",
5176
- // "max_amount": "5000000",
5177
- // "day_rate": "0.001"
5178
- // }
5179
- // },
5142
+ // "min_amount": "60",
5143
+ // "max_amount": "500000",
5144
+ // "daily_interest_rate": "0.001"
5145
+ // }
5180
5146
  //
5181
5147
  const marketId = this.safeString(info, 'market');
5182
5148
  market = this.safeMarket(marketId, market, undefined, 'spot');
5183
- const baseInfo = this.safeValue(info, market['baseId']);
5184
- const quoteInfo = this.safeValue(info, market['quoteId']);
5149
+ const currency = this.safeString(info, 'ccy');
5150
+ const rate = this.safeNumber(info, 'daily_interest_rate');
5151
+ let baseRate = undefined;
5152
+ let quoteRate = undefined;
5153
+ if (currency === market['baseId']) {
5154
+ baseRate = rate;
5155
+ }
5156
+ else if (currency === market['quoteId']) {
5157
+ quoteRate = rate;
5158
+ }
5185
5159
  return {
5186
5160
  'symbol': market['symbol'],
5187
5161
  'base': market['base'],
5188
- 'baseRate': this.safeNumber(baseInfo, 'day_rate'),
5162
+ 'baseRate': baseRate,
5189
5163
  'quote': market['quote'],
5190
- 'quoteRate': this.safeNumber(quoteInfo, 'day_rate'),
5164
+ 'quoteRate': quoteRate,
5191
5165
  'period': 86400000,
5192
5166
  'timestamp': undefined,
5193
5167
  'datetime': undefined,
@@ -5199,78 +5173,56 @@ class coinex extends coinex$1 {
5199
5173
  * @method
5200
5174
  * @name coinex#fetchIsolatedBorrowRate
5201
5175
  * @description fetch the rate of interest to borrow a currency for margin trading
5202
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account007_margin_account_settings
5176
+ * @see https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-interest-limit
5203
5177
  * @param {string} symbol unified symbol of the market to fetch the borrow rate for
5204
5178
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5179
+ * @param {string} params.code unified currency code
5205
5180
  * @returns {object} an [isolated borrow rate structure]{@link https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure}
5206
5181
  */
5207
5182
  await this.loadMarkets();
5183
+ const code = this.safeString(params, 'code');
5184
+ if (code === undefined) {
5185
+ throw new errors.ArgumentsRequired(this.id + ' fetchIsolatedBorrowRate() requires a code parameter');
5186
+ }
5187
+ params = this.omit(params, 'code');
5188
+ const currency = this.currency(code);
5208
5189
  const market = this.market(symbol);
5209
5190
  const request = {
5210
5191
  'market': market['id'],
5192
+ 'ccy': currency['id'],
5211
5193
  };
5212
- const response = await this.v1PrivateGetMarginConfig(this.extend(request, params));
5194
+ const response = await this.v2PrivateGetAssetsMarginInterestLimit(this.extend(request, params));
5213
5195
  //
5214
5196
  // {
5215
5197
  // "code": 0,
5216
5198
  // "data": {
5217
5199
  // "market": "BTCUSDT",
5200
+ // "ccy": "USDT",
5218
5201
  // "leverage": 10,
5219
- // "BTC": {
5220
- // "min_amount": "0.002",
5221
- // "max_amount": "200",
5222
- // "day_rate": "0.001"
5223
- // },
5224
- // "USDT": {
5225
- // "min_amount": "60",
5226
- // "max_amount": "5000000",
5227
- // "day_rate": "0.001"
5228
- // }
5202
+ // "min_amount": "60",
5203
+ // "max_amount": "500000",
5204
+ // "daily_interest_rate": "0.001"
5229
5205
  // },
5230
- // "message": "Success"
5206
+ // "message": "OK"
5231
5207
  // }
5232
5208
  //
5233
- const data = this.safeValue(response, 'data', {});
5209
+ const data = this.safeDict(response, 'data', {});
5234
5210
  return this.parseIsolatedBorrowRate(data, market);
5235
5211
  }
5236
- async fetchIsolatedBorrowRates(params = {}) {
5212
+ async fetchBorrowInterest(code = undefined, symbol = undefined, since = undefined, limit = undefined, params = {}) {
5237
5213
  /**
5238
5214
  * @method
5239
- * @name coinex#fetchIsolatedBorrowRates
5240
- * @description fetch the borrow interest rates of all currencies
5241
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account007_margin_account_settings
5215
+ * @name coinex#fetchBorrowInterest
5216
+ * @description fetch the interest owed by the user for borrowing currency for margin trading
5217
+ * @see https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-borrow-history
5218
+ * @param {string} [code] unified currency code
5219
+ * @param {string} [symbol] unified market symbol when fetch interest in isolated markets
5220
+ * @param {int} [since] the earliest time in ms to fetch borrrow interest for
5221
+ * @param {int} [limit] the maximum number of structures to retrieve
5242
5222
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5243
- * @returns {object} a list of [isolated borrow rate structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#isolated-borrow-rate-structure}
5223
+ * @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/#/?id=borrow-interest-structure}
5244
5224
  */
5245
5225
  await this.loadMarkets();
5246
- const response = await this.v1PrivateGetMarginConfig(params);
5247
- //
5248
- // {
5249
- // "code": 0,
5250
- // "data": [
5251
- // {
5252
- // "market": "BTCUSDT",
5253
- // "leverage": 10,
5254
- // "BTC": {
5255
- // "min_amount": "0.002",
5256
- // "max_amount": "200",
5257
- // "day_rate": "0.001"
5258
- // },
5259
- // "USDT": {
5260
- // "min_amount": "60",
5261
- // "max_amount": "5000000",
5262
- // "day_rate": "0.001"
5263
- // }
5264
- // },
5265
- // ],
5266
- // "message": "Success"
5267
- // }
5268
- //
5269
- const data = this.safeValue(response, 'data', []);
5270
- return this.parseIsolatedBorrowRates(data);
5271
- }
5272
- async fetchBorrowInterest(code = undefined, symbol = undefined, since = undefined, limit = undefined, params = {}) {
5273
- await this.loadMarkets();
5274
5226
  const request = {};
5275
5227
  let market = undefined;
5276
5228
  if (symbol !== undefined) {
@@ -5280,77 +5232,62 @@ class coinex extends coinex$1 {
5280
5232
  if (limit !== undefined) {
5281
5233
  request['limit'] = limit;
5282
5234
  }
5283
- const response = await this.v1PrivateGetMarginLoanHistory(this.extend(request, params));
5235
+ const response = await this.v2PrivateGetAssetsMarginBorrowHistory(this.extend(request, params));
5284
5236
  //
5285
5237
  // {
5286
- // "code": 0,
5287
- // "data": {
5288
- // "page": 1,
5289
- // "limit": 10,
5290
- // "total": 1,
5291
- // "has_next": false,
5292
- // "curr_page": 1,
5293
- // "count": 1,
5294
- // "data": [
5295
- // {
5296
- // "loan_id": 2616357,
5297
- // "create_time": 1654214027,
5298
- // "market_type": "BTCUSDT",
5299
- // "coin_type": "BTC",
5300
- // "day_rate": "0.001",
5301
- // "loan_amount": "0.0144",
5302
- // "interest_amount": "0",
5303
- // "unflat_amount": "0",
5304
- // "expire_time": 1655078027,
5305
- // "is_renew": true,
5306
- // "status": "finish"
5307
- // }
5308
- // ],
5309
- // "total_page": 1
5238
+ // "data": [
5239
+ // {
5240
+ // "borrow_id": 2642934,
5241
+ // "created_at": 1654761016000,
5242
+ // "market": "BTCUSDT",
5243
+ // "ccy": "USDT",
5244
+ // "daily_interest_rate": "0.001",
5245
+ // "expired_at": 1655625016000,
5246
+ // "borrow_amount": "100",
5247
+ // "to_repaied_amount": "0",
5248
+ // "is_auto_renew": false,
5249
+ // "status": "finish"
5250
+ // },
5251
+ // ],
5252
+ // "pagination": {
5253
+ // "total": 4,
5254
+ // "has_next": true
5310
5255
  // },
5311
- // "message": "Success"
5256
+ // "code": 0,
5257
+ // "message": "OK"
5312
5258
  // }
5313
5259
  //
5314
- const data = this.safeValue(response, 'data', {});
5315
- const rows = this.safeValue(data, 'data', []);
5260
+ const rows = this.safeValue(response, 'data', []);
5316
5261
  const interest = this.parseBorrowInterests(rows, market);
5317
5262
  return this.filterByCurrencySinceLimit(interest, code, since, limit);
5318
5263
  }
5319
5264
  parseBorrowInterest(info, market = undefined) {
5320
5265
  //
5321
5266
  // {
5322
- // "loan_id": 2616357,
5323
- // "create_time": 1654214027,
5324
- // "market_type": "BTCUSDT",
5325
- // "coin_type": "BTC",
5326
- // "day_rate": "0.001",
5327
- // "loan_amount": "0.0144",
5328
- // "interest_amount": "0",
5329
- // "unflat_amount": "0",
5330
- // "expire_time": 1655078027,
5331
- // "is_renew": true,
5267
+ // "borrow_id": 2642934,
5268
+ // "created_at": 1654761016000,
5269
+ // "market": "BTCUSDT",
5270
+ // "ccy": "USDT",
5271
+ // "daily_interest_rate": "0.001",
5272
+ // "expired_at": 1655625016000,
5273
+ // "borrow_amount": "100",
5274
+ // "to_repaied_amount": "0",
5275
+ // "is_auto_renew": false,
5332
5276
  // "status": "finish"
5333
5277
  // }
5334
5278
  //
5335
- const marketId = this.safeString(info, 'market_type');
5279
+ const marketId = this.safeString(info, 'market');
5336
5280
  market = this.safeMarket(marketId, market, undefined, 'spot');
5337
- const symbol = this.safeString(market, 'symbol');
5338
- const timestamp = this.safeTimestamp(info, 'expire_time');
5339
- const unflatAmount = this.safeString(info, 'unflat_amount');
5340
- const loanAmount = this.safeString(info, 'loan_amount');
5341
- let interest = Precise["default"].stringSub(unflatAmount, loanAmount);
5342
- if (unflatAmount === '0') {
5343
- interest = undefined;
5344
- }
5281
+ const timestamp = this.safeInteger(info, 'expired_at');
5345
5282
  return {
5346
5283
  'account': undefined,
5347
- 'symbol': symbol,
5284
+ 'symbol': market['symbol'],
5348
5285
  'marginMode': 'isolated',
5349
5286
  'marginType': undefined,
5350
- 'currency': this.safeCurrencyCode(this.safeString(info, 'coin_type')),
5351
- 'interest': this.parseNumber(interest),
5352
- 'interestRate': this.safeNumber(info, 'day_rate'),
5353
- 'amountBorrowed': this.parseNumber(loanAmount),
5287
+ 'currency': this.safeCurrencyCode(this.safeString(info, 'ccy')),
5288
+ 'interest': this.safeNumber(info, 'to_repaied_amount'),
5289
+ 'interestRate': this.safeNumber(info, 'daily_interest_rate'),
5290
+ 'amountBorrowed': this.safeNumber(info, 'borrow_amount'),
5354
5291
  'timestamp': timestamp,
5355
5292
  'datetime': this.iso8601(timestamp),
5356
5293
  'info': info,
@@ -5361,32 +5298,43 @@ class coinex extends coinex$1 {
5361
5298
  * @method
5362
5299
  * @name coinex#borrowIsolatedMargin
5363
5300
  * @description create a loan to borrow margin
5364
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account017_margin_loan
5301
+ * @see https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-borrow
5365
5302
  * @param {string} symbol unified market symbol, required for coinex
5366
5303
  * @param {string} code unified currency code of the currency to borrow
5367
5304
  * @param {float} amount the amount to borrow
5368
5305
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5306
+ * @param {boolean} [params.isAutoRenew] whether to renew the margin loan automatically or not, default is false
5369
5307
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5370
5308
  */
5371
5309
  await this.loadMarkets();
5372
5310
  const market = this.market(symbol);
5373
5311
  const currency = this.currency(code);
5312
+ const isAutoRenew = this.safeBool2(params, 'isAutoRenew', 'is_auto_renew', false);
5313
+ params = this.omit(params, 'isAutoRenew');
5374
5314
  const request = {
5375
5315
  'market': market['id'],
5376
- 'coin_type': currency['id'],
5377
- 'amount': this.currencyToPrecision(code, amount),
5316
+ 'ccy': currency['id'],
5317
+ 'borrow_amount': this.currencyToPrecision(code, amount),
5318
+ 'is_auto_renew': isAutoRenew,
5378
5319
  };
5379
- const response = await this.v1PrivatePostMarginLoan(this.extend(request, params));
5320
+ const response = await this.v2PrivatePostAssetsMarginBorrow(this.extend(request, params));
5380
5321
  //
5381
5322
  // {
5382
5323
  // "code": 0,
5383
5324
  // "data": {
5384
- // "loan_id": 1670
5325
+ // "borrow_id": 13784021,
5326
+ // "market": "BTCUSDT",
5327
+ // "ccy": "USDT",
5328
+ // "daily_interest_rate": "0.001",
5329
+ // "expired_at": 1717299948340,
5330
+ // "borrow_amount": "60",
5331
+ // "to_repaied_amount": "60.0025",
5332
+ // "status": "loan"
5385
5333
  // },
5386
- // "message": "Success"
5334
+ // "message": "OK"
5387
5335
  // }
5388
5336
  //
5389
- const data = this.safeValue(response, 'data', {});
5337
+ const data = this.safeDict(response, 'data', {});
5390
5338
  const transaction = this.parseMarginLoan(data, currency);
5391
5339
  return this.extend(transaction, {
5392
5340
  'amount': amount,
@@ -5398,12 +5346,12 @@ class coinex extends coinex$1 {
5398
5346
  * @method
5399
5347
  * @name coinex#repayIsolatedMargin
5400
5348
  * @description repay borrowed margin and interest
5401
- * @see https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account018_margin_flat
5349
+ * @see https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-repay
5402
5350
  * @param {string} symbol unified market symbol, required for coinex
5403
5351
  * @param {string} code unified currency code of the currency to repay
5404
5352
  * @param {float} amount the amount to repay
5405
5353
  * @param {object} [params] extra parameters specific to the exchange API endpoint
5406
- * @param {string} [params.loan_id] extra parameter that is not required
5354
+ * @param {string} [params.borrow_id] extra parameter that is not required
5407
5355
  * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
5408
5356
  */
5409
5357
  await this.loadMarkets();
@@ -5411,46 +5359,47 @@ class coinex extends coinex$1 {
5411
5359
  const currency = this.currency(code);
5412
5360
  const request = {
5413
5361
  'market': market['id'],
5414
- 'coin_type': currency['id'],
5362
+ 'ccy': currency['id'],
5415
5363
  'amount': this.currencyToPrecision(code, amount),
5416
5364
  };
5417
- const response = await this.v1PrivatePostMarginFlat(this.extend(request, params));
5365
+ const response = await this.v2PrivatePostAssetsMarginRepay(this.extend(request, params));
5418
5366
  //
5419
5367
  // {
5420
5368
  // "code": 0,
5421
- // "data": null,
5422
- // "message": "Success"
5369
+ // "data": {},
5370
+ // "message": "OK"
5423
5371
  // }
5424
5372
  //
5425
- const transaction = this.parseMarginLoan(response, currency);
5373
+ const data = this.safeDict(response, 'data', {});
5374
+ const transaction = this.parseMarginLoan(data, currency);
5426
5375
  return this.extend(transaction, {
5427
5376
  'amount': amount,
5428
5377
  'symbol': symbol,
5429
5378
  });
5430
5379
  }
5431
5380
  parseMarginLoan(info, currency = undefined) {
5432
- //
5433
- // borrowMargin
5434
5381
  //
5435
5382
  // {
5436
- // "loan_id": 1670
5437
- // }
5438
- //
5439
- // repayMargin
5440
- //
5441
- // {
5442
- // "code": 0,
5443
- // "data": null,
5444
- // "message": "Success"
5383
+ // "borrow_id": 13784021,
5384
+ // "market": "BTCUSDT",
5385
+ // "ccy": "USDT",
5386
+ // "daily_interest_rate": "0.001",
5387
+ // "expired_at": 1717299948340,
5388
+ // "borrow_amount": "60",
5389
+ // "to_repaied_amount": "60.0025",
5390
+ // "status": "loan"
5445
5391
  // }
5446
5392
  //
5393
+ const currencyId = this.safeString(info, 'ccy');
5394
+ const marketId = this.safeString(info, 'market');
5395
+ const timestamp = this.safeInteger(info, 'expired_at');
5447
5396
  return {
5448
- 'id': this.safeInteger(info, 'loan_id'),
5449
- 'currency': this.safeCurrencyCode(undefined, currency),
5450
- 'amount': undefined,
5451
- 'symbol': undefined,
5452
- 'timestamp': undefined,
5453
- 'datetime': undefined,
5397
+ 'id': this.safeInteger(info, 'borrow_id'),
5398
+ 'currency': this.safeCurrencyCode(currencyId, currency),
5399
+ 'amount': this.safeString(info, 'borrow_amount'),
5400
+ 'symbol': this.safeSymbol(marketId, undefined, undefined, 'spot'),
5401
+ 'timestamp': timestamp,
5402
+ 'datetime': this.iso8601(timestamp),
5454
5403
  'info': info,
5455
5404
  };
5456
5405
  }