ccxt 4.3.28__py2.py3-none-any.whl → 4.3.30__py2.py3-none-any.whl

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.

Potentially problematic release.


This version of ccxt might be problematic. Click here for more details.

ccxt/coinex.py CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.coinex import ImplicitAPI
8
- from ccxt.base.types import Balances, Currencies, Currency, Int, IsolatedBorrowRate, IsolatedBorrowRates, Leverage, Leverages, MarginModification, Market, Num, Order, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry, TransferEntries
8
+ from ccxt.base.types import Balances, Currencies, Currency, Int, IsolatedBorrowRate, Leverage, Leverages, MarginModification, Market, Num, Order, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry, TransferEntries
9
9
  from typing import List
10
10
  from ccxt.base.errors import ExchangeError
11
11
  from ccxt.base.errors import AuthenticationError
@@ -89,7 +89,7 @@ class coinex(Exchange, ImplicitAPI):
89
89
  'fetchFundingRates': True,
90
90
  'fetchIndexOHLCV': False,
91
91
  'fetchIsolatedBorrowRate': True,
92
- 'fetchIsolatedBorrowRates': True,
92
+ 'fetchIsolatedBorrowRates': False,
93
93
  'fetchLeverage': 'emulated',
94
94
  'fetchLeverages': True,
95
95
  'fetchLeverageTiers': True,
@@ -4501,107 +4501,98 @@ class coinex(Exchange, ImplicitAPI):
4501
4501
  #
4502
4502
  # fetchDeposits
4503
4503
  #
4504
- # {
4505
- # "coin_deposit_id": 32555985,
4506
- # "create_time": 1673325495,
4507
- # "amount": "12.71",
4508
- # "amount_display": "12.71",
4509
- # "diff_amount": "0",
4510
- # "min_amount": "0",
4511
- # "actual_amount": "12.71",
4512
- # "actual_amount_display": "12.71",
4513
- # "confirmations": 35,
4514
- # "tx_id": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
4515
- # "tx_id_display": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
4516
- # "coin_address": "0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
4517
- # "coin_address_display": "0xe7a3****f4b738",
4518
- # "add_explorer": "https://bscscan.com/address/0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
4519
- # "coin_type": "USDT",
4520
- # "smart_contract_name": "BSC",
4521
- # "transfer_method": "onchain",
4522
- # "status": "finish",
4523
- # "status_display": "finish",
4524
- # "remark": "",
4525
- # "explorer": "https://bscscan.com/tx/0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56"
4526
- # }
4504
+ # {
4505
+ # "deposit_id": 5173806,
4506
+ # "created_at": 1714021652557,
4507
+ # "tx_id": "d9f47d2550397c635cb89a8963118f8fe78ef048bc8b6f0caaeaa7dc6",
4508
+ # "tx_id_display": "",
4509
+ # "ccy": "USDT",
4510
+ # "chain": "TRC20",
4511
+ # "deposit_method": "ON_CHAIN",
4512
+ # "amount": "30",
4513
+ # "actual_amount": "",
4514
+ # "to_address": "TYewD2pVWDUwfNr9A",
4515
+ # "confirmations": 20,
4516
+ # "status": "FINISHED",
4517
+ # "tx_explorer_url": "https://tronscan.org/#/transaction",
4518
+ # "to_addr_explorer_url": "https://tronscan.org/#/address",
4519
+ # "remark": ""
4520
+ # }
4527
4521
  #
4528
4522
  # fetchWithdrawals
4529
4523
  #
4530
- # {
4531
- # "coin_withdraw_id": 20076836,
4532
- # "create_time": 1673325776,
4533
- # "actual_amount": "0.029",
4534
- # "actual_amount_display": "0.029",
4535
- # "amount": "0.03",
4536
- # "amount_display": "0.03",
4537
- # "coin_address": "MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
4538
- # "app_coin_address_display": "MBh****pAb",
4539
- # "coin_address_display": "MBhJcc****UdJpAb",
4540
- # "add_explorer": "https://explorer.viawallet.com/ltc/address/MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
4541
- # "coin_type": "LTC",
4542
- # "confirmations": 7,
4543
- # "explorer": "https://explorer.viawallet.com/ltc/tx/a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9",
4544
- # "fee": "0",
4545
- # "remark": "",
4546
- # "smart_contract_name": "",
4547
- # "status": "finish",
4548
- # "status_display": "finish",
4549
- # "transfer_method": "onchain",
4550
- # "tx_fee": "0.001",
4551
- # "tx_id": "a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9"
4552
- # }
4524
+ # {
4525
+ # "withdraw_id": 259364,
4526
+ # "created_at": 1701323541548,
4527
+ # "withdraw_method": "ON_CHAIN",
4528
+ # "ccy": "USDT",
4529
+ # "amount": "23.845744",
4530
+ # "actual_amount": "22.445744",
4531
+ # "chain": "TRC20",
4532
+ # "tx_fee": "1.4",
4533
+ # "fee_asset": "USDT",
4534
+ # "fee_amount": "1.4",
4535
+ # "to_address": "T8t5i2454dhdhnnnGdi49vMbihvY",
4536
+ # "memo": "",
4537
+ # "tx_id": "1237623941964de9954ed2e36640228d78765c1026",
4538
+ # "confirmations": 18,
4539
+ # "explorer_address_url": "https://tronscan.org/#/address",
4540
+ # "explorer_tx_url": "https://tronscan.org/#/transaction",
4541
+ # "remark": "",
4542
+ # "status": "finished"
4543
+ # }
4553
4544
  #
4554
- id = self.safe_string_2(transaction, 'coin_withdraw_id', 'coin_deposit_id')
4555
- address = self.safe_string(transaction, 'coin_address')
4556
- tag = self.safe_string(transaction, 'remark') # set but unused
4545
+ address = self.safe_string(transaction, 'to_address')
4546
+ tag = self.safe_string(transaction, 'memo')
4557
4547
  if tag is not None:
4558
4548
  if len(tag) < 1:
4559
4549
  tag = None
4560
- txid = self.safe_value(transaction, 'tx_id')
4550
+ remark = self.safe_string(transaction, 'remark')
4551
+ if remark is not None:
4552
+ if len(remark) < 1:
4553
+ remark = None
4554
+ txid = self.safe_string(transaction, 'tx_id')
4561
4555
  if txid is not None:
4562
4556
  if len(txid) < 1:
4563
4557
  txid = None
4564
- currencyId = self.safe_string(transaction, 'coin_type')
4558
+ currencyId = self.safe_string(transaction, 'ccy')
4565
4559
  code = self.safe_currency_code(currencyId, currency)
4566
- timestamp = self.safe_timestamp(transaction, 'create_time')
4567
- type = 'withdrawal' if ('coin_withdraw_id' in transaction) else 'deposit'
4568
- status = self.parse_transaction_status(self.safe_string(transaction, 'status'))
4569
- networkId = self.safe_string(transaction, 'smart_contract_name')
4570
- amount = self.safe_number(transaction, 'actual_amount')
4560
+ timestamp = self.safe_integer(transaction, 'created_at')
4561
+ type = 'withdrawal' if ('withdraw_id' in transaction) else 'deposit'
4562
+ networkId = self.safe_string(transaction, 'chain')
4571
4563
  feeCost = self.safe_string(transaction, 'tx_fee')
4572
- transferMethod = self.safe_string(transaction, 'transfer_method')
4564
+ transferMethod = self.safe_string_lower_2(transaction, 'withdraw_method', 'deposit_method')
4573
4565
  internal = transferMethod == 'local'
4574
- addressTo = None
4575
- addressFrom = None
4566
+ amount = self.safe_number(transaction, 'actual_amount')
4567
+ if amount is None:
4568
+ amount = self.safe_number(transaction, 'amount')
4576
4569
  if type == 'deposit':
4577
4570
  feeCost = '0'
4578
- addressTo = address
4579
- else:
4580
- addressFrom = address
4571
+ feeCurrencyId = self.safe_string(transaction, 'fee_asset')
4581
4572
  fee = {
4582
4573
  'cost': self.parse_number(feeCost),
4583
- 'currency': code,
4574
+ 'currency': self.safe_currency_code(feeCurrencyId),
4584
4575
  }
4585
4576
  return {
4586
4577
  'info': transaction,
4587
- 'id': id,
4578
+ 'id': self.safe_string_2(transaction, 'withdraw_id', 'deposit_id'),
4588
4579
  'txid': txid,
4589
4580
  'timestamp': timestamp,
4590
4581
  'datetime': self.iso8601(timestamp),
4591
4582
  'network': self.network_id_to_code(networkId),
4592
4583
  'address': address,
4593
- 'addressTo': None,
4584
+ 'addressTo': address,
4594
4585
  'addressFrom': None,
4595
4586
  'tag': tag,
4596
- 'tagTo': addressTo,
4597
- 'tagFrom': addressFrom,
4587
+ 'tagTo': None,
4588
+ 'tagFrom': None,
4598
4589
  'type': type,
4599
- 'amount': self.parse_number(amount),
4590
+ 'amount': amount,
4600
4591
  'currency': code,
4601
- 'status': status,
4592
+ 'status': self.parse_transaction_status(self.safe_string(transaction, 'status')),
4602
4593
  'updated': None,
4603
4594
  'fee': fee,
4604
- 'comment': None,
4595
+ 'comment': remark,
4605
4596
  'internal': internal,
4606
4597
  }
4607
4598
 
@@ -4734,154 +4725,135 @@ class coinex(Exchange, ImplicitAPI):
4734
4725
  def fetch_withdrawals(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
4735
4726
  """
4736
4727
  fetch all withdrawals made from an account
4737
- :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account026_withdraw_list
4738
- :param str code: unified currency code
4728
+ :see: https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-withdrawal-history
4729
+ :param str [code]: unified currency code
4739
4730
  :param int [since]: the earliest time in ms to fetch withdrawals for
4740
- :param int [limit]: the maximum number of withdrawals structures to retrieve
4731
+ :param int [limit]: the maximum number of withdrawal structures to retrieve
4741
4732
  :param dict [params]: extra parameters specific to the exchange API endpoint
4742
4733
  :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
4743
4734
  """
4735
+ self.load_markets()
4744
4736
  request = {}
4745
4737
  currency = None
4746
4738
  if code is not None:
4747
- self.load_markets()
4748
4739
  currency = self.currency(code)
4749
- request['coin_type'] = currency['id']
4740
+ request['ccy'] = currency['id']
4750
4741
  if limit is not None:
4751
- request['Limit'] = limit
4752
- response = self.v1PrivateGetBalanceCoinWithdraw(self.extend(request, params))
4742
+ request['limit'] = limit
4743
+ response = self.v2PrivateGetAssetsWithdraw(self.extend(request, params))
4753
4744
  #
4754
- # {
4755
- # "code": 0,
4756
- # "data": {
4757
- # "has_next": False,
4758
- # "curr_page": 1,
4759
- # "count": 1,
4760
- # "data": [
4761
- # {
4762
- # "coin_withdraw_id": 20076836,
4763
- # "create_time": 1673325776,
4764
- # "actual_amount": "0.029",
4765
- # "actual_amount_display": "0.029",
4766
- # "amount": "0.03",
4767
- # "amount_display": "0.03",
4768
- # "coin_address": "MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
4769
- # "app_coin_address_display": "MBh****pAb",
4770
- # "coin_address_display": "MBhJcc****UdJpAb",
4771
- # "add_explorer": "https://explorer.viawallet.com/ltc/address/MBhJcc3r5b3insc7QxyvEPtf31NqUdJpAb",
4772
- # "coin_type": "LTC",
4773
- # "confirmations": 7,
4774
- # "explorer": "https://explorer.viawallet.com/ltc/tx/a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9",
4775
- # "fee": "0",
4776
- # "remark": "",
4777
- # "smart_contract_name": "",
4778
- # "status": "finish",
4779
- # "status_display": "finish",
4780
- # "transfer_method": "onchain",
4781
- # "tx_fee": "0.001",
4782
- # "tx_id": "a0aa082132619b8a499b87e7d5bc3c508e0227104f5202ae26b695bb4cb7fbf9"
4783
- # }
4784
- # ],
4785
- # "total": 1,
4786
- # "total_page": 1
4787
- # },
4788
- # "message": "Success"
4789
- # }
4745
+ # {
4746
+ # "data": [
4747
+ # {
4748
+ # "withdraw_id": 259364,
4749
+ # "created_at": 1701323541548,
4750
+ # "withdraw_method": "ON_CHAIN",
4751
+ # "ccy": "USDT",
4752
+ # "amount": "23.845744",
4753
+ # "actual_amount": "22.445744",
4754
+ # "chain": "TRC20",
4755
+ # "tx_fee": "1.4",
4756
+ # "fee_asset": "USDT",
4757
+ # "fee_amount": "1.4",
4758
+ # "to_address": "T8t5i2454dhdhnnnGdi49vMbihvY",
4759
+ # "memo": "",
4760
+ # "tx_id": "1237623941964de9954ed2e36640228d78765c1026",
4761
+ # "confirmations": 18,
4762
+ # "explorer_address_url": "https://tronscan.org/#/address",
4763
+ # "explorer_tx_url": "https://tronscan.org/#/transaction",
4764
+ # "remark": "",
4765
+ # "status": "finished"
4766
+ # },
4767
+ # ],
4768
+ # "pagination": {
4769
+ # "total": 9,
4770
+ # "has_next": True
4771
+ # },
4772
+ # "code": 0,
4773
+ # "message": "OK"
4774
+ # }
4790
4775
  #
4791
- data = self.safe_value(response, 'data')
4792
- if not isinstance(data, list):
4793
- data = self.safe_value(data, 'data', [])
4776
+ data = self.safe_list(response, 'data', [])
4794
4777
  return self.parse_transactions(data, currency, since, limit)
4795
4778
 
4796
4779
  def fetch_deposits(self, code: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Transaction]:
4797
4780
  """
4798
4781
  fetch all deposits made to an account
4799
- :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account009_deposit_list
4800
- :param str code: unified currency code
4782
+ :see: https://docs.coinex.com/api/v2/assets/deposit-withdrawal/http/list-deposit-history
4783
+ :param str [code]: unified currency code
4801
4784
  :param int [since]: the earliest time in ms to fetch deposits for
4802
- :param int [limit]: the maximum number of deposits structures to retrieve
4785
+ :param int [limit]: the maximum number of deposit structures to retrieve
4803
4786
  :param dict [params]: extra parameters specific to the exchange API endpoint
4804
4787
  :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
4805
4788
  """
4789
+ self.load_markets()
4806
4790
  request = {}
4807
4791
  currency = None
4808
4792
  if code is not None:
4809
- self.load_markets()
4810
4793
  currency = self.currency(code)
4811
- request['coin_type'] = currency['id']
4794
+ request['ccy'] = currency['id']
4812
4795
  if limit is not None:
4813
- request['Limit'] = limit
4814
- response = self.v1PrivateGetBalanceCoinDeposit(self.extend(request, params))
4796
+ request['limit'] = limit
4797
+ response = self.v2PrivateGetAssetsDepositHistory(self.extend(request, params))
4815
4798
  #
4816
- # {
4817
- # "code": 0,
4818
- # "data": {
4819
- # "has_next": False,
4820
- # "curr_page": 1,
4821
- # "count": 1,
4822
- # "data": [
4823
- # {
4824
- # "coin_deposit_id": 32555985,
4825
- # "create_time": 1673325495,
4826
- # "amount": "12.71",
4827
- # "amount_display": "12.71",
4828
- # "diff_amount": "0",
4829
- # "min_amount": "0",
4830
- # "actual_amount": "12.71",
4831
- # "actual_amount_display": "12.71",
4832
- # "confirmations": 35,
4833
- # "tx_id": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
4834
- # "tx_id_display": "0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56",
4835
- # "coin_address": "0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
4836
- # "coin_address_display": "0xe7a3****f4b738",
4837
- # "add_explorer": "https://bscscan.com/address/0xe7a3831c56836f466b6a6268cff4fc852cf4b738",
4838
- # "coin_type": "USDT",
4839
- # "smart_contract_name": "BSC",
4840
- # "transfer_method": "onchain",
4841
- # "status": "finish",
4842
- # "status_display": "finish",
4843
- # "remark": "",
4844
- # "explorer": "https://bscscan.com/tx/0x57f1c92cc10b48316e2bf5faf230694fec2174e7744c1562a9a88b9c1e585f56"
4845
- # }
4846
- # ],
4847
- # "total": 1,
4848
- # "total_page": 1
4849
- # },
4850
- # "message": "Success"
4851
- # }
4799
+ # {
4800
+ # "data": [
4801
+ # {
4802
+ # "deposit_id": 5173806,
4803
+ # "created_at": 1714021652557,
4804
+ # "tx_id": "d9f47d2550397c635cb89a8963118f8fe78ef048bc8b6f0caaeaa7dc6",
4805
+ # "tx_id_display": "",
4806
+ # "ccy": "USDT",
4807
+ # "chain": "TRC20",
4808
+ # "deposit_method": "ON_CHAIN",
4809
+ # "amount": "30",
4810
+ # "actual_amount": "",
4811
+ # "to_address": "TYewD2pVWDUwfNr9A",
4812
+ # "confirmations": 20,
4813
+ # "status": "FINISHED",
4814
+ # "tx_explorer_url": "https://tronscan.org/#/transaction",
4815
+ # "to_addr_explorer_url": "https://tronscan.org/#/address",
4816
+ # "remark": ""
4817
+ # },
4818
+ # ],
4819
+ # "paginatation": {
4820
+ # "total": 8,
4821
+ # "has_next": True
4822
+ # },
4823
+ # "code": 0,
4824
+ # "message": "OK"
4825
+ # }
4852
4826
  #
4853
- data = self.safe_value(response, 'data')
4854
- if not isinstance(data, list):
4855
- data = self.safe_value(data, 'data', [])
4827
+ data = self.safe_list(response, 'data', [])
4856
4828
  return self.parse_transactions(data, currency, since, limit)
4857
4829
 
4858
4830
  def parse_isolated_borrow_rate(self, info, market: Market = None) -> IsolatedBorrowRate:
4859
4831
  #
4860
4832
  # {
4861
4833
  # "market": "BTCUSDT",
4834
+ # "ccy": "USDT",
4862
4835
  # "leverage": 10,
4863
- # "BTC": {
4864
- # "min_amount": "0.002",
4865
- # "max_amount": "200",
4866
- # "day_rate": "0.001"
4867
- # },
4868
- # "USDT": {
4869
- # "min_amount": "60",
4870
- # "max_amount": "5000000",
4871
- # "day_rate": "0.001"
4872
- # }
4873
- # },
4836
+ # "min_amount": "60",
4837
+ # "max_amount": "500000",
4838
+ # "daily_interest_rate": "0.001"
4839
+ # }
4874
4840
  #
4875
4841
  marketId = self.safe_string(info, 'market')
4876
4842
  market = self.safe_market(marketId, market, None, 'spot')
4877
- baseInfo = self.safe_value(info, market['baseId'])
4878
- quoteInfo = self.safe_value(info, market['quoteId'])
4843
+ currency = self.safe_string(info, 'ccy')
4844
+ rate = self.safe_number(info, 'daily_interest_rate')
4845
+ baseRate = None
4846
+ quoteRate = None
4847
+ if currency == market['baseId']:
4848
+ baseRate = rate
4849
+ elif currency == market['quoteId']:
4850
+ quoteRate = rate
4879
4851
  return {
4880
4852
  'symbol': market['symbol'],
4881
4853
  'base': market['base'],
4882
- 'baseRate': self.safe_number(baseInfo, 'day_rate'),
4854
+ 'baseRate': baseRate,
4883
4855
  'quote': market['quote'],
4884
- 'quoteRate': self.safe_number(quoteInfo, 'day_rate'),
4856
+ 'quoteRate': quoteRate,
4885
4857
  'period': 86400000,
4886
4858
  'timestamp': None,
4887
4859
  'datetime': None,
@@ -4891,75 +4863,52 @@ class coinex(Exchange, ImplicitAPI):
4891
4863
  def fetch_isolated_borrow_rate(self, symbol: str, params={}) -> IsolatedBorrowRate:
4892
4864
  """
4893
4865
  fetch the rate of interest to borrow a currency for margin trading
4894
- :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account007_margin_account_settings
4866
+ :see: https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-interest-limit
4895
4867
  :param str symbol: unified symbol of the market to fetch the borrow rate for
4896
4868
  :param dict [params]: extra parameters specific to the exchange API endpoint
4869
+ :param str params['code']: unified currency code
4897
4870
  :returns dict: an `isolated borrow rate structure <https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure>`
4898
4871
  """
4899
4872
  self.load_markets()
4873
+ code = self.safe_string(params, 'code')
4874
+ if code is None:
4875
+ raise ArgumentsRequired(self.id + ' fetchIsolatedBorrowRate() requires a code parameter')
4876
+ params = self.omit(params, 'code')
4877
+ currency = self.currency(code)
4900
4878
  market = self.market(symbol)
4901
4879
  request = {
4902
4880
  'market': market['id'],
4881
+ 'ccy': currency['id'],
4903
4882
  }
4904
- response = self.v1PrivateGetMarginConfig(self.extend(request, params))
4883
+ response = self.v2PrivateGetAssetsMarginInterestLimit(self.extend(request, params))
4905
4884
  #
4906
4885
  # {
4907
4886
  # "code": 0,
4908
4887
  # "data": {
4909
4888
  # "market": "BTCUSDT",
4889
+ # "ccy": "USDT",
4910
4890
  # "leverage": 10,
4911
- # "BTC": {
4912
- # "min_amount": "0.002",
4913
- # "max_amount": "200",
4914
- # "day_rate": "0.001"
4915
- # },
4916
- # "USDT": {
4917
- # "min_amount": "60",
4918
- # "max_amount": "5000000",
4919
- # "day_rate": "0.001"
4920
- # }
4891
+ # "min_amount": "60",
4892
+ # "max_amount": "500000",
4893
+ # "daily_interest_rate": "0.001"
4921
4894
  # },
4922
- # "message": "Success"
4895
+ # "message": "OK"
4923
4896
  # }
4924
4897
  #
4925
- data = self.safe_value(response, 'data', {})
4898
+ data = self.safe_dict(response, 'data', {})
4926
4899
  return self.parse_isolated_borrow_rate(data, market)
4927
4900
 
4928
- def fetch_isolated_borrow_rates(self, params={}) -> IsolatedBorrowRates:
4901
+ def fetch_borrow_interest(self, code: Str = None, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
4929
4902
  """
4930
- fetch the borrow interest rates of all currencies
4931
- :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account007_margin_account_settings
4903
+ fetch the interest owed by the user for borrowing currency for margin trading
4904
+ :see: https://docs.coinex.com/api/v2/assets/loan-flat/http/list-margin-borrow-history
4905
+ :param str [code]: unified currency code
4906
+ :param str [symbol]: unified market symbol when fetch interest in isolated markets
4907
+ :param int [since]: the earliest time in ms to fetch borrrow interest for
4908
+ :param int [limit]: the maximum number of structures to retrieve
4932
4909
  :param dict [params]: extra parameters specific to the exchange API endpoint
4933
- :returns dict: a list of `isolated borrow rate structures <https://github.com/ccxt/ccxt/wiki/Manual#isolated-borrow-rate-structure>`
4910
+ :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
4934
4911
  """
4935
- self.load_markets()
4936
- response = self.v1PrivateGetMarginConfig(params)
4937
- #
4938
- # {
4939
- # "code": 0,
4940
- # "data": [
4941
- # {
4942
- # "market": "BTCUSDT",
4943
- # "leverage": 10,
4944
- # "BTC": {
4945
- # "min_amount": "0.002",
4946
- # "max_amount": "200",
4947
- # "day_rate": "0.001"
4948
- # },
4949
- # "USDT": {
4950
- # "min_amount": "60",
4951
- # "max_amount": "5000000",
4952
- # "day_rate": "0.001"
4953
- # }
4954
- # },
4955
- # ],
4956
- # "message": "Success"
4957
- # }
4958
- #
4959
- data = self.safe_value(response, 'data', [])
4960
- return self.parse_isolated_borrow_rates(data)
4961
-
4962
- def fetch_borrow_interest(self, code: Str = None, symbol: Str = None, since: Int = None, limit: Int = None, params={}):
4963
4912
  self.load_markets()
4964
4913
  request = {}
4965
4914
  market = None
@@ -4968,76 +4917,62 @@ class coinex(Exchange, ImplicitAPI):
4968
4917
  request['market'] = market['id']
4969
4918
  if limit is not None:
4970
4919
  request['limit'] = limit
4971
- response = self.v1PrivateGetMarginLoanHistory(self.extend(request, params))
4920
+ response = self.v2PrivateGetAssetsMarginBorrowHistory(self.extend(request, params))
4972
4921
  #
4973
4922
  # {
4974
- # "code": 0,
4975
- # "data": {
4976
- # "page": 1,
4977
- # "limit": 10,
4978
- # "total": 1,
4979
- # "has_next": False,
4980
- # "curr_page": 1,
4981
- # "count": 1,
4982
- # "data": [
4983
- # {
4984
- # "loan_id": 2616357,
4985
- # "create_time": 1654214027,
4986
- # "market_type": "BTCUSDT",
4987
- # "coin_type": "BTC",
4988
- # "day_rate": "0.001",
4989
- # "loan_amount": "0.0144",
4990
- # "interest_amount": "0",
4991
- # "unflat_amount": "0",
4992
- # "expire_time": 1655078027,
4993
- # "is_renew": True,
4994
- # "status": "finish"
4995
- # }
4996
- # ],
4997
- # "total_page": 1
4923
+ # "data": [
4924
+ # {
4925
+ # "borrow_id": 2642934,
4926
+ # "created_at": 1654761016000,
4927
+ # "market": "BTCUSDT",
4928
+ # "ccy": "USDT",
4929
+ # "daily_interest_rate": "0.001",
4930
+ # "expired_at": 1655625016000,
4931
+ # "borrow_amount": "100",
4932
+ # "to_repaied_amount": "0",
4933
+ # "is_auto_renew": False,
4934
+ # "status": "finish"
4935
+ # },
4936
+ # ],
4937
+ # "pagination": {
4938
+ # "total": 4,
4939
+ # "has_next": True
4998
4940
  # },
4999
- # "message": "Success"
4941
+ # "code": 0,
4942
+ # "message": "OK"
5000
4943
  # }
5001
4944
  #
5002
- data = self.safe_value(response, 'data', {})
5003
- rows = self.safe_value(data, 'data', [])
4945
+ rows = self.safe_value(response, 'data', [])
5004
4946
  interest = self.parse_borrow_interests(rows, market)
5005
4947
  return self.filter_by_currency_since_limit(interest, code, since, limit)
5006
4948
 
5007
4949
  def parse_borrow_interest(self, info, market: Market = None):
5008
4950
  #
5009
4951
  # {
5010
- # "loan_id": 2616357,
5011
- # "create_time": 1654214027,
5012
- # "market_type": "BTCUSDT",
5013
- # "coin_type": "BTC",
5014
- # "day_rate": "0.001",
5015
- # "loan_amount": "0.0144",
5016
- # "interest_amount": "0",
5017
- # "unflat_amount": "0",
5018
- # "expire_time": 1655078027,
5019
- # "is_renew": True,
4952
+ # "borrow_id": 2642934,
4953
+ # "created_at": 1654761016000,
4954
+ # "market": "BTCUSDT",
4955
+ # "ccy": "USDT",
4956
+ # "daily_interest_rate": "0.001",
4957
+ # "expired_at": 1655625016000,
4958
+ # "borrow_amount": "100",
4959
+ # "to_repaied_amount": "0",
4960
+ # "is_auto_renew": False,
5020
4961
  # "status": "finish"
5021
4962
  # }
5022
4963
  #
5023
- marketId = self.safe_string(info, 'market_type')
4964
+ marketId = self.safe_string(info, 'market')
5024
4965
  market = self.safe_market(marketId, market, None, 'spot')
5025
- symbol = self.safe_string(market, 'symbol')
5026
- timestamp = self.safe_timestamp(info, 'expire_time')
5027
- unflatAmount = self.safe_string(info, 'unflat_amount')
5028
- loanAmount = self.safe_string(info, 'loan_amount')
5029
- interest = Precise.string_sub(unflatAmount, loanAmount)
5030
- if unflatAmount == '0':
5031
- interest = None
4966
+ timestamp = self.safe_integer(info, 'expired_at')
5032
4967
  return {
5033
4968
  'account': None, # deprecated
5034
- 'symbol': symbol,
4969
+ 'symbol': market['symbol'],
5035
4970
  'marginMode': 'isolated',
5036
4971
  'marginType': None, # deprecated
5037
- 'currency': self.safe_currency_code(self.safe_string(info, 'coin_type')),
5038
- 'interest': self.parse_number(interest),
5039
- 'interestRate': self.safe_number(info, 'day_rate'),
5040
- 'amountBorrowed': self.parse_number(loanAmount),
4972
+ 'currency': self.safe_currency_code(self.safe_string(info, 'ccy')),
4973
+ 'interest': self.safe_number(info, 'to_repaied_amount'),
4974
+ 'interestRate': self.safe_number(info, 'daily_interest_rate'),
4975
+ 'amountBorrowed': self.safe_number(info, 'borrow_amount'),
5041
4976
  'timestamp': timestamp, # expiry time
5042
4977
  'datetime': self.iso8601(timestamp),
5043
4978
  'info': info,
@@ -5046,32 +4981,43 @@ class coinex(Exchange, ImplicitAPI):
5046
4981
  def borrow_isolated_margin(self, symbol: str, code: str, amount: float, params={}):
5047
4982
  """
5048
4983
  create a loan to borrow margin
5049
- :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account017_margin_loan
4984
+ :see: https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-borrow
5050
4985
  :param str symbol: unified market symbol, required for coinex
5051
4986
  :param str code: unified currency code of the currency to borrow
5052
4987
  :param float amount: the amount to borrow
5053
4988
  :param dict [params]: extra parameters specific to the exchange API endpoint
4989
+ :param boolean [params.isAutoRenew]: whether to renew the margin loan automatically or not, default is False
5054
4990
  :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
5055
4991
  """
5056
4992
  self.load_markets()
5057
4993
  market = self.market(symbol)
5058
4994
  currency = self.currency(code)
4995
+ isAutoRenew = self.safe_bool_2(params, 'isAutoRenew', 'is_auto_renew', False)
4996
+ params = self.omit(params, 'isAutoRenew')
5059
4997
  request = {
5060
4998
  'market': market['id'],
5061
- 'coin_type': currency['id'],
5062
- 'amount': self.currency_to_precision(code, amount),
4999
+ 'ccy': currency['id'],
5000
+ 'borrow_amount': self.currency_to_precision(code, amount),
5001
+ 'is_auto_renew': isAutoRenew,
5063
5002
  }
5064
- response = self.v1PrivatePostMarginLoan(self.extend(request, params))
5003
+ response = self.v2PrivatePostAssetsMarginBorrow(self.extend(request, params))
5065
5004
  #
5066
5005
  # {
5067
5006
  # "code": 0,
5068
5007
  # "data": {
5069
- # "loan_id": 1670
5008
+ # "borrow_id": 13784021,
5009
+ # "market": "BTCUSDT",
5010
+ # "ccy": "USDT",
5011
+ # "daily_interest_rate": "0.001",
5012
+ # "expired_at": 1717299948340,
5013
+ # "borrow_amount": "60",
5014
+ # "to_repaied_amount": "60.0025",
5015
+ # "status": "loan"
5070
5016
  # },
5071
- # "message": "Success"
5017
+ # "message": "OK"
5072
5018
  # }
5073
5019
  #
5074
- data = self.safe_value(response, 'data', {})
5020
+ data = self.safe_dict(response, 'data', {})
5075
5021
  transaction = self.parse_margin_loan(data, currency)
5076
5022
  return self.extend(transaction, {
5077
5023
  'amount': amount,
@@ -5081,12 +5027,12 @@ class coinex(Exchange, ImplicitAPI):
5081
5027
  def repay_isolated_margin(self, symbol: str, code: str, amount, params={}):
5082
5028
  """
5083
5029
  repay borrowed margin and interest
5084
- :see: https://viabtc.github.io/coinex_api_en_doc/spot/#docsspot002_account018_margin_flat
5030
+ :see: https://docs.coinex.com/api/v2/assets/loan-flat/http/margin-repay
5085
5031
  :param str symbol: unified market symbol, required for coinex
5086
5032
  :param str code: unified currency code of the currency to repay
5087
5033
  :param float amount: the amount to repay
5088
5034
  :param dict [params]: extra parameters specific to the exchange API endpoint
5089
- :param str [params.loan_id]: extra parameter that is not required
5035
+ :param str [params.borrow_id]: extra parameter that is not required
5090
5036
  :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
5091
5037
  """
5092
5038
  self.load_markets()
@@ -5094,46 +5040,47 @@ class coinex(Exchange, ImplicitAPI):
5094
5040
  currency = self.currency(code)
5095
5041
  request = {
5096
5042
  'market': market['id'],
5097
- 'coin_type': currency['id'],
5043
+ 'ccy': currency['id'],
5098
5044
  'amount': self.currency_to_precision(code, amount),
5099
5045
  }
5100
- response = self.v1PrivatePostMarginFlat(self.extend(request, params))
5046
+ response = self.v2PrivatePostAssetsMarginRepay(self.extend(request, params))
5101
5047
  #
5102
5048
  # {
5103
5049
  # "code": 0,
5104
- # "data": null,
5105
- # "message": "Success"
5050
+ # "data": {},
5051
+ # "message": "OK"
5106
5052
  # }
5107
5053
  #
5108
- transaction = self.parse_margin_loan(response, currency)
5054
+ data = self.safe_dict(response, 'data', {})
5055
+ transaction = self.parse_margin_loan(data, currency)
5109
5056
  return self.extend(transaction, {
5110
5057
  'amount': amount,
5111
5058
  'symbol': symbol,
5112
5059
  })
5113
5060
 
5114
5061
  def parse_margin_loan(self, info, currency: Currency = None):
5115
- #
5116
- # borrowMargin
5117
5062
  #
5118
5063
  # {
5119
- # "loan_id": 1670
5120
- # }
5121
- #
5122
- # repayMargin
5123
- #
5124
- # {
5125
- # "code": 0,
5126
- # "data": null,
5127
- # "message": "Success"
5064
+ # "borrow_id": 13784021,
5065
+ # "market": "BTCUSDT",
5066
+ # "ccy": "USDT",
5067
+ # "daily_interest_rate": "0.001",
5068
+ # "expired_at": 1717299948340,
5069
+ # "borrow_amount": "60",
5070
+ # "to_repaied_amount": "60.0025",
5071
+ # "status": "loan"
5128
5072
  # }
5129
5073
  #
5074
+ currencyId = self.safe_string(info, 'ccy')
5075
+ marketId = self.safe_string(info, 'market')
5076
+ timestamp = self.safe_integer(info, 'expired_at')
5130
5077
  return {
5131
- 'id': self.safe_integer(info, 'loan_id'),
5132
- 'currency': self.safe_currency_code(None, currency),
5133
- 'amount': None,
5134
- 'symbol': None,
5135
- 'timestamp': None,
5136
- 'datetime': None,
5078
+ 'id': self.safe_integer(info, 'borrow_id'),
5079
+ 'currency': self.safe_currency_code(currencyId, currency),
5080
+ 'amount': self.safe_string(info, 'borrow_amount'),
5081
+ 'symbol': self.safe_symbol(marketId, None, None, 'spot'),
5082
+ 'timestamp': timestamp,
5083
+ 'datetime': self.iso8601(timestamp),
5137
5084
  'info': info,
5138
5085
  }
5139
5086