chore: add warning when max_rank exceeds 250 in MarketCapPairList

This commit is contained in:
liuweiqing 2024-11-09 18:23:27 +08:00
parent 00318be59f
commit 7b471d59c5
2 changed files with 10 additions and 8 deletions

View File

@ -6,6 +6,7 @@ Provides dynamic pair list based on Market Cap
import logging import logging
import math import math
import warnings
from cachetools import TTLCache from cachetools import TTLCache
@ -57,8 +58,11 @@ class MarketCapPairList(IPairList):
f"You can choose from {category_ids}" f"You can choose from {category_ids}"
) )
if self._max_rank > 1000: if self._max_rank > 250:
raise OperationalException("This filter only support marketcap rank up to 1000.") 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 @property
def needstickers(self) -> bool: def needstickers(self) -> bool:

View File

@ -2450,7 +2450,7 @@ def test_MarketCapPairList_filter_special_no_pair_from_coingecko(
assert pm.whitelist == [] 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) exchange = get_patched_exchange(mocker, default_conf_usdt)
default_conf_usdt["pairlists"] = [{"method": "MarketCapPairList"}] default_conf_usdt["pairlists"] = [{"method": "MarketCapPairList"}]
with pytest.raises(OperationalException, match=r"`number_assets` not specified.*"): 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) PairListManager(exchange, default_conf_usdt)
default_conf_usdt["pairlists"] = [ default_conf_usdt["pairlists"] = [
{"method": "MarketCapPairList", "number_assets": 20, "max_rank": 1010} {"method": "MarketCapPairList", "number_assets": 20, "max_rank": 500}
] ]
with pytest.raises( with caplog.at_level(logging.WARNING):
OperationalException, match="This filter only support marketcap rank up to 1000."
):
PairListManager(exchange, default_conf_usdt) PairListManager(exchange, default_conf_usdt)
assert log_has_re("The max rank you have set \\(500\\) is quite high", caplog)
# Test invalid coinmarkets list # Test invalid coinmarkets list
mocker.patch( mocker.patch(
"freqtrade.plugins.pairlist.MarketCapPairList.FtCoinGeckoApi.get_coins_categories_list", "freqtrade.plugins.pairlist.MarketCapPairList.FtCoinGeckoApi.get_coins_categories_list",