ccxt 4.2.86__py2.py3-none-any.whl → 4.2.87__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 (78) 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 +18 -5
  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 +20 -6
  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/currencycom.py +1 -1
  19. ccxt/async_support/delta.py +8 -6
  20. ccxt/async_support/digifinex.py +9 -7
  21. ccxt/async_support/exmo.py +15 -15
  22. ccxt/async_support/gate.py +9 -6
  23. ccxt/async_support/hitbtc.py +31 -7
  24. ccxt/async_support/htx.py +2 -2
  25. ccxt/async_support/huobijp.py +1 -1
  26. ccxt/async_support/hyperliquid.py +242 -16
  27. ccxt/async_support/idex.py +1 -1
  28. ccxt/async_support/krakenfutures.py +2 -4
  29. ccxt/async_support/kucoinfutures.py +2 -2
  30. ccxt/async_support/lbank.py +2 -0
  31. ccxt/async_support/mexc.py +3 -3
  32. ccxt/async_support/oceanex.py +1 -1
  33. ccxt/async_support/okx.py +29 -15
  34. ccxt/async_support/phemex.py +6 -4
  35. ccxt/async_support/wazirx.py +1 -1
  36. ccxt/async_support/zonda.py +2 -0
  37. ccxt/base/exchange.py +1 -1
  38. ccxt/base/types.py +12 -0
  39. ccxt/binance.py +18 -5
  40. ccxt/bingx.py +39 -3
  41. ccxt/bitfinex.py +2 -0
  42. ccxt/bitfinex2.py +18 -4
  43. ccxt/bitflyer.py +18 -0
  44. ccxt/bitget.py +20 -6
  45. ccxt/bitopro.py +2 -0
  46. ccxt/bitrue.py +16 -8
  47. ccxt/bitvavo.py +2 -0
  48. ccxt/btcmarkets.py +1 -1
  49. ccxt/btcturk.py +2 -1
  50. ccxt/coinex.py +182 -58
  51. ccxt/currencycom.py +1 -1
  52. ccxt/delta.py +8 -6
  53. ccxt/digifinex.py +9 -7
  54. ccxt/exmo.py +15 -15
  55. ccxt/gate.py +9 -6
  56. ccxt/hitbtc.py +31 -7
  57. ccxt/htx.py +2 -2
  58. ccxt/huobijp.py +1 -1
  59. ccxt/hyperliquid.py +241 -16
  60. ccxt/idex.py +1 -1
  61. ccxt/krakenfutures.py +2 -4
  62. ccxt/kucoinfutures.py +2 -2
  63. ccxt/lbank.py +2 -0
  64. ccxt/mexc.py +3 -3
  65. ccxt/oceanex.py +1 -1
  66. ccxt/okx.py +29 -15
  67. ccxt/phemex.py +6 -4
  68. ccxt/pro/__init__.py +1 -1
  69. ccxt/pro/kucoin.py +10 -6
  70. ccxt/test/base/test_last_price.py +0 -1
  71. ccxt/test/base/test_shared_methods.py +1 -2
  72. ccxt/test/base/test_status.py +1 -1
  73. ccxt/wazirx.py +1 -1
  74. ccxt/zonda.py +2 -0
  75. {ccxt-4.2.86.dist-info → ccxt-4.2.87.dist-info}/METADATA +4 -4
  76. {ccxt-4.2.86.dist-info → ccxt-4.2.87.dist-info}/RECORD +78 -78
  77. {ccxt-4.2.86.dist-info → ccxt-4.2.87.dist-info}/WHEEL +0 -0
  78. {ccxt-4.2.86.dist-info → ccxt-4.2.87.dist-info}/top_level.txt +0 -0
ccxt/async_support/okx.py CHANGED
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.okx import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
- from ccxt.base.types import Account, Balances, Currency, Greeks, Int, Leverage, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
+ from ccxt.base.types import Account, Balances, Currency, Greeks, Int, Leverage, MarginModification, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import PermissionDenied
@@ -6007,7 +6007,7 @@ class okx(Exchange, ImplicitAPI):
6007
6007
  data = self.safe_value(response, 'data')
6008
6008
  return self.parse_borrow_rate_history(data, code, since, limit)
6009
6009
 
6010
- async def modify_margin_helper(self, symbol: str, amount, type, params={}):
6010
+ async def modify_margin_helper(self, symbol: str, amount, type, params={}) -> MarginModification:
6011
6011
  await self.load_markets()
6012
6012
  market = self.market(symbol)
6013
6013
  posSide = self.safe_string(params, 'posSide', 'net')
@@ -6033,29 +6033,43 @@ class okx(Exchange, ImplicitAPI):
6033
6033
  # "msg": ""
6034
6034
  # }
6035
6035
  #
6036
- return self.parse_margin_modification(response, market)
6036
+ data = self.safe_list(response, 'data', [])
6037
+ errorCode = self.safe_string(response, 'code')
6038
+ item = self.safe_dict(data, 0, {})
6039
+ return self.extend(self.parse_margin_modification(item, market), {
6040
+ 'status': 'ok' if (errorCode == '0') else 'failed',
6041
+ })
6037
6042
 
6038
- def parse_margin_modification(self, data, market: Market = None):
6039
- innerData = self.safe_value(data, 'data', [])
6040
- entry = self.safe_value(innerData, 0, {})
6041
- errorCode = self.safe_string(data, 'code')
6042
- status = 'ok' if (errorCode == '0') else 'failed'
6043
- amountRaw = self.safe_number(entry, 'amt')
6044
- typeRaw = self.safe_string(entry, 'type')
6043
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
6044
+ #
6045
+ # addMargin/reduceMargin
6046
+ #
6047
+ # {
6048
+ # "amt": "0.01",
6049
+ # "instId": "ETH-USD-SWAP",
6050
+ # "posSide": "net",
6051
+ # "type": "reduce"
6052
+ # }
6053
+ #
6054
+ amountRaw = self.safe_number(data, 'amt')
6055
+ typeRaw = self.safe_string(data, 'type')
6045
6056
  type = 'reduce' if (typeRaw == 'reduce') else 'add'
6046
- marketId = self.safe_string(entry, 'instId')
6057
+ marketId = self.safe_string(data, 'instId')
6047
6058
  responseMarket = self.safe_market(marketId, market)
6048
6059
  code = responseMarket['base'] if responseMarket['inverse'] else responseMarket['quote']
6049
6060
  return {
6050
6061
  'info': data,
6062
+ 'symbol': responseMarket['symbol'],
6051
6063
  'type': type,
6052
6064
  'amount': amountRaw,
6065
+ 'total': None,
6053
6066
  'code': code,
6054
- 'symbol': responseMarket['symbol'],
6055
- 'status': status,
6067
+ 'status': None,
6068
+ 'timestamp': None,
6069
+ 'datetime': None,
6056
6070
  }
6057
6071
 
6058
- async def reduce_margin(self, symbol: str, amount, params={}):
6072
+ async def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
6059
6073
  """
6060
6074
  remove margin from a position
6061
6075
  :see: https://www.okx.com/docs-v5/en/#trading-account-rest-api-increase-decrease-margin
@@ -6066,7 +6080,7 @@ class okx(Exchange, ImplicitAPI):
6066
6080
  """
6067
6081
  return await self.modify_margin_helper(symbol, amount, 'reduce', params)
6068
6082
 
6069
- async def add_margin(self, symbol: str, amount, params={}):
6083
+ async def add_margin(self, symbol: str, amount, params={}) -> MarginModification:
6070
6084
  """
6071
6085
  add margin
6072
6086
  :see: https://www.okx.com/docs-v5/en/#trading-account-rest-api-increase-decrease-margin
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.phemex import ImplicitAPI
8
8
  import hashlib
9
9
  import numbers
10
- from ccxt.base.types import Balances, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
+ from ccxt.base.types import Balances, Currency, Int, MarginModification, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import PermissionDenied
@@ -3744,7 +3744,7 @@ class phemex(Exchange, ImplicitAPI):
3744
3744
  'previousFundingDatetime': None,
3745
3745
  }
3746
3746
 
3747
- async def set_margin(self, symbol: str, amount: float, params={}):
3747
+ async def set_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3748
3748
  """
3749
3749
  Either adds or reduces margin in an isolated position in order to set the margin to a specific value
3750
3750
  :see: https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#assign-position-balance-in-isolated-marign-mode
@@ -3777,7 +3777,7 @@ class phemex(Exchange, ImplicitAPI):
3777
3777
  }
3778
3778
  return self.safe_string(statuses, status, status)
3779
3779
 
3780
- def parse_margin_modification(self, data, market: Market = None):
3780
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
3781
3781
  #
3782
3782
  # {
3783
3783
  # "code": 0,
@@ -3790,12 +3790,14 @@ class phemex(Exchange, ImplicitAPI):
3790
3790
  codeCurrency = 'base' if inverse else 'quote'
3791
3791
  return {
3792
3792
  'info': data,
3793
+ 'symbol': self.safe_symbol(None, market),
3793
3794
  'type': 'set',
3794
3795
  'amount': None,
3795
3796
  'total': None,
3796
3797
  'code': market[codeCurrency],
3797
- 'symbol': self.safe_symbol(None, market),
3798
3798
  'status': self.parse_margin_status(self.safe_string(data, 'code')),
3799
+ 'timestamp': None,
3800
+ 'datetime': None,
3799
3801
  }
3800
3802
 
3801
3803
  async def set_margin_mode(self, marginMode: str, symbol: Str = None, params={}):
@@ -324,7 +324,7 @@ class wazirx(Exchange, ImplicitAPI):
324
324
  'interval': self.safe_string(self.timeframes, timeframe, timeframe),
325
325
  }
326
326
  if limit is not None:
327
- request['limit'] = limit
327
+ request['limit'] = min(limit, 2000)
328
328
  until = self.safe_integer(params, 'until')
329
329
  params = self.omit(params, ['until'])
330
330
  if since is not None:
@@ -1181,6 +1181,8 @@ class zonda(Exchange, ImplicitAPI):
1181
1181
  }
1182
1182
  if limit is None:
1183
1183
  limit = 100
1184
+ else:
1185
+ limit = min(limit, 11000) # supports up to 11k candles diapason
1184
1186
  duration = self.parse_timeframe(timeframe)
1185
1187
  timerange = limit * duration * 1000
1186
1188
  if since is None:
ccxt/base/exchange.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.2.86'
7
+ __version__ = '4.2.87'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
ccxt/base/types.py CHANGED
@@ -324,6 +324,7 @@ class Option(TypedDict):
324
324
 
325
325
  OptionChain = Dict[str, Option]
326
326
 
327
+
327
328
  class MarketInterface(TypedDict):
328
329
  info: Dict[str, Any]
329
330
  id: Str
@@ -375,6 +376,17 @@ class LastPrice(TypedDict):
375
376
  info: Dict[str, Any]
376
377
 
377
378
 
379
+ class MarginModification(TypedDict):
380
+ info: Dict[str, any]
381
+ symbol: str
382
+ type: Optional[Literal['add', 'reduce', 'set']]
383
+ amount: Optional[float]
384
+ code: Str
385
+ status: Str
386
+ timestamp: Int
387
+ datetime: Str
388
+
389
+
378
390
  LastPrices = Dict[Str, LastPrice]
379
391
 
380
392
  Market = Optional[MarketInterface]
ccxt/binance.py CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.binance import ImplicitAPI
8
8
  import hashlib
9
9
  import json
10
- 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
10
+ 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
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import PermissionDenied
@@ -10312,7 +10312,17 @@ class binance(Exchange, ImplicitAPI):
10312
10312
  'code': code,
10313
10313
  })
10314
10314
 
10315
- def parse_margin_modification(self, data, market: Market = None):
10315
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
10316
+ #
10317
+ # add/reduce margin
10318
+ #
10319
+ # {
10320
+ # "code": 200,
10321
+ # "msg": "Successfully modify position margin.",
10322
+ # "amount": 0.001,
10323
+ # "type": 1
10324
+ # }
10325
+ #
10316
10326
  rawType = self.safe_integer(data, 'type')
10317
10327
  resultType = 'add' if (rawType == 1) else 'reduce'
10318
10328
  resultAmount = self.safe_number(data, 'amount')
@@ -10320,14 +10330,17 @@ class binance(Exchange, ImplicitAPI):
10320
10330
  status = 'ok' if (errorCode == '200') else 'failed'
10321
10331
  return {
10322
10332
  'info': data,
10333
+ 'symbol': market['symbol'],
10323
10334
  'type': resultType,
10324
10335
  'amount': resultAmount,
10336
+ 'total': None,
10325
10337
  'code': None,
10326
- 'symbol': market['symbol'],
10327
10338
  'status': status,
10339
+ 'timestamp': None,
10340
+ 'datetime': None,
10328
10341
  }
10329
10342
 
10330
- def reduce_margin(self, symbol: str, amount, params={}):
10343
+ def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
10331
10344
  """
10332
10345
  :see: https://binance-docs.github.io/apidocs/delivery/en/#modify-isolated-position-margin-trade
10333
10346
  :see: https://binance-docs.github.io/apidocs/futures/en/#modify-isolated-position-margin-trade
@@ -10339,7 +10352,7 @@ class binance(Exchange, ImplicitAPI):
10339
10352
  """
10340
10353
  return self.modify_margin_helper(symbol, amount, 2, params)
10341
10354
 
10342
- def add_margin(self, symbol: str, amount, params={}):
10355
+ def add_margin(self, symbol: str, amount, params={}) -> MarginModification:
10343
10356
  """
10344
10357
  :see: https://binance-docs.github.io/apidocs/delivery/en/#modify-isolated-position-margin-trade
10345
10358
  :see: https://binance-docs.github.io/apidocs/futures/en/#modify-isolated-position-margin-trade
ccxt/bingx.py CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.bingx import ImplicitAPI
8
8
  import hashlib
9
9
  import numbers
10
- 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
10
+ 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
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import PermissionDenied
@@ -43,6 +43,7 @@ class bingx(Exchange, ImplicitAPI):
43
43
  'swap': True,
44
44
  'future': False,
45
45
  'option': False,
46
+ 'addMargin': True,
46
47
  'cancelAllOrders': True,
47
48
  'cancelOrder': True,
48
49
  'cancelOrders': True,
@@ -89,6 +90,7 @@ class bingx(Exchange, ImplicitAPI):
89
90
  'fetchTrades': True,
90
91
  'fetchTransfers': True,
91
92
  'fetchWithdrawals': True,
93
+ 'reduceMargin': True,
92
94
  'setLeverage': True,
93
95
  'setMargin': True,
94
96
  'setMarginMode': True,
@@ -3246,7 +3248,19 @@ class bingx(Exchange, ImplicitAPI):
3246
3248
  }
3247
3249
  return self.swapV2PrivatePostTradeMarginType(self.extend(request, params))
3248
3250
 
3249
- def set_margin(self, symbol: str, amount: float, params={}):
3251
+ def add_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3252
+ request = {
3253
+ 'type': 1,
3254
+ }
3255
+ return self.set_margin(symbol, amount, self.extend(request, params))
3256
+
3257
+ def reduce_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3258
+ request = {
3259
+ 'type': 2,
3260
+ }
3261
+ return self.set_margin(symbol, amount, self.extend(request, params))
3262
+
3263
+ def set_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
3250
3264
  """
3251
3265
  Either adds or reduces margin in an isolated position in order to set the margin to a specific value
3252
3266
  :see: https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Adjust%20isolated%20margin
@@ -3276,7 +3290,29 @@ class bingx(Exchange, ImplicitAPI):
3276
3290
  # "type": 1
3277
3291
  # }
3278
3292
  #
3279
- return response
3293
+ return self.parse_margin_modification(response, market)
3294
+
3295
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
3296
+ #
3297
+ # {
3298
+ # "code": 0,
3299
+ # "msg": "",
3300
+ # "amount": 1,
3301
+ # "type": 1
3302
+ # }
3303
+ #
3304
+ type = self.safe_string(data, 'type')
3305
+ return {
3306
+ 'info': data,
3307
+ 'symbol': self.safe_string(market, 'symbol'),
3308
+ 'type': 'add' if (type == '1') else 'reduce',
3309
+ 'amount': self.safe_number(data, 'amount'),
3310
+ 'total': self.safe_number(data, 'margin'),
3311
+ 'code': self.safe_string(market, 'settle'),
3312
+ 'status': None,
3313
+ 'timestamp': None,
3314
+ 'datetime': None,
3315
+ }
3280
3316
 
3281
3317
  def fetch_leverage(self, symbol: str, params={}) -> Leverage:
3282
3318
  """
ccxt/bitfinex.py CHANGED
@@ -1259,6 +1259,8 @@ class bitfinex(Exchange, ImplicitAPI):
1259
1259
  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 = {
ccxt/bitfinex2.py CHANGED
@@ -6,7 +6,7 @@
6
6
  from ccxt.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
- def set_margin(self, symbol: str, amount: float, params={}):
3284
+ 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
  def fetch_order(self, id: str, symbol: Str = None, params={}):
ccxt/bitflyer.py CHANGED
@@ -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
ccxt/bitget.py CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.bitget import ImplicitAPI
8
8
  import hashlib
9
9
  import json
10
- 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
10
+ 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
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import PermissionDenied
@@ -1240,6 +1240,7 @@ class bitget(Exchange, ImplicitAPI):
1240
1240
  '40768': OrderNotFound, # Order does not exist"
1241
1241
  '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}
1242
1242
  '43011': InvalidOrder, # The parameter does not meet the specification executePrice <= 0
1243
+ '43012': InsufficientFunds, # {"code":"43012","msg":"Insufficient balance","requestTime":1711648951774,"data":null}
1243
1244
  '43025': InvalidOrder, # Plan order does not exist
1244
1245
  '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}
1245
1246
  '45110': InvalidOrder, # {"code":"45110","msg":"less than the minimum amount 5 USDT","requestTime":1669911118932,"data":null}
@@ -6427,7 +6428,7 @@ class bitget(Exchange, ImplicitAPI):
6427
6428
  sorted = self.sort_by(result, 'timestamp')
6428
6429
  return self.filter_by_since_limit(sorted, since, limit)
6429
6430
 
6430
- def modify_margin_helper(self, symbol: str, amount, type, params={}):
6431
+ def modify_margin_helper(self, symbol: str, amount, type, params={}) -> MarginModification:
6431
6432
  self.load_markets()
6432
6433
  holdSide = self.safe_string(params, 'holdSide')
6433
6434
  sandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
@@ -6461,19 +6462,32 @@ class bitget(Exchange, ImplicitAPI):
6461
6462
  'type': type,
6462
6463
  })
6463
6464
 
6464
- def parse_margin_modification(self, data, market: Market = None):
6465
+ def parse_margin_modification(self, data, market: Market = None) -> MarginModification:
6466
+ #
6467
+ # addMargin/reduceMargin
6468
+ #
6469
+ # {
6470
+ # "code": "00000",
6471
+ # "msg": "success",
6472
+ # "requestTime": 1700813444618,
6473
+ # "data": ""
6474
+ # }
6475
+ #
6465
6476
  errorCode = self.safe_string(data, 'code')
6466
6477
  status = 'ok' if (errorCode == '00000') else 'failed'
6467
6478
  return {
6468
6479
  'info': data,
6480
+ 'symbol': market['symbol'],
6469
6481
  'type': None,
6470
6482
  'amount': None,
6483
+ 'total': None,
6471
6484
  'code': market['settle'],
6472
- 'symbol': market['symbol'],
6473
6485
  'status': status,
6486
+ 'timestamp': None,
6487
+ 'datetime': None,
6474
6488
  }
6475
6489
 
6476
- def reduce_margin(self, symbol: str, amount, params={}):
6490
+ def reduce_margin(self, symbol: str, amount, params={}) -> MarginModification:
6477
6491
  """
6478
6492
  remove margin from a position
6479
6493
  :see: https://www.bitget.com/api-doc/contract/account/Change-Margin
@@ -6489,7 +6503,7 @@ class bitget(Exchange, ImplicitAPI):
6489
6503
  raise ArgumentsRequired(self.id + ' reduceMargin() requires a holdSide parameter, either long or short')
6490
6504
  return self.modify_margin_helper(symbol, amount, 'reduce', params)
6491
6505
 
6492
- def add_margin(self, symbol: str, amount, params={}):
6506
+ def add_margin(self, symbol: str, amount, params={}) -> MarginModification:
6493
6507
  """
6494
6508
  add margin
6495
6509
  :see: https://www.bitget.com/api-doc/contract/account/Change-Margin
ccxt/bitopro.py CHANGED
@@ -735,6 +735,8 @@ class bitopro(Exchange, ImplicitAPI):
735
735
  # we need to have a limit argument because "to" and "from" are required
736
736
  if limit is None:
737
737
  limit = 500
738
+ else:
739
+ limit = min(limit, 75000) # supports slightly more than 75k candles atm, but limit here to avoid errors
738
740
  timeframeInSeconds = self.parse_timeframe(timeframe)
739
741
  alignedSince = None
740
742
  if since is None:
ccxt/bitrue.py CHANGED
@@ -7,7 +7,7 @@ from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.bitrue import ImplicitAPI
8
8
  import hashlib
9
9
  import json
10
- from ccxt.base.types import Balances, Currency, Int, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
10
+ from ccxt.base.types import Balances, Currency, Int, MarginModification, Market, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, Transaction, TransferEntry
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import PermissionDenied
@@ -1310,8 +1310,6 @@ class bitrue(Exchange, ImplicitAPI):
1310
1310
  'interval': self.safe_string(timeframesFuture, timeframe, '1min'),
1311
1311
  }
1312
1312
  if limit is not None:
1313
- if limit > 300:
1314
- limit = 300
1315
1313
  request['limit'] = limit
1316
1314
  if market['linear']:
1317
1315
  response = self.fapiV1PublicGetKlines(self.extend(request, params))
@@ -1326,8 +1324,6 @@ class bitrue(Exchange, ImplicitAPI):
1326
1324
  'scale': self.safe_string(timeframesSpot, timeframe, '1m'),
1327
1325
  }
1328
1326
  if limit is not None:
1329
- if limit > 1440:
1330
- limit = 1440
1331
1327
  request['limit'] = limit
1332
1328
  if since is not None:
1333
1329
  request['fromIdx'] = since
@@ -2842,17 +2838,29 @@ class bitrue(Exchange, ImplicitAPI):
2842
2838
  response = self.dapiV2PrivatePostLevelEdit(self.extend(request, params))
2843
2839
  return response
2844
2840
 
2845
- def parse_margin_modification(self, data, market=None):
2841
+ def parse_margin_modification(self, data, market=None) -> MarginModification:
2842
+ #
2843
+ # setMargin
2844
+ #
2845
+ # {
2846
+ # "code": 0,
2847
+ # "msg": "success"
2848
+ # "data": null
2849
+ # }
2850
+ #
2846
2851
  return {
2847
2852
  'info': data,
2853
+ 'symbol': market['symbol'],
2848
2854
  'type': None,
2849
2855
  'amount': None,
2856
+ 'total': None,
2850
2857
  'code': None,
2851
- 'symbol': market['symbol'],
2852
2858
  'status': None,
2859
+ 'timestamp': None,
2860
+ 'datetime': None,
2853
2861
  }
2854
2862
 
2855
- def set_margin(self, symbol: str, amount: float, params={}):
2863
+ def set_margin(self, symbol: str, amount: float, params={}) -> MarginModification:
2856
2864
  """
2857
2865
  Either adds or reduces margin in an isolated position in order to set the margin to a specific value
2858
2866
  :see: https://www.bitrue.com/api-docs#modify-isolated-position-margin-trade-hmac-sha256
ccxt/bitvavo.py CHANGED
@@ -923,6 +923,8 @@ class bitvavo(Exchange, ImplicitAPI):
923
923
  request['start'] = since
924
924
  if limit is None:
925
925
  limit = 1440
926
+ else:
927
+ limit = min(limit, 1440)
926
928
  request['end'] = self.sum(since, limit * duration * 1000)
927
929
  request, params = self.handle_until_option('end', request, params)
928
930
  if limit is not None:
ccxt/btcmarkets.py CHANGED
@@ -522,7 +522,7 @@ class btcmarkets(Exchange, ImplicitAPI):
522
522
  if since is not None:
523
523
  request['from'] = self.iso8601(since)
524
524
  if limit is not None:
525
- request['limit'] = limit # default is 10, max 200
525
+ request['limit'] = min(limit, 200) # default is 10, max 200
526
526
  response = self.publicGetMarketsMarketIdCandles(self.extend(request, params))
527
527
  #
528
528
  # [
ccxt/btcturk.py CHANGED
@@ -570,6 +570,7 @@ class btcturk(Exchange, ImplicitAPI):
570
570
  elif limit is None: # since will also be None
571
571
  limit = 100 # default value
572
572
  if limit is not None:
573
+ limit = min(limit, 11000) # max 11000 candles diapason can be covered
573
574
  if timeframe == '1y': # difficult with leap years
574
575
  raise BadRequest(self.id + ' fetchOHLCV() does not accept a limit parameter when timeframe == "1y"')
575
576
  seconds = self.parse_timeframe(timeframe)
@@ -578,7 +579,7 @@ class btcturk(Exchange, ImplicitAPI):
578
579
  to = self.parse_to_int(since / 1000) + limitSeconds
579
580
  request['to'] = min(request['to'], to)
580
581
  else:
581
- request['from'] = self.parse_to_int(until / 1000) - limitSeconds
582
+ request['from'] = self.parse_to_int(0 / 1000) - limitSeconds
582
583
  response = self.graphGetKlinesHistory(self.extend(request, params))
583
584
  #
584
585
  # {