ccxt 4.4.20__py2.py3-none-any.whl → 4.4.22__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.
Files changed (52) hide show
  1. ccxt/__init__.py +1 -1
  2. ccxt/abstract/bitflyer.py +1 -0
  3. ccxt/abstract/bitget.py +3 -0
  4. ccxt/abstract/bybit.py +1 -0
  5. ccxt/abstract/cex.py +28 -29
  6. ccxt/abstract/gate.py +5 -0
  7. ccxt/abstract/gateio.py +5 -0
  8. ccxt/abstract/kucoin.py +2 -0
  9. ccxt/abstract/kucoinfutures.py +2 -0
  10. ccxt/abstract/okx.py +4 -0
  11. ccxt/alpaca.py +1 -0
  12. ccxt/async_support/__init__.py +1 -1
  13. ccxt/async_support/alpaca.py +1 -0
  14. ccxt/async_support/base/exchange.py +7 -1
  15. ccxt/async_support/bigone.py +3 -0
  16. ccxt/async_support/binance.py +96 -10
  17. ccxt/async_support/bingx.py +5 -1
  18. ccxt/async_support/bitflyer.py +56 -1
  19. ccxt/async_support/bitget.py +73 -1
  20. ccxt/async_support/bybit.py +135 -4
  21. ccxt/async_support/cex.py +1247 -1326
  22. ccxt/async_support/cryptocom.py +1 -1
  23. ccxt/async_support/gate.py +97 -2
  24. ccxt/async_support/htx.py +27 -7
  25. ccxt/async_support/hyperliquid.py +15 -12
  26. ccxt/async_support/kucoin.py +42 -88
  27. ccxt/async_support/kucoinfutures.py +2 -2
  28. ccxt/async_support/okx.py +76 -10
  29. ccxt/base/exchange.py +33 -1
  30. ccxt/base/types.py +9 -0
  31. ccxt/bigone.py +3 -0
  32. ccxt/binance.py +96 -10
  33. ccxt/bingx.py +5 -1
  34. ccxt/bitflyer.py +56 -1
  35. ccxt/bitget.py +73 -1
  36. ccxt/bybit.py +135 -4
  37. ccxt/cex.py +1246 -1326
  38. ccxt/cryptocom.py +1 -1
  39. ccxt/gate.py +97 -2
  40. ccxt/htx.py +27 -7
  41. ccxt/hyperliquid.py +15 -12
  42. ccxt/kucoin.py +42 -88
  43. ccxt/kucoinfutures.py +2 -2
  44. ccxt/okx.py +76 -10
  45. ccxt/pro/__init__.py +1 -1
  46. ccxt/test/tests_async.py +4 -4
  47. ccxt/test/tests_sync.py +4 -4
  48. {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/METADATA +5 -5
  49. {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/RECORD +52 -52
  50. {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/LICENSE.txt +0 -0
  51. {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/WHEEL +0 -0
  52. {ccxt-4.4.20.dist-info → ccxt-4.4.22.dist-info}/top_level.txt +0 -0
@@ -1496,7 +1496,7 @@ class cryptocom(Exchange, ImplicitAPI):
1496
1496
  paginate = False
1497
1497
  paginate, params = self.handle_option_and_params(params, 'fetchMyTrades', 'paginate')
1498
1498
  if paginate:
1499
- return await self.fetch_paginated_call_dynamic('fetchMyTrades', symbol, since, limit, params)
1499
+ return await self.fetch_paginated_call_dynamic('fetchMyTrades', symbol, since, limit, params, 100)
1500
1500
  request: dict = {}
1501
1501
  market = None
1502
1502
  if symbol is not None:
@@ -340,10 +340,17 @@ class gate(Exchange, ImplicitAPI):
340
340
  'interest_records': 20 / 15,
341
341
  'estimate_rate': 20 / 15,
342
342
  'currency_discount_tiers': 20 / 15,
343
+ 'risk_units': 20 / 15,
344
+ 'unified_mode': 20 / 15,
345
+ 'loan_margin_tiers': 20 / 15,
343
346
  },
344
347
  'post': {
345
348
  'account_mode': 20 / 15,
346
349
  'loans': 200 / 15, # 15r/10s cost = 20 / 1.5 = 13.33
350
+ 'portfolio_calculator': 20 / 15,
351
+ },
352
+ 'put': {
353
+ 'unified_mode': 20 / 15,
347
354
  },
348
355
  },
349
356
  'spot': {
@@ -645,6 +652,7 @@ class gate(Exchange, ImplicitAPI):
645
652
  },
646
653
  'options': {
647
654
  'sandboxMode': False,
655
+ 'unifiedAccount': None,
648
656
  'createOrder': {
649
657
  'expiration': 86400, # for conditional orders
650
658
  },
@@ -906,6 +914,34 @@ class gate(Exchange, ImplicitAPI):
906
914
  super(gate, self).set_sandbox_mode(enable)
907
915
  self.options['sandboxMode'] = enable
908
916
 
917
+ async def load_unified_status(self, params={}):
918
+ """
919
+ returns unifiedAccount so the user can check if the unified account is enabled
920
+ :see: https://www.gate.io/docs/developers/apiv4/#get-account-detail
921
+ :returns boolean: True or False if the enabled unified account is enabled or not and sets the unifiedAccount option if it is None
922
+ """
923
+ unifiedAccount = self.safe_bool(self.options, 'unifiedAccount')
924
+ if unifiedAccount is None:
925
+ response = await self.privateAccountGetDetail(params)
926
+ #
927
+ # {
928
+ # "user_id": 10406147,
929
+ # "ip_whitelist": [],
930
+ # "currency_pairs": [],
931
+ # "key": {
932
+ # "mode": 1
933
+ # },
934
+ # "tier": 0,
935
+ # "tier_expire_time": "0001-01-01T00:00:00Z",
936
+ # "copy_trading_role": 0
937
+ # }
938
+ #
939
+ result = self.safe_dict(response, 'key', {})
940
+ self.options['unifiedAccount'] = self.safe_integer(result, 'mode') == 2
941
+
942
+ async def upgrade_unified_trade_account(self, params={}):
943
+ return await self.privateUnifiedPutUnifiedMode(params)
944
+
909
945
  def create_expired_option_market(self, symbol: str):
910
946
  # support expired option contracts
911
947
  quote = 'USDT'
@@ -1550,6 +1586,8 @@ class gate(Exchange, ImplicitAPI):
1550
1586
  apiBackup = self.safe_value(self.urls, 'apiBackup')
1551
1587
  if apiBackup is not None:
1552
1588
  return None
1589
+ if self.check_required_credentials(False):
1590
+ await self.load_unified_status()
1553
1591
  response = await self.publicSpotGetCurrencies(params)
1554
1592
  #
1555
1593
  # {
@@ -2574,10 +2612,14 @@ class gate(Exchange, ImplicitAPI):
2574
2612
  :param str [params.settle]: 'btc' or 'usdt' - settle currency for perpetual swap and future - default="usdt" for swap and "btc" for future
2575
2613
  :param str [params.marginMode]: 'cross' or 'isolated' - marginMode for margin trading if not provided self.options['defaultMarginMode'] is used
2576
2614
  :param str [params.symbol]: margin only - unified ccxt symbol
2615
+ :param boolean [params.unifiedAccount]: default False, set to True for fetching the unified account balance
2577
2616
  """
2578
2617
  await self.load_markets()
2618
+ await self.load_unified_status()
2579
2619
  symbol = self.safe_string(params, 'symbol')
2580
2620
  params = self.omit(params, 'symbol')
2621
+ isUnifiedAccount = False
2622
+ isUnifiedAccount, params = self.handle_option_and_params(params, 'fetchBalance', 'unifiedAccount')
2581
2623
  type, query = self.handle_market_type_and_params('fetchBalance', None, params)
2582
2624
  request, requestParams = self.prepare_request(None, type, query)
2583
2625
  marginMode, requestQuery = self.get_margin_mode(False, requestParams)
@@ -2585,7 +2627,9 @@ class gate(Exchange, ImplicitAPI):
2585
2627
  market = self.market(symbol)
2586
2628
  request['currency_pair'] = market['id']
2587
2629
  response = None
2588
- if type == 'spot':
2630
+ if isUnifiedAccount:
2631
+ response = await self.privateUnifiedGetAccounts(self.extend(request, params))
2632
+ elif type == 'spot':
2589
2633
  if marginMode == 'spot':
2590
2634
  response = await self.privateSpotGetAccounts(self.extend(request, requestQuery))
2591
2635
  elif marginMode == 'margin':
@@ -2748,12 +2792,63 @@ class gate(Exchange, ImplicitAPI):
2748
2792
  # "orders_limit": 10
2749
2793
  # }
2750
2794
  #
2795
+ # unified
2796
+ #
2797
+ # {
2798
+ # "user_id": 10001,
2799
+ # "locked": False,
2800
+ # "balances": {
2801
+ # "ETH": {
2802
+ # "available": "0",
2803
+ # "freeze": "0",
2804
+ # "borrowed": "0.075393666654",
2805
+ # "negative_liab": "0",
2806
+ # "futures_pos_liab": "0",
2807
+ # "equity": "1016.1",
2808
+ # "total_freeze": "0",
2809
+ # "total_liab": "0"
2810
+ # },
2811
+ # "POINT": {
2812
+ # "available": "9999999999.017023138734",
2813
+ # "freeze": "0",
2814
+ # "borrowed": "0",
2815
+ # "negative_liab": "0",
2816
+ # "futures_pos_liab": "0",
2817
+ # "equity": "12016.1",
2818
+ # "total_freeze": "0",
2819
+ # "total_liab": "0"
2820
+ # },
2821
+ # "USDT": {
2822
+ # "available": "0.00000062023",
2823
+ # "freeze": "0",
2824
+ # "borrowed": "0",
2825
+ # "negative_liab": "0",
2826
+ # "futures_pos_liab": "0",
2827
+ # "equity": "16.1",
2828
+ # "total_freeze": "0",
2829
+ # "total_liab": "0"
2830
+ # }
2831
+ # },
2832
+ # "total": "230.94621713",
2833
+ # "borrowed": "161.66395521",
2834
+ # "total_initial_margin": "1025.0524665088",
2835
+ # "total_margin_balance": "3382495.944473949183",
2836
+ # "total_maintenance_margin": "205.01049330176",
2837
+ # "total_initial_margin_rate": "3299.827135672679",
2838
+ # "total_maintenance_margin_rate": "16499.135678363399",
2839
+ # "total_available_margin": "3381470.892007440383",
2840
+ # "unified_account_total": "3381470.892007440383",
2841
+ # "unified_account_total_liab": "0",
2842
+ # "unified_account_total_equity": "100016.1",
2843
+ # "leverage": "2"
2844
+ # }
2845
+ #
2751
2846
  result: dict = {
2752
2847
  'info': response,
2753
2848
  }
2754
2849
  isolated = marginMode == 'margin'
2755
2850
  data = response
2756
- if 'balances' in data: # True for cross_margin
2851
+ if 'balances' in data: # True for cross_margin and unified
2757
2852
  flatBalances = []
2758
2853
  balances = self.safe_value(data, 'balances', [])
2759
2854
  # inject currency and create an artificial balance object
ccxt/async_support/htx.py CHANGED
@@ -1628,6 +1628,10 @@ class htx(Exchange, ImplicitAPI):
1628
1628
  async def fetch_markets(self, params={}) -> List[Market]:
1629
1629
  """
1630
1630
  retrieves data on all markets for huobi
1631
+ :see: https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-trading-symbol-v1-deprecated
1632
+ :see: https://huobiapi.github.io/docs/dm/v1/en/#get-contract-info
1633
+ :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-swap-info
1634
+ :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-swap-info
1631
1635
  :param dict [params]: extra parameters specific to the exchange API endpoint
1632
1636
  :returns dict[]: an array of objects representing market data
1633
1637
  """
@@ -1651,7 +1655,19 @@ class htx(Exchange, ImplicitAPI):
1651
1655
  allMarkets = self.array_concat(allMarkets, promises[i])
1652
1656
  return allMarkets
1653
1657
 
1654
- async def fetch_markets_by_type_and_sub_type(self, type, subType, params={}):
1658
+ async def fetch_markets_by_type_and_sub_type(self, type: Str, subType: Str, params={}):
1659
+ """
1660
+ * @ignore
1661
+ retrieves data on all markets of a certain type and/or subtype
1662
+ :see: https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-trading-symbol-v1-deprecated
1663
+ :see: https://huobiapi.github.io/docs/dm/v1/en/#get-contract-info
1664
+ :see: https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-swap-info
1665
+ :see: https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-swap-info
1666
+ :param str [type]: 'spot', 'swap' or 'future'
1667
+ :param str [subType]: 'linear' or 'inverse'
1668
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1669
+ :returns dict[]: an array of objects representing market data
1670
+ """
1655
1671
  isSpot = (type == 'spot')
1656
1672
  request: dict = {}
1657
1673
  response = None
@@ -3015,7 +3031,15 @@ class htx(Exchange, ImplicitAPI):
3015
3031
  'code': None,
3016
3032
  }
3017
3033
 
3018
- async def fetch_account_id_by_type(self, type, marginMode=None, symbol=None, params={}):
3034
+ async def fetch_account_id_by_type(self, type: str, marginMode: Str = None, symbol: Str = None, params={}):
3035
+ """
3036
+ fetch all the accounts by a type and marginModeassociated with a profile
3037
+ :see: https://huobiapi.github.io/docs/spot/v1/en/#get-all-accounts-of-the-current-user
3038
+ :param str type: 'spot', 'swap' or 'future
3039
+ :param str [marginMode]: 'cross' or 'isolated'
3040
+ :param dict [params]: extra parameters specific to the exchange API endpoint
3041
+ :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
3042
+ """
3019
3043
  accounts = await self.load_accounts()
3020
3044
  accountId = self.safe_value_2(params, 'accountId', 'account-id')
3021
3045
  if accountId is not None:
@@ -4756,11 +4780,7 @@ class htx(Exchange, ImplicitAPI):
4756
4780
  cost = None
4757
4781
  amount = None
4758
4782
  if (type is not None) and (type.find('market') >= 0):
4759
- # for market orders amount is in quote currency, meaning it is the cost
4760
- if side == 'sell':
4761
- cost = self.safe_string(order, 'field-cash-amount')
4762
- else:
4763
- cost = self.safe_string(order, 'amount')
4783
+ cost = self.safe_string(order, 'field-cash-amount')
4764
4784
  else:
4765
4785
  amount = self.safe_string_2(order, 'volume', 'amount')
4766
4786
  cost = self.safe_string_n(order, ['filled-cash-amount', 'field-cash-amount', 'trade_turnover']) # same typo here
@@ -639,17 +639,17 @@ class hyperliquid(Exchange, ImplicitAPI):
639
639
  code = self.safe_currency_code(self.safe_string(balance, 'coin'))
640
640
  account = self.account()
641
641
  total = self.safe_string(balance, 'total')
642
- free = self.safe_string(balance, 'hold')
642
+ used = self.safe_string(balance, 'hold')
643
643
  account['total'] = total
644
- account['used'] = free
644
+ account['used'] = used
645
645
  spotBalances[code] = account
646
646
  return self.safe_balance(spotBalances)
647
647
  data = self.safe_dict(response, 'marginSummary', {})
648
648
  result: dict = {
649
649
  'info': response,
650
650
  'USDC': {
651
- 'total': self.safe_float(data, 'accountValue'),
652
- 'used': self.safe_float(data, 'totalMarginUsed'),
651
+ 'total': self.safe_number(data, 'accountValue'),
652
+ 'free': self.safe_number(response, 'withdrawable'),
653
653
  },
654
654
  }
655
655
  timestamp = self.safe_integer(response, 'time')
@@ -2113,13 +2113,16 @@ class hyperliquid(Exchange, ImplicitAPI):
2113
2113
  leverage = self.safe_dict(entry, 'leverage', {})
2114
2114
  marginMode = self.safe_string(leverage, 'type')
2115
2115
  isIsolated = (marginMode == 'isolated')
2116
- size = self.safe_number(entry, 'szi')
2116
+ rawSize = self.safe_string(entry, 'szi')
2117
+ size = rawSize
2117
2118
  side = None
2118
2119
  if size is not None:
2119
- side = 'long' if (size > 0) else 'short'
2120
- unrealizedPnl = self.safe_number(entry, 'unrealizedPnl')
2121
- initialMargin = self.safe_number(entry, 'marginUsed')
2122
- percentage = unrealizedPnl / initialMargin * 100
2120
+ side = 'long' if Precise.string_gt(rawSize, '0') else 'short'
2121
+ size = Precise.string_abs(size)
2122
+ rawUnrealizedPnl = self.safe_string(entry, 'unrealizedPnl')
2123
+ absRawUnrealizedPnl = Precise.string_abs(rawUnrealizedPnl)
2124
+ initialMargin = self.safe_string(entry, 'marginUsed')
2125
+ percentage = Precise.string_mul(Precise.string_div(absRawUnrealizedPnl, initialMargin), '100')
2123
2126
  return self.safe_position({
2124
2127
  'info': position,
2125
2128
  'id': None,
@@ -2129,7 +2132,7 @@ class hyperliquid(Exchange, ImplicitAPI):
2129
2132
  'isolated': isIsolated,
2130
2133
  'hedged': None,
2131
2134
  'side': side,
2132
- 'contracts': size,
2135
+ 'contracts': self.parse_number(size),
2133
2136
  'contractSize': None,
2134
2137
  'entryPrice': self.safe_number(entry, 'entryPx'),
2135
2138
  'markPrice': None,
@@ -2140,10 +2143,10 @@ class hyperliquid(Exchange, ImplicitAPI):
2140
2143
  'maintenanceMargin': None,
2141
2144
  'initialMarginPercentage': None,
2142
2145
  'maintenanceMarginPercentage': None,
2143
- 'unrealizedPnl': unrealizedPnl,
2146
+ 'unrealizedPnl': self.parse_number(rawUnrealizedPnl),
2144
2147
  'liquidationPrice': self.safe_number(entry, 'liquidationPx'),
2145
2148
  'marginMode': marginMode,
2146
- 'percentage': percentage,
2149
+ 'percentage': self.parse_number(percentage),
2147
2150
  })
2148
2151
 
2149
2152
  async def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
@@ -184,6 +184,7 @@ class kucoin(Exchange, ImplicitAPI):
184
184
  'mark-price/{symbol}/current': 3, # 2PW
185
185
  'mark-price/all-symbols': 3,
186
186
  'margin/config': 25, # 25SW
187
+ 'announcements': 20, # 20W
187
188
  },
188
189
  'post': {
189
190
  # ws
@@ -307,6 +308,7 @@ class kucoin(Exchange, ImplicitAPI):
307
308
  # ws
308
309
  'bullet-private': 10, # 10SW
309
310
  'position/update-user-leverage': 5,
311
+ 'deposit-address/create': 20,
310
312
  },
311
313
  'delete': {
312
314
  # account
@@ -473,6 +475,7 @@ class kucoin(Exchange, ImplicitAPI):
473
475
  'precisionMode': TICK_SIZE,
474
476
  'exceptions': {
475
477
  'exact': {
478
+ 'The order does not exist.': OrderNotFound,
476
479
  'order not exist': OrderNotFound,
477
480
  'order not exist.': OrderNotFound, # duplicated error temporarily
478
481
  'order_not_exist': OrderNotFound, # {"code":"order_not_exist","msg":"order_not_exist"} ¯\_(ツ)_/¯
@@ -673,6 +676,7 @@ class kucoin(Exchange, ImplicitAPI):
673
676
  'currencies/{currency}': 'v3',
674
677
  'symbols': 'v2',
675
678
  'mark-price/all-symbols': 'v3',
679
+ 'announcements': 'v3',
676
680
  },
677
681
  },
678
682
  'private': {
@@ -724,6 +728,7 @@ class kucoin(Exchange, ImplicitAPI):
724
728
  'accounts/sub-transfer': 'v2',
725
729
  'accounts/inner-transfer': 'v2',
726
730
  'transfer-out': 'v3',
731
+ 'deposit-address/create': 'v3',
727
732
  # spot trading
728
733
  'oco/order': 'v3',
729
734
  # margin trading
@@ -735,6 +740,7 @@ class kucoin(Exchange, ImplicitAPI):
735
740
  'redeem': 'v3',
736
741
  'lend/purchase/update': 'v3',
737
742
  'position/update-user-leverage': 'v3',
743
+ 'withdrawals': 'v3',
738
744
  },
739
745
  'DELETE': {
740
746
  # account
@@ -800,7 +806,7 @@ class kucoin(Exchange, ImplicitAPI):
800
806
  'TLOS': 'tlos', # tlosevm is different
801
807
  'CFX': 'cfx',
802
808
  'ACA': 'aca',
803
- 'OPTIMISM': 'optimism',
809
+ 'OP': 'optimism',
804
810
  'ONT': 'ont',
805
811
  'GLMR': 'glmr',
806
812
  'CSPR': 'cspr',
@@ -1530,38 +1536,28 @@ class kucoin(Exchange, ImplicitAPI):
1530
1536
  # "chain": "ERC20"
1531
1537
  # }
1532
1538
  #
1539
+ minWithdrawFee = self.safe_number(fee, 'withdrawMinFee')
1533
1540
  result: dict = {
1534
1541
  'info': fee,
1535
1542
  'withdraw': {
1543
+ 'fee': minWithdrawFee,
1544
+ 'percentage': False,
1545
+ },
1546
+ 'deposit': {
1536
1547
  'fee': None,
1537
1548
  'percentage': None,
1538
1549
  },
1550
+ 'networks': {},
1551
+ }
1552
+ networkId = self.safe_string(fee, 'chain')
1553
+ networkCode = self.network_id_to_code(networkId, self.safe_string(currency, 'code'))
1554
+ result['networks'][networkCode] = {
1555
+ 'withdraw': minWithdrawFee,
1539
1556
  'deposit': {
1540
1557
  'fee': None,
1541
1558
  'percentage': None,
1542
1559
  },
1543
- 'networks': {},
1544
1560
  }
1545
- isWithdrawEnabled = self.safe_bool(fee, 'isWithdrawEnabled', True)
1546
- minFee = None
1547
- if isWithdrawEnabled:
1548
- result['withdraw']['percentage'] = False
1549
- chains = self.safe_list(fee, 'chains', [])
1550
- for i in range(0, len(chains)):
1551
- chain = chains[i]
1552
- networkId = self.safe_string(chain, 'chainId')
1553
- networkCode = self.network_id_to_code(networkId, self.safe_string(currency, 'code'))
1554
- withdrawFee = self.safe_string(chain, 'withdrawalMinFee')
1555
- if minFee is None or (Precise.string_lt(withdrawFee, minFee)):
1556
- minFee = withdrawFee
1557
- result['networks'][networkCode] = {
1558
- 'withdraw': self.parse_number(withdrawFee),
1559
- 'deposit': {
1560
- 'fee': None,
1561
- 'percentage': None,
1562
- },
1563
- }
1564
- result['withdraw']['fee'] = self.parse_number(minFee)
1565
1561
  return result
1566
1562
 
1567
1563
  def is_futures_method(self, methodName, params):
@@ -1870,7 +1866,7 @@ class kucoin(Exchange, ImplicitAPI):
1870
1866
 
1871
1867
  async def create_deposit_address(self, code: str, params={}):
1872
1868
  """
1873
- :see: https://docs.kucoin.com/#create-deposit-address
1869
+ :see: https://www.kucoin.com/docs/rest/funding/deposit/create-deposit-address-v3-
1874
1870
  create a currency deposit address
1875
1871
  :param str code: unified currency code of the currency for the deposit address
1876
1872
  :param dict [params]: extra parameters specific to the exchange API endpoint
@@ -1885,11 +1881,23 @@ class kucoin(Exchange, ImplicitAPI):
1885
1881
  networkCode = None
1886
1882
  networkCode, params = self.handle_network_code_and_params(params)
1887
1883
  if networkCode is not None:
1888
- request['chain'] = self.network_code_to_id(networkCode).lower()
1889
- response = await self.privatePostDepositAddresses(self.extend(request, params))
1884
+ request['chain'] = self.network_code_to_id(networkCode) # docs mention "chain-name", but seems "chain-id" is used, like in "fetchDepositAddress"
1885
+ response = await self.privatePostDepositAddressCreate(self.extend(request, params))
1890
1886
  # {"code":"260000","msg":"Deposit address already exists."}
1891
- # BCH {"code":"200000","data":{"address":"bitcoincash:qza3m4nj9rx7l9r0cdadfqxts6f92shvhvr5ls4q7z","memo":""}}
1892
- # BTC {"code":"200000","data":{"address":"36SjucKqQpQSvsak9A7h6qzFjrVXpRNZhE","memo":""}}
1887
+ #
1888
+ # {
1889
+ # "code": "200000",
1890
+ # "data": {
1891
+ # "address": "0x2336d1834faab10b2dac44e468f2627138417431",
1892
+ # "memo": null,
1893
+ # "chainId": "bsc",
1894
+ # "to": "MAIN",
1895
+ # "expirationDate": 0,
1896
+ # "currency": "BNB",
1897
+ # "chainName": "BEP20"
1898
+ # }
1899
+ # }
1900
+ #
1893
1901
  data = self.safe_dict(response, 'data', {})
1894
1902
  return self.parse_deposit_address(data, currency)
1895
1903
 
@@ -1939,7 +1947,7 @@ class kucoin(Exchange, ImplicitAPI):
1939
1947
  return {
1940
1948
  'info': depositAddress,
1941
1949
  'currency': code,
1942
- 'network': self.network_id_to_code(self.safe_string(depositAddress, 'chain')),
1950
+ 'network': self.network_id_to_code(self.safe_string(depositAddress, 'chainId')),
1943
1951
  'address': address,
1944
1952
  'tag': self.safe_string(depositAddress, 'memo'),
1945
1953
  }
@@ -2921,7 +2929,7 @@ class kucoin(Exchange, ImplicitAPI):
2921
2929
  },
2922
2930
  'status': status,
2923
2931
  'lastTradeTimestamp': None,
2924
- 'average': None,
2932
+ 'average': self.safe_string(order, 'avgDealPrice'),
2925
2933
  'trades': None,
2926
2934
  }, market)
2927
2935
 
@@ -3246,7 +3254,7 @@ class kucoin(Exchange, ImplicitAPI):
3246
3254
  async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
3247
3255
  """
3248
3256
  make a withdrawal
3249
- :see: https://www.kucoin.com/docs/rest/funding/withdrawals/apply-withdraw
3257
+ :see: https://www.kucoin.com/docs/rest/funding/withdrawals/apply-withdraw-v3-
3250
3258
  :param str code: unified currency code
3251
3259
  :param float amount: the amount to withdraw
3252
3260
  :param str address: the address to withdraw to
@@ -3260,7 +3268,8 @@ class kucoin(Exchange, ImplicitAPI):
3260
3268
  currency = self.currency(code)
3261
3269
  request: dict = {
3262
3270
  'currency': currency['id'],
3263
- 'address': address,
3271
+ 'toAddress': address,
3272
+ 'withdrawType': 'ADDRESS',
3264
3273
  # 'memo': tag,
3265
3274
  # 'isInner': False, # internal transfer or external withdrawal
3266
3275
  # 'remark': 'optional',
@@ -3272,15 +3281,14 @@ class kucoin(Exchange, ImplicitAPI):
3272
3281
  networkCode, params = self.handle_network_code_and_params(params)
3273
3282
  if networkCode is not None:
3274
3283
  request['chain'] = self.network_code_to_id(networkCode).lower()
3275
- await self.load_currency_precision(currency, networkCode)
3276
- request['amount'] = self.currency_to_precision(code, amount, networkCode)
3284
+ request['amount'] = float(self.currency_to_precision(code, amount, networkCode))
3277
3285
  includeFee = None
3278
3286
  includeFee, params = self.handle_option_and_params(params, 'withdraw', 'includeFee', False)
3279
3287
  if includeFee:
3280
3288
  request['feeDeductType'] = 'INTERNAL'
3281
3289
  response = await self.privatePostWithdrawals(self.extend(request, params))
3282
3290
  #
3283
- # https://github.com/ccxt/ccxt/issues/5558
3291
+ # the id is inside "data"
3284
3292
  #
3285
3293
  # {
3286
3294
  # "code": 200000,
@@ -3292,51 +3300,6 @@ class kucoin(Exchange, ImplicitAPI):
3292
3300
  data = self.safe_dict(response, 'data', {})
3293
3301
  return self.parse_transaction(data, currency)
3294
3302
 
3295
- async def load_currency_precision(self, currency, networkCode: Str = None):
3296
- # might not have network specific precisions defined in fetchCurrencies(because of webapi failure)
3297
- # we should check and refetch precision once-per-instance for that specific currency & network
3298
- # so avoids thorwing exceptions and burden to users
3299
- # Note: self needs to be executed only if networkCode was provided
3300
- if networkCode is not None:
3301
- networks = currency['networks']
3302
- network = self.safe_dict(networks, networkCode)
3303
- if self.safe_number(network, 'precision') is not None:
3304
- # if precision exists, no need to refetch
3305
- return
3306
- # otherwise try to fetch and store in instance
3307
- request: dict = {
3308
- 'currency': currency['id'],
3309
- 'chain': self.network_code_to_id(networkCode).lower(),
3310
- }
3311
- response = await self.privateGetWithdrawalsQuotas(request)
3312
- #
3313
- # {
3314
- # "code": "200000",
3315
- # "data": {
3316
- # "currency": "USDT",
3317
- # "limitBTCAmount": "14.24094850",
3318
- # "usedBTCAmount": "0.00000000",
3319
- # "quotaCurrency": "USDT",
3320
- # "limitQuotaCurrencyAmount": "999999.00000000",
3321
- # "usedQuotaCurrencyAmount": "0",
3322
- # "remainAmount": "999999.0000",
3323
- # "availableAmount": "10.77545071",
3324
- # "withdrawMinFee": "1",
3325
- # "innerWithdrawMinFee": "0",
3326
- # "withdrawMinSize": "10",
3327
- # "isWithdrawEnabled": True,
3328
- # "precision": 4,
3329
- # "chain": "EOS",
3330
- # "reason": null,
3331
- # "lockedAmount": "0"
3332
- # }
3333
- # }
3334
- #
3335
- data = self.safe_dict(response, 'data', {})
3336
- precision = self.parse_number(self.parse_precision(self.safe_string(data, 'precision')))
3337
- code = currency['code']
3338
- self.currencies[code]['networks'][networkCode]['precision'] = precision
3339
-
3340
3303
  def parse_transaction_status(self, status: Str):
3341
3304
  statuses: dict = {
3342
3305
  'SUCCESS': 'ok',
@@ -4154,15 +4117,6 @@ class kucoin(Exchange, ImplicitAPI):
4154
4117
  return config['v1']
4155
4118
  return self.safe_value(config, 'cost', 1)
4156
4119
 
4157
- def parse_borrow_rate_history(self, response, code, since, limit):
4158
- result = []
4159
- for i in range(0, len(response)):
4160
- item = response[i]
4161
- borrowRate = self.parse_borrow_rate(item)
4162
- result.append(borrowRate)
4163
- sorted = self.sort_by(result, 'timestamp')
4164
- return self.filter_by_currency_since_limit(sorted, code, since, limit)
4165
-
4166
4120
  def parse_borrow_rate(self, info, currency: Currency = None):
4167
4121
  #
4168
4122
  # {
@@ -2103,8 +2103,8 @@ class kucoinfutures(kucoin, ImplicitAPI):
2103
2103
  amount = self.safe_string(order, 'size')
2104
2104
  filled = self.safe_string(order, 'filledSize')
2105
2105
  cost = self.safe_string(order, 'filledValue')
2106
- average = None
2107
- if Precise.string_gt(filled, '0'):
2106
+ average = self.safe_string(order, 'avgDealPrice')
2107
+ if (average is None) and Precise.string_gt(filled, '0'):
2108
2108
  contractSize = self.safe_string(market, 'contractSize')
2109
2109
  if market['linear']:
2110
2110
  average = Precise.string_div(cost, Precise.string_mul(contractSize, filled))