Improve tests of volatilityfilter

This commit is contained in:
Matthias 2020-11-21 16:01:52 +01:00
parent f8fab5c4f8
commit 2e1551a2eb
3 changed files with 36 additions and 3 deletions

View File

@ -138,7 +138,7 @@ If volatility over the last 10 days is <1%, remove the pair from the whitelist.
``` ```
!!! Tip !!! Tip
This Filter can be used to automatically remove stable coin pairs, which have a very low volatility, and are therefore extremely hard to trade with profit. This Filter can be used to automatically remove stable coin pairs, which have a very low volatility, and are therefore extremely difficult to trade with profit.
### Full example of Pairlist Handlers ### Full example of Pairlist Handlers

View File

@ -31,8 +31,8 @@ class VolatilityFilter(IPairList):
if self._days < 1: if self._days < 1:
raise OperationalException("VolatilityFilter requires volatility_over_days to be >= 1") raise OperationalException("VolatilityFilter requires volatility_over_days to be >= 1")
if self._days > exchange.ohlcv_candle_limit: if self._days > exchange.ohlcv_candle_limit:
raise OperationalException("VolatilityFilter requires volatility_over_days to not exceed " raise OperationalException("VolatilityFilter requires volatility_over_days to not "
"exchange max request size " "exceed exchange max request size "
f"({exchange.ohlcv_candle_limit})") f"({exchange.ohlcv_candle_limit})")
@property @property

View File

@ -609,6 +609,39 @@ def test_volatilityfilter_checks(mocker, default_conf, markets, tickers):
get_patched_freqtradebot(mocker, default_conf) get_patched_freqtradebot(mocker, default_conf)
@pytest.mark.parametrize('min_volatility,expected_length', [
(0.01, 5),
(0.05, 0), # Setting volatility to 5% removes all pairs from the whitelist.
])
def test_volatilityfilter_caching(mocker, markets, default_conf, tickers, ohlcv_history_list,
min_volatility, expected_length):
default_conf['pairlists'] = [{'method': 'VolumePairList', 'number_assets': 10},
{'method': 'VolatilityFilter', 'volatility_over_days': 2,
'min_volatility': min_volatility}]
mocker.patch.multiple('freqtrade.exchange.Exchange',
markets=PropertyMock(return_value=markets),
exchange_has=MagicMock(return_value=True),
get_tickers=tickers
)
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
get_historic_ohlcv=MagicMock(return_value=ohlcv_history_list),
)
freqtrade = get_patched_freqtradebot(mocker, default_conf)
assert freqtrade.exchange.get_historic_ohlcv.call_count == 0
freqtrade.pairlists.refresh_pairlist()
assert len(freqtrade.pairlists.whitelist) == expected_length
assert freqtrade.exchange.get_historic_ohlcv.call_count > 0
previous_call_count = freqtrade.exchange.get_historic_ohlcv.call_count
freqtrade.pairlists.refresh_pairlist()
assert len(freqtrade.pairlists.whitelist) == expected_length
# Should not have increased since first call.
assert freqtrade.exchange.get_historic_ohlcv.call_count == previous_call_count
@pytest.mark.parametrize("pairlistconfig,desc_expected,exception_expected", [ @pytest.mark.parametrize("pairlistconfig,desc_expected,exception_expected", [
({"method": "PriceFilter", "low_price_ratio": 0.001, "min_price": 0.00000010, ({"method": "PriceFilter", "low_price_ratio": 0.001, "min_price": 0.00000010,
"max_price": 1.0}, "max_price": 1.0},