diff --git a/freqtrade/exchange/bybit.py b/freqtrade/exchange/bybit.py index 1f810cf1f..c8b05d1de 100644 --- a/freqtrade/exchange/bybit.py +++ b/freqtrade/exchange/bybit.py @@ -250,38 +250,19 @@ class Bybit(Exchange): @retrier def get_leverage_tiers(self) -> Dict[str, List[Dict]]: """ - Temporary workaround for https://github.com/freqtrade/freqtrade/issues/10196 - should be removed or updated once https://github.com/ccxt/ccxt/issues/22448 is fixed. + Cache leverage tiers for 1 day, since they are not expected to change often, and + bybit requires pagination to fetch all tiers. """ # Load cached tiers - tiers_cached = self.load_cached_leverage_tiers(self._config["stake_currency"]) + tiers_cached = self.load_cached_leverage_tiers( + self._config["stake_currency"], timedelta(days=1) + ) if tiers_cached: - tiers = tiers_cached - return tiers + return tiers_cached # Fetch tiers from exchange - - symbols = self._api.market_symbols([]) - - def parse_resp(response): - result = self._api.safe_dict(response, "result", {}) - data = self._api.safe_list(result, "list", []) - return self._api.parse_leverage_tiers(data, symbols, "symbol") - - params = { - "category": "linear", - } - tiers = {} - # 20 pairs ... should be sufficient assuming 30 pairs per page - # Aimed to avoid a potential infinite loop - for _ in range(20): - # Fetch from private endpoint - response = self._api.publicGetV5MarketRiskLimit(params) - tiers = tiers | parse_resp(response) - if (cursor := response["result"]["nextPageCursor"]) == "": - break - params.update({"cursor": cursor}) + tiers = super().get_leverage_tiers() self.cache_leverage_tiers(tiers, self._config["stake_currency"]) return tiers