Skip to content

Commit

Permalink
Fix PerformanceFilter failing in test-pairlist mode
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed May 16, 2021
1 parent 0d50e99 commit 37b71b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion freqtrade/plugins/pairlist/PerformanceFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:
:return: new allowlist
"""
# Get the trading performance for pairs from database
performance = pd.DataFrame(Trade.get_overall_performance())
try:
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
if len(performance) == 0:
Expand Down
15 changes: 14 additions & 1 deletion tests/plugins/test_pairlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

from freqtrade.constants import AVAILABLE_PAIRLISTS
from freqtrade.exceptions import OperationalException
from freqtrade.persistence import Trade
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.plugins.pairlistmanager import PairListManager
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")
Expand Down Expand Up @@ -512,6 +513,18 @@ def test_PrecisionFilter_error(mocker, whitelist_conf) -> None:
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:
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10}]

Expand Down

0 comments on commit 37b71b8

Please sign in to comment.