ccxt 4.2.86__py2.py3-none-any.whl → 4.2.88__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.

Files changed (82) hide show
  1. ccxt/__init__.py +1 -1
  2. ccxt/ascendex.py +16 -6
  3. ccxt/async_support/__init__.py +1 -1
  4. ccxt/async_support/ascendex.py +16 -6
  5. ccxt/async_support/base/exchange.py +1 -1
  6. ccxt/async_support/binance.py +28 -11
  7. ccxt/async_support/bingx.py +39 -3
  8. ccxt/async_support/bitfinex.py +2 -0
  9. ccxt/async_support/bitfinex2.py +18 -4
  10. ccxt/async_support/bitflyer.py +18 -0
  11. ccxt/async_support/bitget.py +37 -22
  12. ccxt/async_support/bitopro.py +2 -0
  13. ccxt/async_support/bitrue.py +16 -8
  14. ccxt/async_support/bitvavo.py +2 -0
  15. ccxt/async_support/btcmarkets.py +1 -1
  16. ccxt/async_support/btcturk.py +2 -1
  17. ccxt/async_support/coinex.py +182 -58
  18. ccxt/async_support/cryptocom.py +1 -1
  19. ccxt/async_support/currencycom.py +1 -1
  20. ccxt/async_support/delta.py +8 -6
  21. ccxt/async_support/digifinex.py +9 -7
  22. ccxt/async_support/exmo.py +15 -15
  23. ccxt/async_support/gate.py +23 -20
  24. ccxt/async_support/hitbtc.py +31 -7
  25. ccxt/async_support/htx.py +2 -2
  26. ccxt/async_support/huobijp.py +1 -1
  27. ccxt/async_support/hyperliquid.py +242 -16
  28. ccxt/async_support/idex.py +1 -1
  29. ccxt/async_support/krakenfutures.py +4 -5
  30. ccxt/async_support/kucoin.py +7 -4
  31. ccxt/async_support/kucoinfutures.py +2 -2
  32. ccxt/async_support/lbank.py +2 -0
  33. ccxt/async_support/mexc.py +4 -4
  34. ccxt/async_support/oceanex.py +1 -1
  35. ccxt/async_support/okx.py +29 -15
  36. ccxt/async_support/phemex.py +6 -4
  37. ccxt/async_support/wazirx.py +1 -1
  38. ccxt/async_support/zonda.py +2 -0
  39. ccxt/base/exchange.py +22 -3
  40. ccxt/base/types.py +12 -0
  41. ccxt/binance.py +28 -11
  42. ccxt/bingx.py +39 -3
  43. ccxt/bitfinex.py +2 -0
  44. ccxt/bitfinex2.py +18 -4
  45. ccxt/bitflyer.py +18 -0
  46. ccxt/bitget.py +37 -22
  47. ccxt/bitopro.py +2 -0
  48. ccxt/bitrue.py +16 -8
  49. ccxt/bitvavo.py +2 -0
  50. ccxt/btcmarkets.py +1 -1
  51. ccxt/btcturk.py +2 -1
  52. ccxt/coinex.py +182 -58
  53. ccxt/cryptocom.py +1 -1
  54. ccxt/currencycom.py +1 -1
  55. ccxt/delta.py +8 -6
  56. ccxt/digifinex.py +9 -7
  57. ccxt/exmo.py +15 -15
  58. ccxt/gate.py +23 -20
  59. ccxt/hitbtc.py +31 -7
  60. ccxt/htx.py +2 -2
  61. ccxt/huobijp.py +1 -1
  62. ccxt/hyperliquid.py +241 -16
  63. ccxt/idex.py +1 -1
  64. ccxt/krakenfutures.py +4 -5
  65. ccxt/kucoin.py +7 -4
  66. ccxt/kucoinfutures.py +2 -2
  67. ccxt/lbank.py +2 -0
  68. ccxt/mexc.py +4 -4
  69. ccxt/oceanex.py +1 -1
  70. ccxt/okx.py +29 -15
  71. ccxt/phemex.py +6 -4
  72. ccxt/pro/__init__.py +1 -1
  73. ccxt/pro/kucoin.py +10 -6
  74. ccxt/test/base/test_last_price.py +0 -1
  75. ccxt/test/base/test_shared_methods.py +1 -2
  76. ccxt/test/base/test_status.py +1 -1
  77. ccxt/wazirx.py +1 -1
  78. ccxt/zonda.py +2 -0
  79. {ccxt-4.2.86.dist-info → ccxt-4.2.88.dist-info}/METADATA +5 -6
  80. {ccxt-4.2.86.dist-info → ccxt-4.2.88.dist-info}/RECORD +82 -82
  81. {ccxt-4.2.86.dist-info → ccxt-4.2.88.dist-info}/WHEEL +0 -0
  82. {ccxt-4.2.86.dist-info → ccxt-4.2.88.dist-info}/top_level.txt +0 -0
ccxt/__init__.py CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  # ----------------------------------------------------------------------------
24
24
 
25
- __version__ = '4.2.86'
25
+ __version__ = '4.2.88'
26
26
 
27
27
  # ----------------------------------------------------------------------------
28
28
 
ccxt/ascendex.py CHANGED
@@ -6,7 +6,7 @@
6
6
  from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.ascendex import ImplicitAPI
8
8
  import hashlib
9
- from ccxt.base.types import Account, Balances, Currency, Int, Leverage, Leverages, MarginMode, MarginModes, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
9
+ from ccxt.base.types import Account, Balances, Currency, Int, Leverage, Leverages, MarginMode, MarginModes, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import PermissionDenied
@@ -2701,7 +2701,7 @@ class ascendex(Exchange, ImplicitAPI):
2701
2701
  result = self.parse_funding_rates(contracts)
2702
2702
  return self.filter_by_array(result, 'symbol', symbols)
2703
2703
 
2704
- def modify_margin_helper(self, symbol: str, amount, type, params={}):
2704
+ def modify_margin_helper(self, symbol: str, amount, type, params={}) -> MarginModification:
2705
2705
  self.load_markets()
2706
2706
  self.load_accounts()
2707
2707
  market = self.market(symbol)
@@ -2728,19 +2728,29 @@ class ascendex(Exchange, ImplicitAPI):
2728
2728
  'type': type,
2729
2729
  })
2730
2730
 
2731
- def parse_margin_modification(self, data, market: Market = None):
2731
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
2732
+ #
2733
+ # addMargin/reduceMargin
2734
+ #
2735
+ # {
2736
+ # "code": 0
2737
+ # }
2738
+ #
2732
2739
  errorCode = self.safe_string(data, 'code')
2733
2740
  status = 'ok' if (errorCode == '0') else 'failed'
2734
2741
  return {
2735
2742
  'info': data,
2743
+ 'symbol': market['symbol'],
2736
2744
  'type': None,
2737
2745
  'amount': None,
2746
+ 'total': None,
2738
2747
  'code': market['quote'],
2739
- 'symbol': market['symbol'],
2740
2748
  'status': status,
2749
+ 'timestamp': None,
2750
+ 'datetime': None,
2741
2751
  }
2742
2752
 
2743
- def reduce_margin(self, symbol: str, amount, params={}):
2753
+ def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
2744
2754
  """
2745
2755
  remove margin from a position
2746
2756
  :param str symbol: unified market symbol
@@ -2750,7 +2760,7 @@ class ascendex(Exchange, ImplicitAPI):
2750
2760
  """
2751
2761
  return self.modify_margin_helper(symbol, -amount, 'reduce', params)
2752
2762
 
2753
- def add_margin(self, symbol: str, amount, params={}):
2763
+ def add_margin(self, symbol: str, amount, params={}) -> MarginModification:
2754
2764
  """
2755
2765
  add margin
2756
2766
  :param str symbol: unified market symbol
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.2.86'
7
+ __version__ = '4.2.88'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -6,7 +6,7 @@
6
6
  from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.ascendex import ImplicitAPI
8
8
  import hashlib
9
- from ccxt.base.types import Account, Balances, Currency, Int, Leverage, Leverages, MarginMode, MarginModes, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
9
+ from ccxt.base.types import Account, Balances, Currency, Int, Leverage, Leverages, MarginMode, MarginModes, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import PermissionDenied
@@ -2701,7 +2701,7 @@ class ascendex(Exchange, ImplicitAPI):
2701
2701
  result = self.parse_funding_rates(contracts)
2702
2702
  return self.filter_by_array(result, 'symbol', symbols)
2703
2703
 
2704
- async def modify_margin_helper(self, symbol: str, amount, type, params={}):
2704
+ async def modify_margin_helper(self, symbol: str, amount, type, params={}) -> MarginModification:
2705
2705
  await self.load_markets()
2706
2706
  await self.load_accounts()
2707
2707
  market = self.market(symbol)
@@ -2728,19 +2728,29 @@ class ascendex(Exchange, ImplicitAPI):
2728
2728
  'type': type,
2729
2729
  })
2730
2730
 
2731
- def parse_margin_modification(self, data, market: Market = None):
2731
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
2732
+ #
2733
+ # addMargin/reduceMargin
2734
+ #
2735
+ # {
2736
+ # "code": 0
2737
+ # }
2738
+ #
2732
2739
  errorCode = self.safe_string(data, 'code')
2733
2740
  status = 'ok' if (errorCode == '0') else 'failed'
2734
2741
  return {
2735
2742
  'info': data,
2743
+ 'symbol': market['symbol'],
2736
2744
  'type': None,
2737
2745
  'amount': None,
2746
+ 'total': None,
2738
2747
  'code': market['quote'],
2739
- 'symbol': market['symbol'],
2740
2748
  'status': status,
2749
+ 'timestamp': None,
2750
+ 'datetime': None,
2741
2751
  }
2742
2752
 
2743
- async def reduce_margin(self, symbol: str, amount, params={}):
2753
+ async def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
2744
2754
  """
2745
2755
  remove margin from a position
2746
2756
  :param str symbol: unified market symbol
@@ -2750,7 +2760,7 @@ class ascendex(Exchange, ImplicitAPI):
2750
2760
  """
2751
2761
  return await self.modify_margin_helper(symbol, -amount, 'reduce', params)
2752
2762
 
2753
- async def add_margin(self, symbol: str, amount, params={}):
2763
+ async def add_margin(self, symbol: str, amount, params={}) -> MarginModification:
2754
2764
  """
2755
2765
  add margin
2756
2766
  :param str symbol: unified market symbol
@@ -2,7 +2,7 @@
2
2
 
3
3
  # -----------------------------------------------------------------------------
4
4
 
5
- __version__ = '4.2.86'
5
+ __version__ = '4.2.88'
6
6
 
7
7
  # -----------------------------------------------------------------------------
8
8
 
@@ -8,7 +8,7 @@ from ccxt.abstract.binance import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
10
  import json
11
- from ccxt.base.types import Balances, Currency, Greeks, Int, Leverage, Leverages, MarginMode, MarginModes, Market, MarketInterface, Num, Option, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
11
+ from ccxt.base.types import Balances, Currency, Greeks, Int, Leverage, Leverages, MarginMode, MarginModes, MarginModification, Market, MarketInterface, Num, Option, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
12
12
  from typing import List
13
13
  from ccxt.base.errors import ExchangeError
14
14
  from ccxt.base.errors import PermissionDenied
@@ -1883,7 +1883,7 @@ class binance(Exchange, ImplicitAPI):
1883
1883
  '-4140': BadRequest, # Invalid symbol status for opening position
1884
1884
  '-4141': OperationRejected, # Symbol is closed
1885
1885
  '-4144': BadSymbol, # Invalid pair
1886
- '-4164': OperationRejected, # Leverage reduction is not supported in Isolated Margin Mode with open positions
1886
+ '-4164': InvalidOrder, # {"code":-4164,"msg":"Order's notional must be no smaller than 20(unless you choose reduce only)."}
1887
1887
  '-4165': BadRequest, # Invalid time interval
1888
1888
  '-4167': BadRequest, # Unable to adjust to Multi-Assets mode with symbols of USDⓈ-M Futures under isolated-margin mode.
1889
1889
  '-4168': BadRequest, # Unable to adjust to isolated-margin mode under the Multi-Assets mode.
@@ -8500,7 +8500,7 @@ class binance(Exchange, ImplicitAPI):
8500
8500
  'previousFundingDatetime': None,
8501
8501
  }
8502
8502
 
8503
- def parse_account_positions(self, account):
8503
+ def parse_account_positions(self, account, filterClosed=False):
8504
8504
  positions = self.safe_list(account, 'positions')
8505
8505
  assets = self.safe_list(account, 'assets', [])
8506
8506
  balances = {}
@@ -8522,7 +8522,8 @@ class binance(Exchange, ImplicitAPI):
8522
8522
  code = market['quote'] if market['linear'] else market['base']
8523
8523
  maintenanceMargin = self.safe_string(position, 'maintMargin')
8524
8524
  # check for maintenance margin so empty positions are not returned
8525
- if (maintenanceMargin != '0') and (maintenanceMargin != '0.00000000'):
8525
+ isPositionOpen = (maintenanceMargin != '0') and (maintenanceMargin != '0.00000000')
8526
+ if not filterClosed or isPositionOpen:
8526
8527
  # sometimes not all the codes are correctly returned...
8527
8528
  if code in balances:
8528
8529
  parsed = self.parse_account_position(self.extend(position, {
@@ -9288,10 +9289,11 @@ class binance(Exchange, ImplicitAPI):
9288
9289
  :see: https://binance-docs.github.io/apidocs/delivery/en/#account-information-user_data
9289
9290
  :see: https://binance-docs.github.io/apidocs/pm/en/#get-um-account-detail-user_data
9290
9291
  :see: https://binance-docs.github.io/apidocs/pm/en/#get-cm-account-detail-user_data
9291
- :param str[]|None symbols: list of unified market symbols
9292
+ :param str[] [symbols]: list of unified market symbols
9292
9293
  :param dict [params]: extra parameters specific to the exchange API endpoint
9293
9294
  :param boolean [params.portfolioMargin]: set to True if you would like to fetch positions in a portfolio margin account
9294
9295
  :param str [params.subType]: "linear" or "inverse"
9296
+ :param boolean [params.filterClosed]: set to True if you would like to filter out closed positions, default is False
9295
9297
  :returns dict: data on account positions
9296
9298
  """
9297
9299
  if symbols is not None:
@@ -9319,7 +9321,9 @@ class binance(Exchange, ImplicitAPI):
9319
9321
  response = await self.dapiPrivateGetAccount(params)
9320
9322
  else:
9321
9323
  raise NotSupported(self.id + ' fetchPositions() supports linear and inverse contracts only')
9322
- result = self.parse_account_positions(response)
9324
+ filterClosed = None
9325
+ filterClosed, params = self.handle_option_and_params(params, 'fetchAccountPositions', 'filterClosed', False)
9326
+ result = self.parse_account_positions(response, filterClosed)
9323
9327
  symbols = self.market_symbols(symbols)
9324
9328
  return self.filter_by_array_positions(result, 'symbol', symbols, False)
9325
9329
 
@@ -10287,7 +10291,7 @@ class binance(Exchange, ImplicitAPI):
10287
10291
  raise NotSupported(self.id + ' add / reduce margin only supported with type future or delivery')
10288
10292
  await self.load_markets()
10289
10293
  market = self.market(symbol)
10290
- amount = self.cost_to_precision(symbol, amount)
10294
+ amount = self.amount_to_precision(symbol, amount)
10291
10295
  request = {
10292
10296
  'type': addOrReduce,
10293
10297
  'symbol': market['id'],
@@ -10313,7 +10317,17 @@ class binance(Exchange, ImplicitAPI):
10313
10317
  'code': code,
10314
10318
  })
10315
10319
 
10316
- def parse_margin_modification(self, data, market: Market = None):
10320
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
10321
+ #
10322
+ # add/reduce margin
10323
+ #
10324
+ # {
10325
+ # "code": 200,
10326
+ # "msg": "Successfully modify position margin.",
10327
+ # "amount": 0.001,
10328
+ # "type": 1
10329
+ # }
10330
+ #
10317
10331
  rawType = self.safe_integer(data, 'type')
10318
10332
  resultType = 'add' if (rawType == 1) else 'reduce'
10319
10333
  resultAmount = self.safe_number(data, 'amount')
@@ -10321,14 +10335,17 @@ class binance(Exchange, ImplicitAPI):
10321
10335
  status = 'ok' if (errorCode == '200') else 'failed'
10322
10336
  return {
10323
10337
  'info': data,
10338
+ 'symbol': market['symbol'],
10324
10339
  'type': resultType,
10325
10340
  'amount': resultAmount,
10341
+ 'total': None,
10326
10342
  'code': None,
10327
- 'symbol': market['symbol'],
10328
10343
  'status': status,
10344
+ 'timestamp': None,
10345
+ 'datetime': None,
10329
10346
  }
10330
10347
 
10331
- async def reduce_margin(self, symbol: str, amount, params={}):
10348
+ async def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
10332
10349
  """
10333
10350
  :see: https://binance-docs.github.io/apidocs/delivery/en/#modify-isolated-position-margin-trade
10334
10351
  :see: https://binance-docs.github.io/apidocs/futures/en/#modify-isolated-position-margin-trade
@@ -10340,7 +10357,7 @@ class binance(Exchange, ImplicitAPI):
10340
10357
  """
10341
10358
  return await self.modify_margin_helper(symbol, amount, 2, params)
10342
10359
 
10343
- async def add_margin(self, symbol: str, amount, params={}):
10360
+ async def add_margin(self, symbol: str, amount, params={}) -> MarginModification:
10344
10361
  """
10345
10362
  :see: https://binance-docs.github.io/apidocs/delivery/en/#modify-isolated-position-margin-trade
10346
10363
  :see: https://binance-docs.github.io/apidocs/futures/en/#modify-isolated-position-margin-trade
@@ -8,7 +8,7 @@ from ccxt.abstract.bingx import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
10
  import numbers
11
- from ccxt.base.types import Balances, Currency, Int, Leverage, MarginMode, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
11
+ from ccxt.base.types import Balances, Currency, Int, Leverage, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
12
12
  from typing import List
13
13
  from ccxt.base.errors import ExchangeError
14
14
  from ccxt.base.errors import PermissionDenied
@@ -44,6 +44,7 @@ class bingx(Exchange, ImplicitAPI):
44
44
  'swap': True,
45
45
  'future': False,
46
46
  'option': False,
47
+ 'addMargin': True,
47
48
  'cancelAllOrders': True,
48
49
  'cancelOrder': True,
49
50
  'cancelOrders': True,
@@ -90,6 +91,7 @@ class bingx(Exchange, ImplicitAPI):
90
91
  'fetchTrades': True,
91
92
  'fetchTransfers': True,
92
93
  'fetchWithdrawals': True,
94
+ 'reduceMargin': True,
93
95
  'setLeverage': True,
94
96
  'setMargin': True,
95
97
  'setMarginMode': True,
@@ -3247,7 +3249,19 @@ class bingx(Exchange, ImplicitAPI):
3247
3249
  }
3248
3250
  return await self.swapV2PrivatePostTradeMarginType(self.extend(request, params))
3249
3251
 
3250
- async def set_margin(self, symbol: str, amount: float, params={}):
3252
+ async def add_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3253
+ request = {
3254
+ 'type': 1,
3255
+ }
3256
+ return await self.set_margin(symbol, amount, self.extend(request, params))
3257
+
3258
+ async def reduce_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3259
+ request = {
3260
+ 'type': 2,
3261
+ }
3262
+ return await self.set_margin(symbol, amount, self.extend(request, params))
3263
+
3264
+ async def set_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3251
3265
  """
3252
3266
  Either adds or reduces margin in an isolated position in order to set the margin to a specific value
3253
3267
  :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Adjust%20isolated%20margin
@@ -3277,7 +3291,29 @@ class bingx(Exchange, ImplicitAPI):
3277
3291
  # "type": 1
3278
3292
  # }
3279
3293
  #
3280
- return response
3294
+ return self.parse_margin_modification(response, market)
3295
+
3296
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
3297
+ #
3298
+ # {
3299
+ # "code": 0,
3300
+ # "msg": "",
3301
+ # "amount": 1,
3302
+ # "type": 1
3303
+ # }
3304
+ #
3305
+ type = self.safe_string(data, 'type')
3306
+ return {
3307
+ 'info': data,
3308
+ 'symbol': self.safe_string(market, 'symbol'),
3309
+ 'type': 'add' if (type == '1') else 'reduce',
3310
+ 'amount': self.safe_number(data, 'amount'),
3311
+ 'total': self.safe_number(data, 'margin'),
3312
+ 'code': self.safe_string(market, 'settle'),
3313
+ 'status': None,
3314
+ 'timestamp': None,
3315
+ 'datetime': None,
3316
+ }
3281
3317
 
3282
3318
  async def fetch_leverage(self, symbol: str, params={}) -> Leverage:
3283
3319
  """
@@ -1259,6 +1259,8 @@ class bitfinex(Exchange, ImplicitAPI):
1259
1259
  await self.load_markets()
1260
1260
  if limit is None:
1261
1261
  limit = 100
1262
+ else:
1263
+ limit = min(limit, 10000)
1262
1264
  market = self.market(symbol)
1263
1265
  v2id = 't' + market['id']
1264
1266
  request = {
@@ -6,7 +6,7 @@
6
6
  from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.bitfinex2 import ImplicitAPI
8
8
  import hashlib
9
- from ccxt.base.types import Balances, Currency, Int, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
9
+ from ccxt.base.types import Balances, Currency, Int, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import PermissionDenied
@@ -1343,6 +1343,8 @@ class bitfinex2(Exchange, ImplicitAPI):
1343
1343
  market = self.market(symbol)
1344
1344
  if limit is None:
1345
1345
  limit = 10000
1346
+ else:
1347
+ limit = min(limit, 10000)
1346
1348
  request = {
1347
1349
  'symbol': market['id'],
1348
1350
  'timeframe': self.safe_string(self.timeframes, timeframe, timeframe),
@@ -3279,7 +3281,7 @@ class bitfinex2(Exchange, ImplicitAPI):
3279
3281
  'datetime': self.iso8601(timestamp),
3280
3282
  })
3281
3283
 
3282
- async def set_margin(self, symbol: str, amount: float, params={}):
3284
+ async def set_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3283
3285
  """
3284
3286
  either adds or reduces margin in a swap position in order to set the margin to a specific value
3285
3287
  :see: https://docs.bitfinex.com/reference/rest-auth-deriv-pos-collateral-set
@@ -3307,16 +3309,28 @@ class bitfinex2(Exchange, ImplicitAPI):
3307
3309
  data = self.safe_value(response, 0)
3308
3310
  return self.parse_margin_modification(data, market)
3309
3311
 
3310
- def parse_margin_modification(self, data, market=None):
3312
+ def parse_margin_modification(self, data, market=None) -> MarginModification:
3313
+ #
3314
+ # setMargin
3315
+ #
3316
+ # [
3317
+ # [
3318
+ # 1
3319
+ # ]
3320
+ # ]
3321
+ #
3311
3322
  marginStatusRaw = data[0]
3312
3323
  marginStatus = 'ok' if (marginStatusRaw == 1) else 'failed'
3313
3324
  return {
3314
3325
  'info': data,
3326
+ 'symbol': market['symbol'],
3315
3327
  'type': None,
3316
3328
  'amount': None,
3329
+ 'total': None,
3317
3330
  'code': None,
3318
- 'symbol': market['symbol'],
3319
3331
  'status': marginStatus,
3332
+ 'timestamp': None,
3333
+ 'datetime': None,
3320
3334
  }
3321
3335
 
3322
3336
  async def fetch_order(self, id: str, symbol: Str = None, params={}):
@@ -11,6 +11,7 @@ from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import ArgumentsRequired
13
13
  from ccxt.base.errors import OrderNotFound
14
+ from ccxt.base.errors import OnMaintenance
14
15
  from ccxt.base.decimal_to_precision import TICK_SIZE
15
16
  from ccxt.base.precise import Precise
16
17
 
@@ -118,6 +119,11 @@ class bitflyer(Exchange, ImplicitAPI):
118
119
  },
119
120
  },
120
121
  'precisionMode': TICK_SIZE,
122
+ 'exceptions': {
123
+ 'exact': {
124
+ '-2': OnMaintenance, # {"status":-2,"error_message":"Under maintenance","data":null}
125
+ },
126
+ },
121
127
  })
122
128
 
123
129
  def parse_expiry_date(self, expiry):
@@ -973,3 +979,15 @@ class bitflyer(Exchange, ImplicitAPI):
973
979
  'Content-Type': 'application/json',
974
980
  }
975
981
  return {'url': url, 'method': method, 'body': body, 'headers': headers}
982
+
983
+ def handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody):
984
+ if response is None:
985
+ return None # fallback to the default error handler
986
+ feedback = self.id + ' ' + body
987
+ # i.e. {"status":-2,"error_message":"Under maintenance","data":null}
988
+ errorMessage = self.safe_string(response, 'error_message')
989
+ statusCode = self.safe_number(response, 'status')
990
+ if errorMessage is not None:
991
+ self.throw_exactly_matched_exception(self.exceptions['exact'], statusCode, feedback)
992
+ self.throw_broadly_matched_exception(self.exceptions['broad'], errorMessage, feedback)
993
+ return None
@@ -8,7 +8,7 @@ from ccxt.abstract.bitget import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
10
  import json
11
- from ccxt.base.types import Balances, Currency, FundingHistory, Int, Leverage, Liquidation, MarginMode, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
11
+ from ccxt.base.types import Balances, Currency, FundingHistory, Int, Liquidation, Leverage, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
12
12
  from typing import List
13
13
  from ccxt.base.errors import ExchangeError
14
14
  from ccxt.base.errors import PermissionDenied
@@ -1241,6 +1241,7 @@ class bitget(Exchange, ImplicitAPI):
1241
1241
  '40768': OrderNotFound, # Order does not exist"
1242
1242
  '41114': OnMaintenance, # {"code":"41114","msg":"The current trading pair is under maintenance, please refer to the official announcement for the opening time","requestTime":1679196062544,"data":null}
1243
1243
  '43011': InvalidOrder, # The parameter does not meet the specification executePrice <= 0
1244
+ '43012': InsufficientFunds, # {"code":"43012","msg":"Insufficient balance","requestTime":1711648951774,"data":null}
1244
1245
  '43025': InvalidOrder, # Plan order does not exist
1245
1246
  '43115': OnMaintenance, # {"code":"43115","msg":"The current trading pair is opening soon, please refer to the official announcement for the opening time","requestTime":1688907202434,"data":null}
1246
1247
  '45110': InvalidOrder, # {"code":"45110","msg":"less than the minimum amount 5 USDT","requestTime":1669911118932,"data":null}
@@ -1316,6 +1317,7 @@ class bitget(Exchange, ImplicitAPI):
1316
1317
  'commonCurrencies': {
1317
1318
  'JADE': 'Jade Protocol',
1318
1319
  'DEGEN': 'DegenReborn',
1320
+ 'TONCOIN': 'TON',
1319
1321
  },
1320
1322
  'options': {
1321
1323
  'timeframes': {
@@ -1853,8 +1855,8 @@ class bitget(Exchange, ImplicitAPI):
1853
1855
  data = self.safe_value(response, 'data', [])
1854
1856
  for i in range(0, len(data)):
1855
1857
  entry = data[i]
1856
- id = self.safe_string(entry, 'coinId')
1857
- code = self.safe_currency_code(self.safe_string(entry, 'coin'))
1858
+ id = self.safe_string(entry, 'coin') # we don't use 'coinId' has no use. it is 'coin' field that needs to be used in currency related endpoints(deposit, withdraw, etc..)
1859
+ code = self.safe_currency_code(id)
1858
1860
  chains = self.safe_value(entry, 'chains', [])
1859
1861
  networks = {}
1860
1862
  deposit = False
@@ -1971,7 +1973,7 @@ class bitget(Exchange, ImplicitAPI):
1971
1973
  raise ArgumentsRequired(self.id + ' fetchMarketLeverageTiers() requires a code argument')
1972
1974
  params = self.omit(params, 'code')
1973
1975
  currency = self.currency(code)
1974
- request['coin'] = currency['code']
1976
+ request['coin'] = currency['id']
1975
1977
  response = await self.privateMarginGetV2MarginCrossedTierData(self.extend(request, params))
1976
1978
  else:
1977
1979
  raise BadRequest(self.id + ' fetchMarketLeverageTiers() symbol does not support market ' + market['symbol'])
@@ -2118,7 +2120,7 @@ class bitget(Exchange, ImplicitAPI):
2118
2120
  if since is None:
2119
2121
  since = self.milliseconds() - 7776000000 # 90 days
2120
2122
  request = {
2121
- 'coin': currency['code'],
2123
+ 'coin': currency['id'],
2122
2124
  'startTime': since,
2123
2125
  'endTime': self.milliseconds(),
2124
2126
  }
@@ -2173,7 +2175,7 @@ class bitget(Exchange, ImplicitAPI):
2173
2175
  currency = self.currency(code)
2174
2176
  networkId = self.network_code_to_id(chain)
2175
2177
  request = {
2176
- 'coin': currency['code'],
2178
+ 'coin': currency['id'],
2177
2179
  'address': address,
2178
2180
  'chain': networkId,
2179
2181
  'size': amount,
@@ -2252,7 +2254,7 @@ class bitget(Exchange, ImplicitAPI):
2252
2254
  if since is None:
2253
2255
  since = self.milliseconds() - 7776000000 # 90 days
2254
2256
  request = {
2255
- 'coin': currency['code'],
2257
+ 'coin': currency['id'],
2256
2258
  'startTime': since,
2257
2259
  'endTime': self.milliseconds(),
2258
2260
  }
@@ -2390,7 +2392,7 @@ class bitget(Exchange, ImplicitAPI):
2390
2392
  networkId = self.network_code_to_id(networkCode, code)
2391
2393
  currency = self.currency(code)
2392
2394
  request = {
2393
- 'coin': currency['code'],
2395
+ 'coin': currency['id'],
2394
2396
  }
2395
2397
  if networkId is not None:
2396
2398
  request['chain'] = networkId
@@ -5492,7 +5494,7 @@ class bitget(Exchange, ImplicitAPI):
5492
5494
  request = {}
5493
5495
  if code is not None:
5494
5496
  currency = self.currency(code)
5495
- request['coin'] = currency['code']
5497
+ request['coin'] = currency['id']
5496
5498
  request, params = self.handle_until_option('endTime', request, params)
5497
5499
  if since is not None:
5498
5500
  request['startTime'] = since
@@ -6428,7 +6430,7 @@ class bitget(Exchange, ImplicitAPI):
6428
6430
  sorted = self.sort_by(result, 'timestamp')
6429
6431
  return self.filter_by_since_limit(sorted, since, limit)
6430
6432
 
6431
- async def modify_margin_helper(self, symbol: str, amount, type, params={}):
6433
+ async def modify_margin_helper(self, symbol: str, amount, type, params={}) -> MarginModification:
6432
6434
  await self.load_markets()
6433
6435
  holdSide = self.safe_string(params, 'holdSide')
6434
6436
  sandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
@@ -6462,19 +6464,32 @@ class bitget(Exchange, ImplicitAPI):
6462
6464
  'type': type,
6463
6465
  })
6464
6466
 
6465
- def parse_margin_modification(self, data, market: Market = None):
6467
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
6468
+ #
6469
+ # addMargin/reduceMargin
6470
+ #
6471
+ # {
6472
+ # "code": "00000",
6473
+ # "msg": "success",
6474
+ # "requestTime": 1700813444618,
6475
+ # "data": ""
6476
+ # }
6477
+ #
6466
6478
  errorCode = self.safe_string(data, 'code')
6467
6479
  status = 'ok' if (errorCode == '00000') else 'failed'
6468
6480
  return {
6469
6481
  'info': data,
6482
+ 'symbol': market['symbol'],
6470
6483
  'type': None,
6471
6484
  'amount': None,
6485
+ 'total': None,
6472
6486
  'code': market['settle'],
6473
- 'symbol': market['symbol'],
6474
6487
  'status': status,
6488
+ 'timestamp': None,
6489
+ 'datetime': None,
6475
6490
  }
6476
6491
 
6477
- async def reduce_margin(self, symbol: str, amount, params={}):
6492
+ async def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
6478
6493
  """
6479
6494
  remove margin from a position
6480
6495
  :see: https://www.bitget.com/api-doc/contract/account/Change-Margin
@@ -6490,7 +6505,7 @@ class bitget(Exchange, ImplicitAPI):
6490
6505
  raise ArgumentsRequired(self.id + ' reduceMargin() requires a holdSide parameter, either long or short')
6491
6506
  return await self.modify_margin_helper(symbol, amount, 'reduce', params)
6492
6507
 
6493
- async def add_margin(self, symbol: str, amount, params={}):
6508
+ async def add_margin(self, symbol: str, amount, params={}) -> MarginModification:
6494
6509
  """
6495
6510
  add margin
6496
6511
  :see: https://www.bitget.com/api-doc/contract/account/Change-Margin
@@ -6793,7 +6808,7 @@ class bitget(Exchange, ImplicitAPI):
6793
6808
  type = self.safe_string(accountsByType, fromAccount)
6794
6809
  currency = self.currency(code)
6795
6810
  request = {
6796
- 'coin': currency['code'],
6811
+ 'coin': currency['id'],
6797
6812
  'fromType': type,
6798
6813
  }
6799
6814
  if since is not None:
@@ -6848,7 +6863,7 @@ class bitget(Exchange, ImplicitAPI):
6848
6863
  'fromType': fromType,
6849
6864
  'toType': toType,
6850
6865
  'amount': amount,
6851
- 'coin': currency['code'],
6866
+ 'coin': currency['id'],
6852
6867
  }
6853
6868
  symbol = self.safe_string(params, 'symbol')
6854
6869
  params = self.omit(params, 'symbol')
@@ -7028,7 +7043,7 @@ class bitget(Exchange, ImplicitAPI):
7028
7043
  await self.load_markets()
7029
7044
  currency = self.currency(code)
7030
7045
  request = {
7031
- 'coin': currency['code'],
7046
+ 'coin': currency['id'],
7032
7047
  'borrowAmount': self.currency_to_precision(code, amount),
7033
7048
  }
7034
7049
  response = await self.privateMarginPostV2MarginCrossedAccountBorrow(self.extend(request, params))
@@ -7061,7 +7076,7 @@ class bitget(Exchange, ImplicitAPI):
7061
7076
  currency = self.currency(code)
7062
7077
  market = self.market(symbol)
7063
7078
  request = {
7064
- 'coin': currency['code'],
7079
+ 'coin': currency['id'],
7065
7080
  'borrowAmount': self.currency_to_precision(code, amount),
7066
7081
  'symbol': market['id'],
7067
7082
  }
@@ -7096,7 +7111,7 @@ class bitget(Exchange, ImplicitAPI):
7096
7111
  currency = self.currency(code)
7097
7112
  market = self.market(symbol)
7098
7113
  request = {
7099
- 'coin': currency['code'],
7114
+ 'coin': currency['id'],
7100
7115
  'repayAmount': self.currency_to_precision(code, amount),
7101
7116
  'symbol': market['id'],
7102
7117
  }
@@ -7130,7 +7145,7 @@ class bitget(Exchange, ImplicitAPI):
7130
7145
  await self.load_markets()
7131
7146
  currency = self.currency(code)
7132
7147
  request = {
7133
- 'coin': currency['code'],
7148
+ 'coin': currency['id'],
7134
7149
  'repayAmount': self.currency_to_precision(code, amount),
7135
7150
  }
7136
7151
  response = await self.privateMarginPostV2MarginCrossedAccountRepay(self.extend(request, params))
@@ -7476,7 +7491,7 @@ class bitget(Exchange, ImplicitAPI):
7476
7491
  await self.load_markets()
7477
7492
  currency = self.currency(code)
7478
7493
  request = {
7479
- 'coin': currency['code'],
7494
+ 'coin': currency['id'],
7480
7495
  }
7481
7496
  response = await self.privateMarginGetV2MarginCrossedInterestRateAndLimit(self.extend(request, params))
7482
7497
  #
@@ -7567,7 +7582,7 @@ class bitget(Exchange, ImplicitAPI):
7567
7582
  currency = None
7568
7583
  if code is not None:
7569
7584
  currency = self.currency(code)
7570
- request['coin'] = currency['code']
7585
+ request['coin'] = currency['id']
7571
7586
  if since is not None:
7572
7587
  request['startTime'] = since
7573
7588
  else: