From c22b00b30303ba44f3dcf140b4fd8b70fb2e2f80 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 19 Nov 2019 06:34:54 +0100 Subject: [PATCH] move pairlist filters out of config[] --- config_full.json.example | 5 +---- docs/configuration.md | 22 +++++++------------- freqtrade/pairlist/LowPriceFilter.py | 8 +++---- freqtrade/pairlist/pairlistmanager.py | 2 +- tests/pairlist/test_pairlist.py | 30 +++++++++++++-------------- tests/rpc/test_rpc.py | 2 +- tests/rpc/test_rpc_telegram.py | 2 +- 7 files changed, 30 insertions(+), 41 deletions(-) diff --git a/config_full.json.example b/config_full.json.example index ba53f47d6..270938237 100644 --- a/config_full.json.example +++ b/config_full.json.example @@ -61,10 +61,7 @@ } }, {"method": "PrecisionFilter"}, - {"method": "LowPriceFilter", - "config": { - "low_price_percent": 0.01 - } + {"method": "LowPriceFilter", "low_price_ratio": 0.01 } ], "exchange": { diff --git a/docs/configuration.md b/docs/configuration.md index 8a2b74ed5..120842cdb 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -416,11 +416,9 @@ It uses configuration from `exchange.pair_whitelist` and `exchange.pair_blacklis ```json "pairlists": [{ "method": "VolumePairList", - "config": { - "number_assets": 20, - "sort_key": "quoteVolume", - "ttl": 1800, - } + "number_assets": 20, + "sort_key": "quoteVolume", + "ttl": 1800, ], ``` @@ -430,7 +428,7 @@ Filters low-value coins which would not allow setting a stoploss. #### Low Price Pair Filter -The `LowPriceFilter` allows filtering of pairs where a raise of 1 price unit is below the `low_price_percent` ratio. +The `LowPriceFilter` allows filtering of pairs where a raise of 1 price unit is below the `low_price_ratio` ratio. This option is disabled by default, and will only apply if set to <> 0. Calculation example: @@ -450,16 +448,12 @@ The below example blacklists `BNB/BTC`, uses `VolumePairList` with `20` assets, "pairlists": [ { "method": "VolumePairList", - "config": { - "number_assets": 20, - "sort_key": "quoteVolume", - }, + "number_assets": 20, + "sort_key": "quoteVolume", }, {"method": "PrecisionFilter"}, - {"method": "LowPriceFilter", - "config": {"low_price_percent": 0.01} - } - }], + {"method": "LowPriceFilter", "low_price_ratio": 0.01} + ], ``` ## Switch to Dry-run mode diff --git a/freqtrade/pairlist/LowPriceFilter.py b/freqtrade/pairlist/LowPriceFilter.py index 83b6a85e6..ff18b97c8 100644 --- a/freqtrade/pairlist/LowPriceFilter.py +++ b/freqtrade/pairlist/LowPriceFilter.py @@ -13,7 +13,7 @@ class LowPriceFilter(IPairList): pairlist_pos: int) -> None: super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos) - self._low_price_percent = pairlistconfig.get('low_price_percent', 0) + self._low_price_ratio = pairlistconfig.get('low_price_ratio', 0) @property def needstickers(self) -> bool: @@ -28,7 +28,7 @@ class LowPriceFilter(IPairList): """ Short whitelist method description - used for startup-messages """ - return f"{self.name} - Filtering pairs priced below {self._low_price_percent * 100}%." + return f"{self.name} - Filtering pairs priced below {self._low_price_ratio * 100}%." def _validate_ticker_lowprice(self, ticker) -> bool: """ @@ -41,7 +41,7 @@ class LowPriceFilter(IPairList): compare = ticker['last'] + 1 / pow(10, precision) changeperc = (compare - ticker['last']) / ticker['last'] - if changeperc > self._low_price_percent: + if changeperc > self._low_price_ratio: logger.info(f"Removed {ticker['symbol']} from whitelist, " f"because 1 unit is {changeperc * 100:.3f}%") return False @@ -63,7 +63,7 @@ class LowPriceFilter(IPairList): pairlist.remove(p) # Filter out assets which would not allow setting a stoploss - if self._low_price_percent and not self._validate_ticker_lowprice(ticker): + if self._low_price_ratio and not self._validate_ticker_lowprice(ticker): pairlist.remove(p) return pairlist diff --git a/freqtrade/pairlist/pairlistmanager.py b/freqtrade/pairlist/pairlistmanager.py index 0734d7f8f..fa5382c37 100644 --- a/freqtrade/pairlist/pairlistmanager.py +++ b/freqtrade/pairlist/pairlistmanager.py @@ -32,7 +32,7 @@ class PairListManager(): exchange=exchange, pairlistmanager=self, config=config, - pairlistconfig=pl.get('config'), + pairlistconfig=pl, pairlist_pos=len(self._pairlists) ).pairlist self._tickers_needed = pairl.needstickers or self._tickers_needed diff --git a/tests/pairlist/test_pairlist.py b/tests/pairlist/test_pairlist.py index 13f868c7a..9daaa5353 100644 --- a/tests/pairlist/test_pairlist.py +++ b/tests/pairlist/test_pairlist.py @@ -29,10 +29,8 @@ def whitelist_conf(default_conf): default_conf['pairlists'] = [ { "method": "VolumePairList", - "config": { - "number_assets": 5, - "sort_key": "quoteVolume", - } + "number_assets": 5, + "sort_key": "quoteVolume", }, ] return default_conf @@ -136,37 +134,37 @@ def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf): @pytest.mark.parametrize("pairlists,base_currency,whitelist_result", [ - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}], + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'HOT/BTC', 'FUEL/BTC']), # Different sorting depending on quote or bid volume - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "bidVolume"}}], + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"}], "BTC", ['HOT/BTC', 'FUEL/BTC', 'LTC/BTC', 'TKN/BTC', 'ETH/BTC']), - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}], + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}], "USDT", ['ETH/USDT']), # No pair for ETH ... - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}], + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}], "ETH", []), # Precisionfilter and quote volume - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}, + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}, {"method": "PrecisionFilter"}], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'FUEL/BTC']), # Precisionfilter bid - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "bidVolume"}}, + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"}, {"method": "PrecisionFilter"}], "BTC", ['FUEL/BTC', 'LTC/BTC', 'TKN/BTC', 'ETH/BTC']), # Lowpricefilter and VolumePairList - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}, - {"method": "LowPriceFilter", "config": {"low_price_percent": 0.03}}], + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}, + {"method": "LowPriceFilter", "low_price_ratio": 0.03}], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'FUEL/BTC']), # Hot is removed by precision_filter, Fuel by low_price_filter. - ([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}, + ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}, {"method": "PrecisionFilter"}, - {"method": "LowPriceFilter", "config": {"low_price_percent": 0.02}} + {"method": "LowPriceFilter", "low_price_ratio": 0.02} ], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']), # StaticPairlist Only ([{"method": "StaticPairList"}, ], "BTC", ['ETH/BTC', 'TKN/BTC']), # Static Pairlist before VolumePairList - sorting changes ([{"method": "StaticPairList"}, - {"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "bidVolume"}}, + {"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"}, ], "BTC", ['TKN/BTC', 'ETH/BTC']), ]) def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, tickers, @@ -257,7 +255,7 @@ def test__whitelist_for_active_markets(mocker, whitelist_conf, markets, pairlist def test_volumepairlist_invalid_sortvalue(mocker, markets, whitelist_conf): - whitelist_conf['pairlists'][0]['config'].update({"sort_key": "asdf"}) + whitelist_conf['pairlists'][0].update({"sort_key": "asdf"}) mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) with pytest.raises(OperationalException, diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 8747fe6ff..edc0fdb8a 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -726,7 +726,7 @@ def test_rpc_whitelist(mocker, default_conf) -> None: def test_rpc_whitelist_dynamic(mocker, default_conf) -> None: default_conf['pairlists'] = [{'method': 'VolumePairList', - 'config': {'number_assets': 4} + 'number_assets': 4, }] mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index bb9d88658..52d58e887 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1063,7 +1063,7 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None: ) mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) default_conf['pairlists'] = [{'method': 'VolumePairList', - 'config': {'number_assets': 4} + 'number_assets': 4 }] freqtradebot = get_patched_freqtradebot(mocker, default_conf)