From 4d7f3e570b18d1927ad00514088616c84c627ad7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 26 Jan 2021 17:15:47 +0100 Subject: [PATCH] Add test for spreadfilter division exception --- tests/plugins/test_pairlist.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/plugins/test_pairlist.py b/tests/plugins/test_pairlist.py index d62230e76..fda2b1409 100644 --- a/tests/plugins/test_pairlist.py +++ b/tests/plugins/test_pairlist.py @@ -719,6 +719,32 @@ def test_rangestabilityfilter_caching(mocker, markets, default_conf, tickers, oh assert freqtrade.exchange.refresh_latest_ohlcv.call_count == previous_call_count +def test_spreadfilter_invalid_data(mocker, default_conf, markets, tickers, caplog): + default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10}, + {'method': 'SpreadFilter', 'max_spread_ratio': 0.1}] + + mocker.patch.multiple('freqtrade.exchange.Exchange', + markets=PropertyMock(return_value=markets), + exchange_has=MagicMock(return_value=True), + get_tickers=tickers + ) + + ftbot = get_patched_freqtradebot(mocker, default_conf) + ftbot.pairlists.refresh_pairlist() + + assert len(ftbot.pairlists.whitelist) == 5 + + tickers.return_value['ETH/BTC']['ask'] = 0.0 + del tickers.return_value['TKN/BTC'] + del tickers.return_value['LTC/BTC'] + mocker.patch.multiple('freqtrade.exchange.Exchange', get_tickers=tickers) + + ftbot.pairlists.refresh_pairlist() + assert log_has_re(r'Removed .* invalid ticker data.*', caplog) + + assert len(ftbot.pairlists.whitelist) == 2 + + @pytest.mark.parametrize("pairlistconfig,desc_expected,exception_expected", [ ({"method": "PriceFilter", "low_price_ratio": 0.001, "min_price": 0.00000010, "max_price": 1.0},