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
ccxt/bybit.py CHANGED
@@ -6,7 +6,7 @@
6
6
  from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.bybit import ImplicitAPI
8
8
  import hashlib
9
- 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
9
+ 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
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import AuthenticationError
@@ -105,6 +105,8 @@ class bybit(Exchange, ImplicitAPI):
105
105
  'fetchLedger': True,
106
106
  'fetchLeverage': True,
107
107
  'fetchLeverageTiers': True,
108
+ 'fetchLongShortRatio': False,
109
+ 'fetchLongShortRatioHistory': True,
108
110
  'fetchMarginAdjustmentHistory': False,
109
111
  'fetchMarketLeverageTiers': True,
110
112
  'fetchMarkets': True,
@@ -384,6 +386,7 @@ class bybit(Exchange, ImplicitAPI):
384
386
  # spot leverage token
385
387
  'v5/spot-lever-token/order-record': 1, # 50/s => cost = 50 / 50 = 1
386
388
  # spot margin trade
389
+ 'v5/spot-margin-trade/interest-rate-history': 5,
387
390
  'v5/spot-margin-trade/state': 5,
388
391
  'v5/spot-cross-margin-trade/loan-info': 1, # 50/s => cost = 50 / 50 = 1
389
392
  'v5/spot-cross-margin-trade/account': 1, # 50/s => cost = 50 / 50 = 1
@@ -6775,12 +6778,22 @@ class bybit(Exchange, ImplicitAPI):
6775
6778
  # "timestamp": 1666734490778
6776
6779
  # }
6777
6780
  #
6781
+ # fetchBorrowRateHistory
6782
+ # {
6783
+ # "timestamp": 1721469600000,
6784
+ # "currency": "USDC",
6785
+ # "hourlyBorrowRate": "0.000014621596",
6786
+ # "vipLevel": "No VIP"
6787
+ # }
6788
+ #
6778
6789
  timestamp = self.safe_integer(info, 'timestamp')
6779
- currencyId = self.safe_string(info, 'coin')
6790
+ currencyId = self.safe_string_2(info, 'coin', 'currency')
6791
+ hourlyBorrowRate = self.safe_number(info, 'hourlyBorrowRate')
6792
+ period = 3600000 if (hourlyBorrowRate is not None) else 86400000 # 1h or 1d
6780
6793
  return {
6781
6794
  'currency': self.safe_currency_code(currencyId, currency),
6782
- 'rate': self.safe_number(info, 'interestRate'),
6783
- 'period': 86400000, # Daily
6795
+ 'rate': self.safe_number(info, 'interestRate', hourlyBorrowRate),
6796
+ 'period': period, # Daily
6784
6797
  'timestamp': timestamp,
6785
6798
  'datetime': self.iso8601(timestamp),
6786
6799
  'info': info,
@@ -6830,6 +6843,53 @@ class bybit(Exchange, ImplicitAPI):
6830
6843
  interest = self.parse_borrow_interests(rows, None)
6831
6844
  return self.filter_by_currency_since_limit(interest, code, since, limit)
6832
6845
 
6846
+ def fetch_borrow_rate_history(self, code: str, since: Int = None, limit: Int = None, params={}):
6847
+ """
6848
+ retrieves a history of a currencies borrow interest rate at specific time slots
6849
+ :see: https://bybit-exchange.github.io/docs/v5/spot-margin-uta/historical-interest
6850
+ :param str code: unified currency code
6851
+ :param int [since]: timestamp for the earliest borrow rate
6852
+ :param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` to retrieve
6853
+ :param dict [params]: extra parameters specific to the exchange API endpoint
6854
+ :param int [params.until]: the latest time in ms to fetch entries for
6855
+ :returns dict[]: an array of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
6856
+ """
6857
+ self.load_markets()
6858
+ currency = self.currency(code)
6859
+ request: dict = {
6860
+ 'currency': currency['id'],
6861
+ }
6862
+ if since is None:
6863
+ since = self.milliseconds() - 86400000 * 30 # last 30 days
6864
+ request['startTime'] = since
6865
+ endTime = self.safe_integer_2(params, 'until', 'endTime')
6866
+ params = self.omit(params, ['until'])
6867
+ if endTime is None:
6868
+ endTime = since + 86400000 * 30 # since + 30 days
6869
+ request['endTime'] = endTime
6870
+ response = self.privateGetV5SpotMarginTradeInterestRateHistory(self.extend(request, params))
6871
+ #
6872
+ # {
6873
+ # "retCode": 0,
6874
+ # "retMsg": "OK",
6875
+ # "result": {
6876
+ # "list": [
6877
+ # {
6878
+ # "timestamp": 1721469600000,
6879
+ # "currency": "USDC",
6880
+ # "hourlyBorrowRate": "0.000014621596",
6881
+ # "vipLevel": "No VIP"
6882
+ # }
6883
+ # ]
6884
+ # },
6885
+ # "retExtInfo": "{}",
6886
+ # "time": 1721899048991
6887
+ # }
6888
+ #
6889
+ data = self.safe_dict(response, 'result')
6890
+ rows = self.safe_list(data, 'list', [])
6891
+ return self.parse_borrow_rate_history(rows, code, since, limit)
6892
+
6833
6893
  def parse_borrow_interest(self, info: dict, market: Market = None):
6834
6894
  #
6835
6895
  # {
@@ -8606,6 +8666,77 @@ class bybit(Exchange, ImplicitAPI):
8606
8666
  'fee': None,
8607
8667
  }
8608
8668
 
8669
+ def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
8670
+ """
8671
+ fetches the long short ratio history for a unified market symbol
8672
+ :see: https://bybit-exchange.github.io/docs/v5/market/long-short-ratio
8673
+ :param str symbol: unified symbol of the market to fetch the long short ratio for
8674
+ :param str [timeframe]: the period for the ratio, default is 24 hours
8675
+ :param int [since]: the earliest time in ms to fetch ratios for
8676
+ :param int [limit]: the maximum number of long short ratio structures to retrieve
8677
+ :param dict [params]: extra parameters specific to the exchange API endpoint
8678
+ :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
8679
+ """
8680
+ self.load_markets()
8681
+ market = self.market(symbol)
8682
+ type = None
8683
+ type, params = self.get_bybit_type('fetchLongShortRatioHistory', market, params)
8684
+ if type == 'spot' or type == 'option':
8685
+ raise NotSupported(self.id + ' fetchLongShortRatioHistory() only support linear and inverse markets')
8686
+ if timeframe is None:
8687
+ timeframe = '1d'
8688
+ request: dict = {
8689
+ 'symbol': market['id'],
8690
+ 'period': timeframe,
8691
+ 'category': type,
8692
+ }
8693
+ if limit is not None:
8694
+ request['limit'] = limit
8695
+ response = self.publicGetV5MarketAccountRatio(self.extend(request, params))
8696
+ #
8697
+ # {
8698
+ # "retCode": 0,
8699
+ # "retMsg": "OK",
8700
+ # "result": {
8701
+ # "list": [
8702
+ # {
8703
+ # "symbol": "BTCUSDT",
8704
+ # "buyRatio": "0.5707",
8705
+ # "sellRatio": "0.4293",
8706
+ # "timestamp": "1729123200000"
8707
+ # },
8708
+ # ]
8709
+ # },
8710
+ # "retExtInfo": {},
8711
+ # "time": 1729147842516
8712
+ # }
8713
+ #
8714
+ result = self.safe_dict(response, 'result', {})
8715
+ data = self.safe_list(result, 'list', [])
8716
+ return self.parse_long_short_ratio_history(data, market)
8717
+
8718
+ def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
8719
+ #
8720
+ # {
8721
+ # "symbol": "BTCUSDT",
8722
+ # "buyRatio": "0.5707",
8723
+ # "sellRatio": "0.4293",
8724
+ # "timestamp": "1729123200000"
8725
+ # }
8726
+ #
8727
+ marketId = self.safe_string(info, 'symbol')
8728
+ timestamp = self.safe_integer_omit_zero(info, 'timestamp')
8729
+ longString = self.safe_string(info, 'buyRatio')
8730
+ shortString = self.safe_string(info, 'sellRatio')
8731
+ return {
8732
+ 'info': info,
8733
+ 'symbol': self.safe_symbol(marketId, market, None, 'contract'),
8734
+ 'timestamp': timestamp,
8735
+ 'datetime': self.iso8601(timestamp),
8736
+ 'timeframe': None,
8737
+ 'longShortRatio': self.parse_to_numeric(Precise.string_div(longString, shortString)),
8738
+ }
8739
+
8609
8740
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
8610
8741
  url = self.implode_hostname(self.urls['api'][api]) + '/' + path
8611
8742
  if api == 'public':