ccxt 4.4.21__py2.py3-none-any.whl → 4.4.23__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 (76) hide show
  1. ccxt/__init__.py +3 -1
  2. ccxt/abstract/binance.py +64 -43
  3. ccxt/abstract/binancecoinm.py +64 -43
  4. ccxt/abstract/binanceus.py +64 -43
  5. ccxt/abstract/binanceusdm.py +64 -43
  6. ccxt/abstract/bitflyer.py +1 -0
  7. ccxt/abstract/bitget.py +3 -0
  8. ccxt/abstract/cex.py +28 -29
  9. ccxt/abstract/coincatch.py +94 -0
  10. ccxt/abstract/gate.py +5 -0
  11. ccxt/abstract/gateio.py +5 -0
  12. ccxt/abstract/kucoin.py +1 -0
  13. ccxt/abstract/kucoinfutures.py +1 -0
  14. ccxt/abstract/okx.py +1 -0
  15. ccxt/alpaca.py +1 -0
  16. ccxt/async_support/__init__.py +3 -1
  17. ccxt/async_support/alpaca.py +1 -0
  18. ccxt/async_support/base/exchange.py +7 -1
  19. ccxt/async_support/bigone.py +3 -0
  20. ccxt/async_support/binance.py +183 -63
  21. ccxt/async_support/bitfinex.py +4 -0
  22. ccxt/async_support/bitflyer.py +57 -1
  23. ccxt/async_support/bitget.py +73 -1
  24. ccxt/async_support/bitrue.py +3 -0
  25. ccxt/async_support/bybit.py +76 -3
  26. ccxt/async_support/cex.py +1247 -1322
  27. ccxt/async_support/coinbase.py +1 -1
  28. ccxt/async_support/coinbaseexchange.py +3 -0
  29. ccxt/async_support/coincatch.py +4955 -0
  30. ccxt/async_support/coinex.py +60 -1
  31. ccxt/async_support/cryptocom.py +1 -1
  32. ccxt/async_support/gate.py +97 -2
  33. ccxt/async_support/htx.py +1 -5
  34. ccxt/async_support/hyperliquid.py +10 -8
  35. ccxt/async_support/kucoin.py +27 -57
  36. ccxt/async_support/latoken.py +6 -0
  37. ccxt/async_support/mexc.py +1 -1
  38. ccxt/async_support/oceanex.py +2 -0
  39. ccxt/async_support/okcoin.py +1 -0
  40. ccxt/async_support/okx.py +67 -1
  41. ccxt/async_support/poloniex.py +5 -0
  42. ccxt/base/exchange.py +21 -1
  43. ccxt/base/types.py +9 -0
  44. ccxt/bigone.py +3 -0
  45. ccxt/binance.py +183 -63
  46. ccxt/bitfinex.py +4 -0
  47. ccxt/bitflyer.py +57 -1
  48. ccxt/bitget.py +73 -1
  49. ccxt/bitrue.py +3 -0
  50. ccxt/bybit.py +76 -3
  51. ccxt/cex.py +1246 -1322
  52. ccxt/coinbase.py +1 -1
  53. ccxt/coinbaseexchange.py +3 -0
  54. ccxt/coincatch.py +4955 -0
  55. ccxt/coinex.py +60 -1
  56. ccxt/cryptocom.py +1 -1
  57. ccxt/gate.py +97 -2
  58. ccxt/htx.py +1 -5
  59. ccxt/hyperliquid.py +10 -8
  60. ccxt/kucoin.py +27 -57
  61. ccxt/latoken.py +6 -0
  62. ccxt/mexc.py +1 -1
  63. ccxt/oceanex.py +2 -0
  64. ccxt/okcoin.py +1 -0
  65. ccxt/okx.py +67 -1
  66. ccxt/poloniex.py +5 -0
  67. ccxt/pro/__init__.py +3 -1
  68. ccxt/pro/coincatch.py +1429 -0
  69. ccxt/test/tests_async.py +19 -5
  70. ccxt/test/tests_sync.py +19 -5
  71. ccxt-4.4.23.dist-info/METADATA +636 -0
  72. {ccxt-4.4.21.dist-info → ccxt-4.4.23.dist-info}/RECORD +75 -71
  73. ccxt-4.4.21.dist-info/METADATA +0 -635
  74. {ccxt-4.4.21.dist-info → ccxt-4.4.23.dist-info}/LICENSE.txt +0 -0
  75. {ccxt-4.4.21.dist-info → ccxt-4.4.23.dist-info}/WHEEL +0 -0
  76. {ccxt-4.4.21.dist-info → ccxt-4.4.23.dist-info}/top_level.txt +0 -0
@@ -6,7 +6,7 @@
6
6
  from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.bitflyer import ImplicitAPI
8
8
  import hashlib
9
- from ccxt.base.types import Balances, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, Trade, TradingFeeInterface, Transaction
9
+ from ccxt.base.types import Balances, Currency, Int, Market, MarketInterface, Num, Order, OrderBook, OrderSide, OrderType, Str, Strings, Ticker, FundingRate, Trade, TradingFeeInterface, Transaction
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import ArgumentsRequired
@@ -39,6 +39,9 @@ class bitflyer(Exchange, ImplicitAPI):
39
39
  'fetchBalance': True,
40
40
  'fetchClosedOrders': 'emulated',
41
41
  'fetchDeposits': True,
42
+ 'fetchFundingRate': True,
43
+ 'fetchFundingRateHistory': False,
44
+ 'fetchFundingRates': False,
42
45
  'fetchMarginMode': False,
43
46
  'fetchMarkets': True,
44
47
  'fetchMyTrades': True,
@@ -78,6 +81,7 @@ class bitflyer(Exchange, ImplicitAPI):
78
81
  'gethealth',
79
82
  'getboardstate',
80
83
  'getchats',
84
+ 'getfundingrate',
81
85
  ],
82
86
  },
83
87
  'private': {
@@ -963,6 +967,58 @@ class bitflyer(Exchange, ImplicitAPI):
963
967
  'fee': fee,
964
968
  }
965
969
 
970
+ async def fetch_funding_rate(self, symbol: str, params={}) -> FundingRate:
971
+ """
972
+ fetch the current funding rate
973
+ :see: https://lightning.bitflyer.com/docs#funding-rate
974
+ :param str symbol: unified market symbol
975
+ :param dict [params]: extra parameters specific to the exchange API endpoint
976
+ :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
977
+ """
978
+ await self.load_markets()
979
+ market = self.market(symbol)
980
+ request: dict = {
981
+ 'product_code': market['id'],
982
+ }
983
+ response = await self.publicGetGetfundingrate(self.extend(request, params))
984
+ #
985
+ # {
986
+ # "current_funding_rate": -0.003750000000
987
+ # "next_funding_rate_settledate": "2024-04-15T13:00:00"
988
+ # }
989
+ #
990
+ return self.parse_funding_rate(response, market)
991
+
992
+ def parse_funding_rate(self, contract, market: Market = None) -> FundingRate:
993
+ #
994
+ # {
995
+ # "current_funding_rate": -0.003750000000
996
+ # "next_funding_rate_settledate": "2024-04-15T13:00:00"
997
+ # }
998
+ #
999
+ nextFundingDatetime = self.safe_string(contract, 'next_funding_rate_settledate')
1000
+ nextFundingTimestamp = self.parse8601(nextFundingDatetime)
1001
+ return {
1002
+ 'info': contract,
1003
+ 'symbol': self.safe_string(market, 'symbol'),
1004
+ 'markPrice': None,
1005
+ 'indexPrice': None,
1006
+ 'interestRate': None,
1007
+ 'estimatedSettlePrice': None,
1008
+ 'timestamp': None,
1009
+ 'datetime': None,
1010
+ 'fundingRate': None,
1011
+ 'fundingTimestamp': None,
1012
+ 'fundingDatetime': None,
1013
+ 'nextFundingRate': self.safe_number(contract, 'current_funding_rate'),
1014
+ 'nextFundingTimestamp': nextFundingTimestamp,
1015
+ 'nextFundingDatetime': self.iso8601(nextFundingTimestamp),
1016
+ 'previousFundingRate': None,
1017
+ 'previousFundingTimestamp': None,
1018
+ 'previousFundingDatetime': None,
1019
+ 'interval': None,
1020
+ }
1021
+
966
1022
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
967
1023
  request = '/' + self.version + '/'
968
1024
  if api == 'private':
@@ -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, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, FundingHistory, Int, IsolatedBorrowRate, LedgerEntry, Leverage, LeverageTier, Liquidation, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
11
+ from ccxt.base.types import LongShortRatio, Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, FundingHistory, Int, IsolatedBorrowRate, LedgerEntry, Leverage, LeverageTier, Liquidation, MarginMode, MarginModification, Market, Num, Order, OrderBook, OrderRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
12
12
  from typing import List
13
13
  from ccxt.base.errors import ExchangeError
14
14
  from ccxt.base.errors import AuthenticationError
@@ -114,6 +114,8 @@ class bitget(Exchange, ImplicitAPI):
114
114
  'fetchLeverage': True,
115
115
  'fetchLeverageTiers': False,
116
116
  'fetchLiquidations': False,
117
+ 'fetchLongShortRatio': False,
118
+ 'fetchLongShortRatioHistory': True,
117
119
  'fetchMarginAdjustmentHistory': False,
118
120
  'fetchMarginMode': True,
119
121
  'fetchMarketLeverageTiers': True,
@@ -289,6 +291,7 @@ class bitget(Exchange, ImplicitAPI):
289
291
  'v2/mix/market/current-fund-rate': 1,
290
292
  'v2/mix/market/contracts': 1,
291
293
  'v2/mix/market/query-position-lever': 2,
294
+ 'v2/mix/market/account-long-short': 20,
292
295
  },
293
296
  },
294
297
  'margin': {
@@ -299,6 +302,7 @@ class bitget(Exchange, ImplicitAPI):
299
302
  'margin/v1/isolated/public/tierData': 2, # 10 times/1s(IP) => 20/10 = 2
300
303
  'margin/v1/public/currencies': 1, # 20 times/1s(IP) => 20/20 = 1
301
304
  'v2/margin/currencies': 2,
305
+ 'v2/margin/market/long-short-ratio': 20,
302
306
  },
303
307
  },
304
308
  'earn': {
@@ -461,6 +465,7 @@ class bitget(Exchange, ImplicitAPI):
461
465
  'v2/mix/order/orders-history': 2,
462
466
  'v2/mix/order/orders-plan-pending': 2,
463
467
  'v2/mix/order/orders-plan-history': 2,
468
+ 'v2/mix/market/position-long-short': 20,
464
469
  },
465
470
  'post': {
466
471
  'mix/v1/account/sub-account-contract-assets': 200, # 0.1 times/1s(UID) => 20/0.1 = 200
@@ -8273,6 +8278,73 @@ class bitget(Exchange, ImplicitAPI):
8273
8278
  first = self.safe_dict(data, 0, {})
8274
8279
  return self.parse_funding_rate(first, market)
8275
8280
 
8281
+ async def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
8282
+ """
8283
+ fetches the long short ratio history for a unified market symbol
8284
+ :see: https://www.bitget.com/api-doc/common/apidata/Margin-Ls-Ratio
8285
+ :see: https://www.bitget.com/api-doc/common/apidata/Account-Long-Short
8286
+ :param str symbol: unified symbol of the market to fetch the long short ratio for
8287
+ :param str [timeframe]: the period for the ratio
8288
+ :param int [since]: the earliest time in ms to fetch ratios for
8289
+ :param int [limit]: the maximum number of long short ratio structures to retrieve
8290
+ :param dict [params]: extra parameters specific to the exchange API endpoint
8291
+ :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
8292
+ """
8293
+ await self.load_markets()
8294
+ market = self.market(symbol)
8295
+ request: dict = {
8296
+ 'symbol': market['id'],
8297
+ }
8298
+ if timeframe is not None:
8299
+ request['period'] = timeframe
8300
+ response = None
8301
+ if market['swap'] or market['future']:
8302
+ response = await self.publicMixGetV2MixMarketAccountLongShort(self.extend(request, params))
8303
+ #
8304
+ # {
8305
+ # "code": "00000",
8306
+ # "msg": "success",
8307
+ # "requestTime": 1729321233281,
8308
+ # "data": [
8309
+ # {
8310
+ # "longAccountRatio": "0.58",
8311
+ # "shortAccountRatio": "0.42",
8312
+ # "longShortAccountRatio": "0.0138",
8313
+ # "ts": "1729312200000"
8314
+ # },
8315
+ # ]
8316
+ # }
8317
+ #
8318
+ else:
8319
+ response = await self.publicMarginGetV2MarginMarketLongShortRatio(self.extend(request, params))
8320
+ #
8321
+ # {
8322
+ # "code": "00000",
8323
+ # "msg": "success",
8324
+ # "requestTime": 1729306974712,
8325
+ # "data": [
8326
+ # {
8327
+ # "longShortRatio": "40.66",
8328
+ # "ts": "1729306800000"
8329
+ # },
8330
+ # ]
8331
+ # }
8332
+ #
8333
+ data = self.safe_list(response, 'data', [])
8334
+ return self.parse_long_short_ratio_history(data, market)
8335
+
8336
+ def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
8337
+ marketId = self.safe_string(info, 'symbol')
8338
+ timestamp = self.safe_integer_omit_zero(info, 'ts')
8339
+ return {
8340
+ 'info': info,
8341
+ 'symbol': self.safe_symbol(marketId, market, None, 'contract'),
8342
+ 'timestamp': timestamp,
8343
+ 'datetime': self.iso8601(timestamp),
8344
+ 'timeframe': None,
8345
+ 'longShortRatio': self.safe_number_2(info, 'longShortRatio', 'longShortAccountRatio'),
8346
+ }
8347
+
8276
8348
  def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
8277
8349
  if not response:
8278
8350
  return None # fallback to default error handler
@@ -73,7 +73,10 @@ class bitrue(Exchange, ImplicitAPI):
73
73
  'fetchDepositsWithdrawals': False,
74
74
  'fetchDepositWithdrawFee': 'emulated',
75
75
  'fetchDepositWithdrawFees': True,
76
+ 'fetchFundingHistory': False,
76
77
  'fetchFundingRate': False,
78
+ 'fetchFundingRateHistory': False,
79
+ 'fetchFundingRates': False,
77
80
  'fetchIsolatedBorrowRate': False,
78
81
  'fetchIsolatedBorrowRates': False,
79
82
  'fetchMarginMode': False,
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.bybit import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
- from ccxt.base.types import Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, Greeks, Int, LedgerEntry, Leverage, LeverageTier, LeverageTiers, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, FundingRates, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
10
+ from ccxt.base.types import LongShortRatio, Balances, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, Greeks, Int, LedgerEntry, Leverage, LeverageTier, LeverageTiers, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, FundingRate, FundingRates, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import AuthenticationError
@@ -106,6 +106,8 @@ class bybit(Exchange, ImplicitAPI):
106
106
  'fetchLedger': True,
107
107
  'fetchLeverage': True,
108
108
  'fetchLeverageTiers': True,
109
+ 'fetchLongShortRatio': False,
110
+ 'fetchLongShortRatioHistory': True,
109
111
  'fetchMarginAdjustmentHistory': False,
110
112
  'fetchMarketLeverageTiers': True,
111
113
  'fetchMarkets': True,
@@ -7086,13 +7088,13 @@ class bybit(Exchange, ImplicitAPI):
7086
7088
 
7087
7089
  def parse_margin_loan(self, info, currency: Currency = None):
7088
7090
  #
7089
- # borrowMargin
7091
+ # borrowCrossMargin
7090
7092
  #
7091
7093
  # {
7092
7094
  # "transactId": "14143"
7093
7095
  # }
7094
7096
  #
7095
- # repayMargin
7097
+ # repayCrossMargin
7096
7098
  #
7097
7099
  # {
7098
7100
  # "repayId": "12128"
@@ -8665,6 +8667,77 @@ class bybit(Exchange, ImplicitAPI):
8665
8667
  'fee': None,
8666
8668
  }
8667
8669
 
8670
+ async def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
8671
+ """
8672
+ fetches the long short ratio history for a unified market symbol
8673
+ :see: https://bybit-exchange.github.io/docs/v5/market/long-short-ratio
8674
+ :param str symbol: unified symbol of the market to fetch the long short ratio for
8675
+ :param str [timeframe]: the period for the ratio, default is 24 hours
8676
+ :param int [since]: the earliest time in ms to fetch ratios for
8677
+ :param int [limit]: the maximum number of long short ratio structures to retrieve
8678
+ :param dict [params]: extra parameters specific to the exchange API endpoint
8679
+ :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
8680
+ """
8681
+ await self.load_markets()
8682
+ market = self.market(symbol)
8683
+ type = None
8684
+ type, params = self.get_bybit_type('fetchLongShortRatioHistory', market, params)
8685
+ if type == 'spot' or type == 'option':
8686
+ raise NotSupported(self.id + ' fetchLongShortRatioHistory() only support linear and inverse markets')
8687
+ if timeframe is None:
8688
+ timeframe = '1d'
8689
+ request: dict = {
8690
+ 'symbol': market['id'],
8691
+ 'period': timeframe,
8692
+ 'category': type,
8693
+ }
8694
+ if limit is not None:
8695
+ request['limit'] = limit
8696
+ response = await self.publicGetV5MarketAccountRatio(self.extend(request, params))
8697
+ #
8698
+ # {
8699
+ # "retCode": 0,
8700
+ # "retMsg": "OK",
8701
+ # "result": {
8702
+ # "list": [
8703
+ # {
8704
+ # "symbol": "BTCUSDT",
8705
+ # "buyRatio": "0.5707",
8706
+ # "sellRatio": "0.4293",
8707
+ # "timestamp": "1729123200000"
8708
+ # },
8709
+ # ]
8710
+ # },
8711
+ # "retExtInfo": {},
8712
+ # "time": 1729147842516
8713
+ # }
8714
+ #
8715
+ result = self.safe_dict(response, 'result', {})
8716
+ data = self.safe_list(result, 'list', [])
8717
+ return self.parse_long_short_ratio_history(data, market)
8718
+
8719
+ def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
8720
+ #
8721
+ # {
8722
+ # "symbol": "BTCUSDT",
8723
+ # "buyRatio": "0.5707",
8724
+ # "sellRatio": "0.4293",
8725
+ # "timestamp": "1729123200000"
8726
+ # }
8727
+ #
8728
+ marketId = self.safe_string(info, 'symbol')
8729
+ timestamp = self.safe_integer_omit_zero(info, 'timestamp')
8730
+ longString = self.safe_string(info, 'buyRatio')
8731
+ shortString = self.safe_string(info, 'sellRatio')
8732
+ return {
8733
+ 'info': info,
8734
+ 'symbol': self.safe_symbol(marketId, market, None, 'contract'),
8735
+ 'timestamp': timestamp,
8736
+ 'datetime': self.iso8601(timestamp),
8737
+ 'timeframe': None,
8738
+ 'longShortRatio': self.parse_to_numeric(Precise.string_div(longString, shortString)),
8739
+ }
8740
+
8668
8741
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
8669
8742
  url = self.implode_hostname(self.urls['api'][api]) + '/' + path
8670
8743
  if api == 'public':