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
ccxt/base/exchange.py CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # -----------------------------------------------------------------------------
6
6
 
7
- __version__ = '4.4.21'
7
+ __version__ = '4.4.23'
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
10
 
@@ -1910,6 +1910,8 @@ class Exchange(object):
1910
1910
  'fetchLeverages': None,
1911
1911
  'fetchLeverageTiers': None,
1912
1912
  'fetchLiquidations': None,
1913
+ 'fetchLongShortRatio': None,
1914
+ 'fetchLongShortRatioHistory': None,
1913
1915
  'fetchMarginMode': None,
1914
1916
  'fetchMarginModes': None,
1915
1917
  'fetchMarketLeverageTiers': None,
@@ -2621,6 +2623,12 @@ class Exchange(object):
2621
2623
  def set_margin(self, symbol: str, amount: float, params={}):
2622
2624
  raise NotSupported(self.id + ' setMargin() is not supported yet')
2623
2625
 
2626
+ def fetch_long_short_ratio(self, symbol: str, timeframe: Str = None, params={}):
2627
+ raise NotSupported(self.id + ' fetchLongShortRatio() is not supported yet')
2628
+
2629
+ def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}):
2630
+ raise NotSupported(self.id + ' fetchLongShortRatioHistory() is not supported yet')
2631
+
2624
2632
  def fetch_margin_adjustment_history(self, symbol: Str = None, type: Str = None, since: Num = None, limit: Num = None, params={}):
2625
2633
  """
2626
2634
  fetches the history of margin added or reduced from contract isolated positions
@@ -5489,6 +5497,18 @@ class Exchange(object):
5489
5497
  result[parsed['symbol']] = parsed
5490
5498
  return result
5491
5499
 
5500
+ def parse_long_short_ratio(self, info: dict, market: Market = None):
5501
+ raise NotSupported(self.id + ' parseLongShortRatio() is not supported yet')
5502
+
5503
+ def parse_long_short_ratio_history(self, response, market=None, since: Int = None, limit: Int = None):
5504
+ rates = []
5505
+ for i in range(0, len(response)):
5506
+ entry = response[i]
5507
+ rates.append(self.parse_long_short_ratio(entry, market))
5508
+ sorted = self.sort_by(rates, 'timestamp')
5509
+ symbol = None if (market is None) else market['symbol']
5510
+ return self.filter_by_symbol_since_limit(sorted, symbol, since, limit)
5511
+
5492
5512
  def handle_trigger_and_params(self, params):
5493
5513
  isTrigger = self.safe_bool_2(params, 'trigger', 'stop')
5494
5514
  if isTrigger:
ccxt/base/types.py CHANGED
@@ -533,6 +533,15 @@ class DepositAddress:
533
533
  tag: Optional[Str]
534
534
 
535
535
 
536
+ class LongShortRatio:
537
+ info: Any
538
+ symbol: Str
539
+ timestamp: Optional[Int]
540
+ datetime: Optional[Str]
541
+ timeframe: Optional[Str]
542
+ longShortRatio: float
543
+
544
+
536
545
  FundingRates = Dict[Str, FundingRate]
537
546
  LastPrices = Dict[Str, LastPrice]
538
547
  Currencies = Dict[Str, CurrencyInterface]
ccxt/bigone.py CHANGED
@@ -54,7 +54,10 @@ class bigone(Exchange, ImplicitAPI):
54
54
  'fetchDepositAddresses': False,
55
55
  'fetchDepositAddressesByNetwork': False,
56
56
  'fetchDeposits': True,
57
+ 'fetchFundingHistory': False,
57
58
  'fetchFundingRate': False,
59
+ 'fetchFundingRateHistory': False,
60
+ 'fetchFundingRates': False,
58
61
  'fetchMarkets': True,
59
62
  'fetchMyTrades': True,
60
63
  'fetchOHLCV': True,
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, Conversion, CrossBorrowRate, Currencies, Currency, DepositAddress, Greeks, Int, IsolatedBorrowRate, IsolatedBorrowRates, LedgerEntry, Leverage, Leverages, LeverageTier, LeverageTiers, MarginMode, MarginModes, MarginModification, Market, MarketInterface, Num, Option, Order, OrderBook, OrderRequest, OrderSide, OrderType, 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, IsolatedBorrowRate, IsolatedBorrowRates, LedgerEntry, Leverage, Leverages, LeverageTier, LeverageTiers, MarginMode, MarginModes, MarginModification, Market, MarketInterface, Num, Option, Order, OrderBook, OrderRequest, OrderSide, OrderType, 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
@@ -128,6 +128,8 @@ class binance(Exchange, ImplicitAPI):
128
128
  'fetchLeverages': True,
129
129
  'fetchLeverageTiers': True,
130
130
  'fetchLiquidations': False,
131
+ 'fetchLongShortRatio': False,
132
+ 'fetchLongShortRatioHistory': True,
131
133
  'fetchMarginAdjustmentHistory': True,
132
134
  'fetchMarginMode': 'emulated',
133
135
  'fetchMarginModes': True,
@@ -492,6 +494,7 @@ class binance(Exchange, ImplicitAPI):
492
494
  'portfolio/asset-index-price': 0.1,
493
495
  'portfolio/repay-futures-switch': 3, # Weight(IP): 30 => cost = 0.1 * 30 = 3
494
496
  'portfolio/margin-asset-leverage': 5, # Weight(IP): 50 => cost = 0.1 * 50 = 5
497
+ 'portfolio/balance': 2,
495
498
  # staking
496
499
  'staking/productList': 0.1,
497
500
  'staking/position': 0.1,
@@ -694,6 +697,7 @@ class binance(Exchange, ImplicitAPI):
694
697
  'loan/flexible/ltv/adjustment/history': 40, # Weight(IP): 400 => cost = 0.1 * 400 = 40
695
698
  'loan/flexible/loanable/data': 40, # Weight(IP): 400 => cost = 0.1 * 400 = 40
696
699
  'loan/flexible/collateral/data': 40, # Weight(IP): 400 => cost = 0.1 * 400 = 40
700
+ 'portfolio/account': 2,
697
701
  },
698
702
  'post': {
699
703
  'eth-staking/eth/stake': 15, # Weight(IP): 150 => cost = 0.1 * 150 = 15
@@ -771,6 +775,10 @@ class binance(Exchange, ImplicitAPI):
771
775
  'commissionRate': 20,
772
776
  'income/asyn': 5,
773
777
  'income/asyn/id': 5,
778
+ 'trade/asyn': 0.5,
779
+ 'trade/asyn/id': 0.5,
780
+ 'order/asyn': 0.5,
781
+ 'order/asyn/id': 0.5,
774
782
  'pmExchangeInfo': 0.5, # Weight(IP): 5 => cost = 0.1 * 5 = 0.5
775
783
  'pmAccountInfo': 0.5, # Weight(IP): 5 => cost = 0.1 * 5 = 0.5
776
784
  },
@@ -1049,99 +1057,118 @@ class binance(Exchange, ImplicitAPI):
1049
1057
  },
1050
1058
  },
1051
1059
  'papi': {
1060
+ # IP(papi) request rate limit of 6000 per minute
1061
+ # 1 IP(papi) => cost = 0.2 =>(1000 / (50 * 0.2)) * 60 = 6000
1062
+ # Order(papi) request rate limit of 1200 per minute
1063
+ # 1 Order(papi) => cost = 1 =>(1000 / (50 * 1)) * 60 = 1200
1052
1064
  'get': {
1053
- 'ping': 1,
1054
- 'um/order': 1, # 1
1055
- 'um/openOrder': 1, # 1
1065
+ 'ping': 0.2,
1066
+ 'um/order': 1,
1067
+ 'um/openOrder': 1,
1056
1068
  'um/openOrders': {'cost': 1, 'noSymbol': 40},
1057
- 'um/allOrders': 5, # 5
1058
- 'cm/order': 1, # 1
1059
- 'cm/openOrder': 1, # 1
1069
+ 'um/allOrders': 5,
1070
+ 'cm/order': 1,
1071
+ 'cm/openOrder': 1,
1060
1072
  'cm/openOrders': {'cost': 1, 'noSymbol': 40},
1061
- 'cm/allOrders': 20, # 20
1073
+ 'cm/allOrders': 20,
1062
1074
  'um/conditional/openOrder': 1,
1063
1075
  'um/conditional/openOrders': {'cost': 1, 'noSymbol': 40},
1064
1076
  'um/conditional/orderHistory': 1,
1065
- 'um/conditional/allOrders': 40,
1077
+ 'um/conditional/allOrders': {'cost': 1, 'noSymbol': 40},
1066
1078
  'cm/conditional/openOrder': 1,
1067
1079
  'cm/conditional/openOrders': {'cost': 1, 'noSymbol': 40},
1068
1080
  'cm/conditional/orderHistory': 1,
1069
1081
  'cm/conditional/allOrders': 40,
1070
- 'margin/order': 5,
1082
+ 'margin/order': 10,
1071
1083
  'margin/openOrders': 5,
1072
1084
  'margin/allOrders': 100,
1073
1085
  'margin/orderList': 5,
1074
1086
  'margin/allOrderList': 100,
1075
1087
  'margin/openOrderList': 5,
1076
1088
  'margin/myTrades': 5,
1077
- 'balance': 20, # 20
1078
- 'account': 20, # 20
1079
- 'margin/maxBorrowable': 5, # 5
1080
- 'margin/maxWithdraw': 5, # 5
1081
- 'um/positionRisk': 5, # 5
1082
- 'cm/positionRisk': 1, # 1
1083
- 'um/positionSide/dual': 30, # 30
1084
- 'cm/positionSide/dual': 30, # 30
1085
- 'um/userTrades': 5, # 5
1086
- 'cm/userTrades': 20, # 20
1087
- 'um/leverageBracket': 1, # 1
1088
- 'cm/leverageBracket': 1, # 1
1089
- 'margin/forceOrders': 1, # 1
1090
- 'um/forceOrders': 20, # 20
1091
- 'cm/forceOrders': 20, # 20
1092
- 'um/apiTradingStatus': 1, # 1
1093
- 'um/commissionRate': 20, # 20
1094
- 'cm/commissionRate': 20, # 20
1095
- 'margin/marginLoan': 10,
1096
- 'margin/repayLoan': 10,
1097
- 'margin/marginInterestHistory': 1,
1098
- 'portfolio/interest-history': 50, # 50
1099
- 'um/income': 30,
1100
- 'cm/income': 30,
1101
- 'um/account': 5,
1102
- 'cm/account': 5,
1103
- 'repay-futures-switch': 3, # Weight(IP): 30 => cost = 0.1 * 30 = 3
1089
+ 'balance': 4,
1090
+ 'account': 4,
1091
+ 'margin/maxBorrowable': 1,
1092
+ 'margin/maxWithdraw': 1,
1093
+ 'um/positionRisk': 1,
1094
+ 'cm/positionRisk': 0.2,
1095
+ 'um/positionSide/dual': 6,
1096
+ 'cm/positionSide/dual': 6,
1097
+ 'um/userTrades': 5,
1098
+ 'cm/userTrades': 20,
1099
+ 'um/leverageBracket': 0.2,
1100
+ 'cm/leverageBracket': 0.2,
1101
+ 'margin/forceOrders': 1,
1102
+ 'um/forceOrders': {'cost': 20, 'noSymbol': 50},
1103
+ 'cm/forceOrders': {'cost': 20, 'noSymbol': 50},
1104
+ 'um/apiTradingStatus': {'cost': 0.2, 'noSymbol': 2},
1105
+ 'um/commissionRate': 4,
1106
+ 'cm/commissionRate': 4,
1107
+ 'margin/marginLoan': 2,
1108
+ 'margin/repayLoan': 2,
1109
+ 'margin/marginInterestHistory': 0.2,
1110
+ 'portfolio/interest-history': 10,
1111
+ 'um/income': 6,
1112
+ 'cm/income': 6,
1113
+ 'um/account': 1,
1114
+ 'cm/account': 1,
1115
+ 'repay-futures-switch': 6,
1104
1116
  'um/adlQuantile': 5,
1105
1117
  'cm/adlQuantile': 5,
1118
+ 'um/trade/asyn': 300,
1119
+ 'um/trade/asyn/id': 2,
1120
+ 'um/order/asyn/': 300,
1121
+ 'um/order/asyn/id': 2,
1122
+ 'um/income/asyn': 300,
1123
+ 'um/income/asyn/id': 2,
1124
+ 'um/orderAmendment': 1,
1125
+ 'cm/orderAmendment': 1,
1126
+ 'um/feeBurn': 30,
1127
+ 'um/accountConfig': 1,
1128
+ 'um/symbolConfig': 1,
1129
+ 'cm/accountConfig': 1,
1130
+ 'cm/symbolConfig': 1,
1106
1131
  },
1107
1132
  'post': {
1108
- 'um/order': 1, # 0
1133
+ 'um/order': 1,
1109
1134
  'um/conditional/order': 1,
1110
- 'cm/order': 1, # 0
1135
+ 'cm/order': 1,
1111
1136
  'cm/conditional/order': 1,
1112
- 'margin/order': 0.0133, # Weight(UID): 2 => cost = 0.006667 * 2 = 0.013334
1113
- 'marginLoan': 0.1333, # Weight(UID): 20 => cost = 0.006667 * 20 = 0.13334
1114
- 'repayLoan': 0.1333, # Weight(UID): 20 => cost = 0.006667 * 20 = 0.13334
1115
- 'margin/order/oco': 0.0400, # Weight(UID): 6 => cost = 0.006667 * 6 = 0.040002
1116
- 'um/leverage': 1, # 1
1117
- 'cm/leverage': 1, # 1
1118
- 'um/positionSide/dual': 1, # 1
1119
- 'cm/positionSide/dual': 1, # 1
1120
- 'auto-collection': 0.6667, # Weight(UID): 100 => cost = 0.006667 * 100 = 0.6667
1121
- 'bnb-transfer': 0.6667, # Weight(UID): 100 => cost = 0.006667 * 100 = 0.6667
1122
- 'repay-futures-switch': 150, # Weight(IP): 1500 => cost = 0.1 * 1500 = 150
1123
- 'repay-futures-negative-balance': 150, # Weight(IP): 1500 => cost = 0.1 * 1500 = 150
1124
- 'listenKey': 1, # 1
1125
- 'asset-collection': 3,
1126
- 'margin/repay-debt': 0.4, # Weight(Order): 0.4 =>(1000 / (50 * 0.4)) * 60 = 3000
1137
+ 'margin/order': 1,
1138
+ 'marginLoan': 100,
1139
+ 'repayLoan': 100,
1140
+ 'margin/order/oco': 1,
1141
+ 'um/leverage': 0.2,
1142
+ 'cm/leverage': 0.2,
1143
+ 'um/positionSide/dual': 0.2,
1144
+ 'cm/positionSide/dual': 0.2,
1145
+ 'auto-collection': 150,
1146
+ 'bnb-transfer': 150,
1147
+ 'repay-futures-switch': 150,
1148
+ 'repay-futures-negative-balance': 150,
1149
+ 'listenKey': 0.2,
1150
+ 'asset-collection': 6,
1151
+ 'margin/repay-debt': 3000,
1127
1152
  'um/feeBurn': 1,
1128
1153
  },
1129
1154
  'put': {
1130
- 'listenKey': 1, # 1
1155
+ 'listenKey': 0.2,
1156
+ 'um/order': 1,
1157
+ 'cm/order': 1,
1131
1158
  },
1132
1159
  'delete': {
1133
- 'um/order': 1, # 1
1160
+ 'um/order': 1,
1134
1161
  'um/conditional/order': 1,
1135
- 'um/allOpenOrders': 1, # 1
1162
+ 'um/allOpenOrders': 1,
1136
1163
  'um/conditional/allOpenOrders': 1,
1137
- 'cm/order': 1, # 1
1164
+ 'cm/order': 1,
1138
1165
  'cm/conditional/order': 1,
1139
- 'cm/allOpenOrders': 1, # 1
1166
+ 'cm/allOpenOrders': 1,
1140
1167
  'cm/conditional/allOpenOrders': 1,
1141
- 'margin/order': 1, # Weight(IP): 10 => cost = 0.1 * 10 = 1
1142
- 'margin/allOpenOrders': 5, # 5
1143
- 'margin/orderList': 2, # 2
1144
- 'listenKey': 1, # 1
1168
+ 'margin/order': 2,
1169
+ 'margin/allOpenOrders': 5,
1170
+ 'margin/orderList': 2,
1171
+ 'listenKey': 0.2,
1145
1172
  },
1146
1173
  },
1147
1174
  },
@@ -12700,3 +12727,96 @@ class binance(Exchange, ImplicitAPI):
12700
12727
  #
12701
12728
  result = self.parse_funding_rates(response, market)
12702
12729
  return self.filter_by_array(result, 'symbol', symbols)
12730
+
12731
+ def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
12732
+ """
12733
+ fetches the long short ratio history for a unified market symbol
12734
+ :see: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio
12735
+ :see: https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Long-Short-Ratio
12736
+ :param str symbol: unified symbol of the market to fetch the long short ratio for
12737
+ :param str [timeframe]: the period for the ratio, default is 24 hours
12738
+ :param int [since]: the earliest time in ms to fetch ratios for
12739
+ :param int [limit]: the maximum number of long short ratio structures to retrieve
12740
+ :param dict [params]: extra parameters specific to the exchange API endpoint
12741
+ :param int [params.until]: timestamp in ms of the latest ratio to fetch
12742
+ :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
12743
+ """
12744
+ self.load_markets()
12745
+ market = self.market(symbol)
12746
+ if timeframe is None:
12747
+ timeframe = '1d'
12748
+ request: dict = {
12749
+ 'period': timeframe,
12750
+ }
12751
+ request, params = self.handle_until_option('endTime', request, params)
12752
+ if since is not None:
12753
+ request['startTime'] = since
12754
+ if limit is not None:
12755
+ request['limit'] = limit
12756
+ subType = None
12757
+ subType, params = self.handle_sub_type_and_params('fetchLongShortRatioHistory', market, params)
12758
+ response = None
12759
+ if subType == 'linear':
12760
+ request['symbol'] = market['id']
12761
+ response = self.fapiDataGetGlobalLongShortAccountRatio(self.extend(request, params))
12762
+ #
12763
+ # [
12764
+ # {
12765
+ # "symbol": "BTCUSDT",
12766
+ # "longAccount": "0.4558",
12767
+ # "longShortRatio": "0.8376",
12768
+ # "shortAccount": "0.5442",
12769
+ # "timestamp": 1726790400000
12770
+ # },
12771
+ # ]
12772
+ #
12773
+ elif subType == 'inverse':
12774
+ request['pair'] = market['info']['pair']
12775
+ response = self.dapiDataGetGlobalLongShortAccountRatio(self.extend(request, params))
12776
+ #
12777
+ # [
12778
+ # {
12779
+ # "longAccount": "0.7262",
12780
+ # "longShortRatio": "2.6523",
12781
+ # "shortAccount": "0.2738",
12782
+ # "pair": "BTCUSD",
12783
+ # "timestamp": 1726790400000
12784
+ # },
12785
+ # ]
12786
+ #
12787
+ else:
12788
+ raise BadRequest(self.id + ' fetchLongShortRatioHistory() supports linear and inverse subTypes only')
12789
+ return self.parse_long_short_ratio_history(response, market)
12790
+
12791
+ def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
12792
+ #
12793
+ # linear
12794
+ #
12795
+ # {
12796
+ # "symbol": "BTCUSDT",
12797
+ # "longAccount": "0.4558",
12798
+ # "longShortRatio": "0.8376",
12799
+ # "shortAccount": "0.5442",
12800
+ # "timestamp": 1726790400000
12801
+ # }
12802
+ #
12803
+ # inverse
12804
+ #
12805
+ # {
12806
+ # "longAccount": "0.7262",
12807
+ # "longShortRatio": "2.6523",
12808
+ # "shortAccount": "0.2738",
12809
+ # "pair": "BTCUSD",
12810
+ # "timestamp": 1726790400000
12811
+ # }
12812
+ #
12813
+ marketId = self.safe_string(info, 'symbol')
12814
+ timestamp = self.safe_integer_omit_zero(info, 'timestamp')
12815
+ return {
12816
+ 'info': info,
12817
+ 'symbol': self.safe_symbol(marketId, market, None, 'contract'),
12818
+ 'timestamp': timestamp,
12819
+ 'datetime': self.iso8601(timestamp),
12820
+ 'timeframe': None,
12821
+ 'longShortRatio': self.safe_number(info, 'longShortRatio'),
12822
+ }
ccxt/bitfinex.py CHANGED
@@ -60,6 +60,10 @@ class bitfinex(Exchange, ImplicitAPI):
60
60
  'fetchDepositsWithdrawals': True,
61
61
  'fetchDepositWithdrawFee': 'emulated',
62
62
  'fetchDepositWithdrawFees': True,
63
+ 'fetchFundingHistory': False,
64
+ 'fetchFundingRate': False, # Endpoint 'lendbook/{currency}' is related to interest rates on spot margin lending
65
+ 'fetchFundingRateHistory': False,
66
+ 'fetchFundingRates': False,
63
67
  'fetchIndexOHLCV': False,
64
68
  'fetchLeverageTiers': False,
65
69
  'fetchMarginMode': False,
ccxt/bitflyer.py CHANGED
@@ -6,7 +6,7 @@
6
6
  from ccxt.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
+ 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
+ self.load_markets()
979
+ market = self.market(symbol)
980
+ request: dict = {
981
+ 'product_code': market['id'],
982
+ }
983
+ response = 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':
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, 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
10
+ 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
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import AuthenticationError
@@ -113,6 +113,8 @@ class bitget(Exchange, ImplicitAPI):
113
113
  'fetchLeverage': True,
114
114
  'fetchLeverageTiers': False,
115
115
  'fetchLiquidations': False,
116
+ 'fetchLongShortRatio': False,
117
+ 'fetchLongShortRatioHistory': True,
116
118
  'fetchMarginAdjustmentHistory': False,
117
119
  'fetchMarginMode': True,
118
120
  'fetchMarketLeverageTiers': True,
@@ -288,6 +290,7 @@ class bitget(Exchange, ImplicitAPI):
288
290
  'v2/mix/market/current-fund-rate': 1,
289
291
  'v2/mix/market/contracts': 1,
290
292
  'v2/mix/market/query-position-lever': 2,
293
+ 'v2/mix/market/account-long-short': 20,
291
294
  },
292
295
  },
293
296
  'margin': {
@@ -298,6 +301,7 @@ class bitget(Exchange, ImplicitAPI):
298
301
  'margin/v1/isolated/public/tierData': 2, # 10 times/1s(IP) => 20/10 = 2
299
302
  'margin/v1/public/currencies': 1, # 20 times/1s(IP) => 20/20 = 1
300
303
  'v2/margin/currencies': 2,
304
+ 'v2/margin/market/long-short-ratio': 20,
301
305
  },
302
306
  },
303
307
  'earn': {
@@ -460,6 +464,7 @@ class bitget(Exchange, ImplicitAPI):
460
464
  'v2/mix/order/orders-history': 2,
461
465
  'v2/mix/order/orders-plan-pending': 2,
462
466
  'v2/mix/order/orders-plan-history': 2,
467
+ 'v2/mix/market/position-long-short': 20,
463
468
  },
464
469
  'post': {
465
470
  'mix/v1/account/sub-account-contract-assets': 200, # 0.1 times/1s(UID) => 20/0.1 = 200
@@ -8272,6 +8277,73 @@ class bitget(Exchange, ImplicitAPI):
8272
8277
  first = self.safe_dict(data, 0, {})
8273
8278
  return self.parse_funding_rate(first, market)
8274
8279
 
8280
+ def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
8281
+ """
8282
+ fetches the long short ratio history for a unified market symbol
8283
+ :see: https://www.bitget.com/api-doc/common/apidata/Margin-Ls-Ratio
8284
+ :see: https://www.bitget.com/api-doc/common/apidata/Account-Long-Short
8285
+ :param str symbol: unified symbol of the market to fetch the long short ratio for
8286
+ :param str [timeframe]: the period for the ratio
8287
+ :param int [since]: the earliest time in ms to fetch ratios for
8288
+ :param int [limit]: the maximum number of long short ratio structures to retrieve
8289
+ :param dict [params]: extra parameters specific to the exchange API endpoint
8290
+ :returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
8291
+ """
8292
+ self.load_markets()
8293
+ market = self.market(symbol)
8294
+ request: dict = {
8295
+ 'symbol': market['id'],
8296
+ }
8297
+ if timeframe is not None:
8298
+ request['period'] = timeframe
8299
+ response = None
8300
+ if market['swap'] or market['future']:
8301
+ response = self.publicMixGetV2MixMarketAccountLongShort(self.extend(request, params))
8302
+ #
8303
+ # {
8304
+ # "code": "00000",
8305
+ # "msg": "success",
8306
+ # "requestTime": 1729321233281,
8307
+ # "data": [
8308
+ # {
8309
+ # "longAccountRatio": "0.58",
8310
+ # "shortAccountRatio": "0.42",
8311
+ # "longShortAccountRatio": "0.0138",
8312
+ # "ts": "1729312200000"
8313
+ # },
8314
+ # ]
8315
+ # }
8316
+ #
8317
+ else:
8318
+ response = self.publicMarginGetV2MarginMarketLongShortRatio(self.extend(request, params))
8319
+ #
8320
+ # {
8321
+ # "code": "00000",
8322
+ # "msg": "success",
8323
+ # "requestTime": 1729306974712,
8324
+ # "data": [
8325
+ # {
8326
+ # "longShortRatio": "40.66",
8327
+ # "ts": "1729306800000"
8328
+ # },
8329
+ # ]
8330
+ # }
8331
+ #
8332
+ data = self.safe_list(response, 'data', [])
8333
+ return self.parse_long_short_ratio_history(data, market)
8334
+
8335
+ def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
8336
+ marketId = self.safe_string(info, 'symbol')
8337
+ timestamp = self.safe_integer_omit_zero(info, 'ts')
8338
+ return {
8339
+ 'info': info,
8340
+ 'symbol': self.safe_symbol(marketId, market, None, 'contract'),
8341
+ 'timestamp': timestamp,
8342
+ 'datetime': self.iso8601(timestamp),
8343
+ 'timeframe': None,
8344
+ 'longShortRatio': self.safe_number_2(info, 'longShortRatio', 'longShortAccountRatio'),
8345
+ }
8346
+
8275
8347
  def handle_errors(self, code: int, reason: str, url: str, method: str, headers: dict, body: str, response, requestHeaders, requestBody):
8276
8348
  if not response:
8277
8349
  return None # fallback to default error handler
ccxt/bitrue.py CHANGED
@@ -72,7 +72,10 @@ class bitrue(Exchange, ImplicitAPI):
72
72
  'fetchDepositsWithdrawals': False,
73
73
  'fetchDepositWithdrawFee': 'emulated',
74
74
  'fetchDepositWithdrawFees': True,
75
+ 'fetchFundingHistory': False,
75
76
  'fetchFundingRate': False,
77
+ 'fetchFundingRateHistory': False,
78
+ 'fetchFundingRates': False,
76
79
  'fetchIsolatedBorrowRate': False,
77
80
  'fetchIsolatedBorrowRates': False,
78
81
  'fetchMarginMode': False,