Fix PerformanceFilter failing in test-pairlist mode

This commit is contained in:
Matthias 2021-05-16 19:55:13 +02:00
parent 0d50e99563
commit 37b71b8cfd
2 changed files with 20 additions and 2 deletions

View File

@ -39,7 +39,12 @@ class PerformanceFilter(IPairList):
:return: new allowlist :return: new allowlist
""" """
# Get the trading performance for pairs from database # Get the trading performance for pairs from database
try:
performance = pd.DataFrame(Trade.get_overall_performance()) performance = pd.DataFrame(Trade.get_overall_performance())
except AttributeError:
# Performancefilter does not work in backtesting.
self.log_once("PerformanceFilter is not available in this mode.", logger.warning)
return pairlist
# Skip performance-based sorting if no performance data is available # Skip performance-based sorting if no performance data is available
if len(performance) == 0: if len(performance) == 0:

View File

@ -7,10 +7,11 @@ import pytest
from freqtrade.constants import AVAILABLE_PAIRLISTS from freqtrade.constants import AVAILABLE_PAIRLISTS
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.persistence import Trade
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.plugins.pairlistmanager import PairListManager from freqtrade.plugins.pairlistmanager import PairListManager
from freqtrade.resolvers import PairListResolver from freqtrade.resolvers import PairListResolver
from tests.conftest import get_patched_freqtradebot, log_has, log_has_re from tests.conftest import get_patched_exchange, get_patched_freqtradebot, log_has, log_has_re
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
@ -512,6 +513,18 @@ def test_PrecisionFilter_error(mocker, whitelist_conf) -> None:
PairListManager(MagicMock, whitelist_conf) PairListManager(MagicMock, whitelist_conf)
def test_PerformanceFilter_error(mocker, whitelist_conf, caplog) -> None:
whitelist_conf['pairlists'] = [{"method": "StaticPairList"}, {"method": "PerformanceFilter"}]
if hasattr(Trade, 'query'):
del Trade.query
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
exchange = get_patched_exchange(mocker, whitelist_conf)
pm = PairListManager(exchange, whitelist_conf)
pm.refresh_pairlist()
assert log_has("PerformanceFilter is not available in this mode.", caplog)
def test_gen_pair_whitelist_not_supported(mocker, default_conf, tickers) -> None: def test_gen_pair_whitelist_not_supported(mocker, default_conf, tickers) -> None:
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10}] default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10}]