From 7b471d59c5da9f1456715f1d4c6eef2672f44e30 Mon Sep 17 00:00:00 2001 From: liuweiqing Date: Sat, 9 Nov 2024 18:23:27 +0800 Subject: [PATCH] chore: add warning when max_rank exceeds 250 in MarketCapPairList --- freqtrade/plugins/pairlist/MarketCapPairList.py | 8 ++++++-- tests/plugins/test_pairlist.py | 10 ++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/freqtrade/plugins/pairlist/MarketCapPairList.py b/freqtrade/plugins/pairlist/MarketCapPairList.py index b925d0b21..01a724529 100644 --- a/freqtrade/plugins/pairlist/MarketCapPairList.py +++ b/freqtrade/plugins/pairlist/MarketCapPairList.py @@ -6,6 +6,7 @@ Provides dynamic pair list based on Market Cap import logging import math +import warnings from cachetools import TTLCache @@ -57,8 +58,11 @@ class MarketCapPairList(IPairList): f"You can choose from {category_ids}" ) - if self._max_rank > 1000: - raise OperationalException("This filter only support marketcap rank up to 1000.") + if self._max_rank > 250: + self.logger.warning( + f"The max rank you have set ({self._max_rank}) is quite high. " + "Please ensure this value is appropriate for your use case.", + ) @property def needstickers(self) -> bool: diff --git a/tests/plugins/test_pairlist.py b/tests/plugins/test_pairlist.py index 0cb1df323..a4f66a702 100644 --- a/tests/plugins/test_pairlist.py +++ b/tests/plugins/test_pairlist.py @@ -2450,7 +2450,7 @@ def test_MarketCapPairList_filter_special_no_pair_from_coingecko( assert pm.whitelist == [] -def test_MarketCapPairList_exceptions(mocker, default_conf_usdt): +def test_MarketCapPairList_exceptions(mocker, default_conf_usdt, caplog): exchange = get_patched_exchange(mocker, default_conf_usdt) default_conf_usdt["pairlists"] = [{"method": "MarketCapPairList"}] with pytest.raises(OperationalException, match=r"`number_assets` not specified.*"): @@ -2458,13 +2458,11 @@ def test_MarketCapPairList_exceptions(mocker, default_conf_usdt): PairListManager(exchange, default_conf_usdt) default_conf_usdt["pairlists"] = [ - {"method": "MarketCapPairList", "number_assets": 20, "max_rank": 1010} + {"method": "MarketCapPairList", "number_assets": 20, "max_rank": 500} ] - with pytest.raises( - OperationalException, match="This filter only support marketcap rank up to 1000." - ): + with caplog.at_level(logging.WARNING): PairListManager(exchange, default_conf_usdt) - + assert log_has_re("The max rank you have set \\(500\\) is quite high", caplog) # Test invalid coinmarkets list mocker.patch( "freqtrade.plugins.pairlist.MarketCapPairList.FtCoinGeckoApi.get_coins_categories_list",