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