ccxt 4.4.21__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.
- ccxt/__init__.py +1 -1
- ccxt/abstract/bitflyer.py +1 -0
- ccxt/abstract/bitget.py +3 -0
- ccxt/abstract/cex.py +28 -29
- ccxt/abstract/gate.py +5 -0
- ccxt/abstract/gateio.py +5 -0
- ccxt/abstract/kucoin.py +1 -0
- ccxt/abstract/kucoinfutures.py +1 -0
- ccxt/abstract/okx.py +1 -0
- ccxt/alpaca.py +1 -0
- ccxt/async_support/__init__.py +1 -1
- ccxt/async_support/alpaca.py +1 -0
- ccxt/async_support/base/exchange.py +7 -1
- ccxt/async_support/bigone.py +3 -0
- ccxt/async_support/binance.py +96 -1
- ccxt/async_support/bitflyer.py +56 -1
- ccxt/async_support/bitget.py +73 -1
- ccxt/async_support/bybit.py +74 -1
- ccxt/async_support/cex.py +1247 -1326
- ccxt/async_support/cryptocom.py +1 -1
- ccxt/async_support/gate.py +97 -2
- ccxt/async_support/htx.py +1 -5
- ccxt/async_support/hyperliquid.py +10 -8
- ccxt/async_support/kucoin.py +27 -57
- ccxt/async_support/okx.py +67 -1
- ccxt/base/exchange.py +21 -1
- ccxt/base/types.py +9 -0
- ccxt/bigone.py +3 -0
- ccxt/binance.py +96 -1
- ccxt/bitflyer.py +56 -1
- ccxt/bitget.py +73 -1
- ccxt/bybit.py +74 -1
- ccxt/cex.py +1246 -1326
- ccxt/cryptocom.py +1 -1
- ccxt/gate.py +97 -2
- ccxt/htx.py +1 -5
- ccxt/hyperliquid.py +10 -8
- ccxt/kucoin.py +27 -57
- ccxt/okx.py +67 -1
- ccxt/pro/__init__.py +1 -1
- ccxt/test/tests_async.py +4 -4
- ccxt/test/tests_sync.py +4 -4
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/METADATA +5 -5
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/RECORD +47 -47
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/LICENSE.txt +0 -0
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/WHEEL +0 -0
- {ccxt-4.4.21.dist-info → ccxt-4.4.22.dist-info}/top_level.txt +0 -0
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,
|
@@ -12700,3 +12702,96 @@ class binance(Exchange, ImplicitAPI):
|
|
12700
12702
|
#
|
12701
12703
|
result = self.parse_funding_rates(response, market)
|
12702
12704
|
return self.filter_by_array(result, 'symbol', symbols)
|
12705
|
+
|
12706
|
+
def fetch_long_short_ratio_history(self, symbol: Str = None, timeframe: Str = None, since: Int = None, limit: Int = None, params={}) -> List[LongShortRatio]:
|
12707
|
+
"""
|
12708
|
+
fetches the long short ratio history for a unified market symbol
|
12709
|
+
:see: https://developers.binance.com/docs/derivatives/usds-margined-futures/market-data/rest-api/Long-Short-Ratio
|
12710
|
+
:see: https://developers.binance.com/docs/derivatives/coin-margined-futures/market-data/Long-Short-Ratio
|
12711
|
+
:param str symbol: unified symbol of the market to fetch the long short ratio for
|
12712
|
+
:param str [timeframe]: the period for the ratio, default is 24 hours
|
12713
|
+
:param int [since]: the earliest time in ms to fetch ratios for
|
12714
|
+
:param int [limit]: the maximum number of long short ratio structures to retrieve
|
12715
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
12716
|
+
:param int [params.until]: timestamp in ms of the latest ratio to fetch
|
12717
|
+
:returns dict[]: an array of `long short ratio structures <https://docs.ccxt.com/#/?id=long-short-ratio-structure>`
|
12718
|
+
"""
|
12719
|
+
self.load_markets()
|
12720
|
+
market = self.market(symbol)
|
12721
|
+
if timeframe is None:
|
12722
|
+
timeframe = '1d'
|
12723
|
+
request: dict = {
|
12724
|
+
'period': timeframe,
|
12725
|
+
}
|
12726
|
+
request, params = self.handle_until_option('endTime', request, params)
|
12727
|
+
if since is not None:
|
12728
|
+
request['startTime'] = since
|
12729
|
+
if limit is not None:
|
12730
|
+
request['limit'] = limit
|
12731
|
+
subType = None
|
12732
|
+
subType, params = self.handle_sub_type_and_params('fetchLongShortRatioHistory', market, params)
|
12733
|
+
response = None
|
12734
|
+
if subType == 'linear':
|
12735
|
+
request['symbol'] = market['id']
|
12736
|
+
response = self.fapiDataGetGlobalLongShortAccountRatio(self.extend(request, params))
|
12737
|
+
#
|
12738
|
+
# [
|
12739
|
+
# {
|
12740
|
+
# "symbol": "BTCUSDT",
|
12741
|
+
# "longAccount": "0.4558",
|
12742
|
+
# "longShortRatio": "0.8376",
|
12743
|
+
# "shortAccount": "0.5442",
|
12744
|
+
# "timestamp": 1726790400000
|
12745
|
+
# },
|
12746
|
+
# ]
|
12747
|
+
#
|
12748
|
+
elif subType == 'inverse':
|
12749
|
+
request['pair'] = market['info']['pair']
|
12750
|
+
response = self.dapiDataGetGlobalLongShortAccountRatio(self.extend(request, params))
|
12751
|
+
#
|
12752
|
+
# [
|
12753
|
+
# {
|
12754
|
+
# "longAccount": "0.7262",
|
12755
|
+
# "longShortRatio": "2.6523",
|
12756
|
+
# "shortAccount": "0.2738",
|
12757
|
+
# "pair": "BTCUSD",
|
12758
|
+
# "timestamp": 1726790400000
|
12759
|
+
# },
|
12760
|
+
# ]
|
12761
|
+
#
|
12762
|
+
else:
|
12763
|
+
raise BadRequest(self.id + ' fetchLongShortRatioHistory() supports linear and inverse subTypes only')
|
12764
|
+
return self.parse_long_short_ratio_history(response, market)
|
12765
|
+
|
12766
|
+
def parse_long_short_ratio(self, info: dict, market: Market = None) -> LongShortRatio:
|
12767
|
+
#
|
12768
|
+
# linear
|
12769
|
+
#
|
12770
|
+
# {
|
12771
|
+
# "symbol": "BTCUSDT",
|
12772
|
+
# "longAccount": "0.4558",
|
12773
|
+
# "longShortRatio": "0.8376",
|
12774
|
+
# "shortAccount": "0.5442",
|
12775
|
+
# "timestamp": 1726790400000
|
12776
|
+
# }
|
12777
|
+
#
|
12778
|
+
# inverse
|
12779
|
+
#
|
12780
|
+
# {
|
12781
|
+
# "longAccount": "0.7262",
|
12782
|
+
# "longShortRatio": "2.6523",
|
12783
|
+
# "shortAccount": "0.2738",
|
12784
|
+
# "pair": "BTCUSD",
|
12785
|
+
# "timestamp": 1726790400000
|
12786
|
+
# }
|
12787
|
+
#
|
12788
|
+
marketId = self.safe_string(info, 'symbol')
|
12789
|
+
timestamp = self.safe_integer_omit_zero(info, 'timestamp')
|
12790
|
+
return {
|
12791
|
+
'info': info,
|
12792
|
+
'symbol': self.safe_symbol(marketId, market, None, 'contract'),
|
12793
|
+
'timestamp': timestamp,
|
12794
|
+
'datetime': self.iso8601(timestamp),
|
12795
|
+
'timeframe': None,
|
12796
|
+
'longShortRatio': self.safe_number(info, 'longShortRatio'),
|
12797
|
+
}
|
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,8 @@ class bitflyer(Exchange, ImplicitAPI):
|
|
39
39
|
'fetchBalance': True,
|
40
40
|
'fetchClosedOrders': 'emulated',
|
41
41
|
'fetchDeposits': True,
|
42
|
+
'fetchFundingRate': True,
|
43
|
+
'fetchFundingRateHistory': False,
|
42
44
|
'fetchMarginMode': False,
|
43
45
|
'fetchMarkets': True,
|
44
46
|
'fetchMyTrades': True,
|
@@ -78,6 +80,7 @@ class bitflyer(Exchange, ImplicitAPI):
|
|
78
80
|
'gethealth',
|
79
81
|
'getboardstate',
|
80
82
|
'getchats',
|
83
|
+
'getfundingrate',
|
81
84
|
],
|
82
85
|
},
|
83
86
|
'private': {
|
@@ -963,6 +966,58 @@ class bitflyer(Exchange, ImplicitAPI):
|
|
963
966
|
'fee': fee,
|
964
967
|
}
|
965
968
|
|
969
|
+
def fetch_funding_rate(self, symbol: str, params={}) -> FundingRate:
|
970
|
+
"""
|
971
|
+
fetch the current funding rate
|
972
|
+
:see: https://lightning.bitflyer.com/docs#funding-rate
|
973
|
+
:param str symbol: unified market symbol
|
974
|
+
:param dict [params]: extra parameters specific to the exchange API endpoint
|
975
|
+
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
|
976
|
+
"""
|
977
|
+
self.load_markets()
|
978
|
+
market = self.market(symbol)
|
979
|
+
request: dict = {
|
980
|
+
'product_code': market['id'],
|
981
|
+
}
|
982
|
+
response = self.publicGetGetfundingrate(self.extend(request, params))
|
983
|
+
#
|
984
|
+
# {
|
985
|
+
# "current_funding_rate": -0.003750000000
|
986
|
+
# "next_funding_rate_settledate": "2024-04-15T13:00:00"
|
987
|
+
# }
|
988
|
+
#
|
989
|
+
return self.parse_funding_rate(response, market)
|
990
|
+
|
991
|
+
def parse_funding_rate(self, contract, market: Market = None) -> FundingRate:
|
992
|
+
#
|
993
|
+
# {
|
994
|
+
# "current_funding_rate": -0.003750000000
|
995
|
+
# "next_funding_rate_settledate": "2024-04-15T13:00:00"
|
996
|
+
# }
|
997
|
+
#
|
998
|
+
nextFundingDatetime = self.safe_string(contract, 'next_funding_rate_settledate')
|
999
|
+
nextFundingTimestamp = self.parse8601(nextFundingDatetime)
|
1000
|
+
return {
|
1001
|
+
'info': contract,
|
1002
|
+
'symbol': self.safe_string(market, 'symbol'),
|
1003
|
+
'markPrice': None,
|
1004
|
+
'indexPrice': None,
|
1005
|
+
'interestRate': None,
|
1006
|
+
'estimatedSettlePrice': None,
|
1007
|
+
'timestamp': None,
|
1008
|
+
'datetime': None,
|
1009
|
+
'fundingRate': None,
|
1010
|
+
'fundingTimestamp': None,
|
1011
|
+
'fundingDatetime': None,
|
1012
|
+
'nextFundingRate': self.safe_number(contract, 'current_funding_rate'),
|
1013
|
+
'nextFundingTimestamp': nextFundingTimestamp,
|
1014
|
+
'nextFundingDatetime': self.iso8601(nextFundingTimestamp),
|
1015
|
+
'previousFundingRate': None,
|
1016
|
+
'previousFundingTimestamp': None,
|
1017
|
+
'previousFundingDatetime': None,
|
1018
|
+
'interval': None,
|
1019
|
+
}
|
1020
|
+
|
966
1021
|
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
967
1022
|
request = '/' + self.version + '/'
|
968
1023
|
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/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,
|
@@ -8664,6 +8666,77 @@ class bybit(Exchange, ImplicitAPI):
|
|
8664
8666
|
'fee': None,
|
8665
8667
|
}
|
8666
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
|
+
|
8667
8740
|
def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
|
8668
8741
|
url = self.implode_hostname(self.urls['api'][api]) + '/' + path
|
8669
8742
|
if api == 'public':
|