move pairlist filters out of config[]

This commit is contained in:
Matthias 2019-11-19 06:34:54 +01:00
parent 66a273b31b
commit c22b00b303
7 changed files with 30 additions and 41 deletions

View File

@ -61,10 +61,7 @@
} }
}, },
{"method": "PrecisionFilter"}, {"method": "PrecisionFilter"},
{"method": "LowPriceFilter", {"method": "LowPriceFilter", "low_price_ratio": 0.01
"config": {
"low_price_percent": 0.01
}
} }
], ],
"exchange": { "exchange": {

View File

@ -416,11 +416,9 @@ It uses configuration from `exchange.pair_whitelist` and `exchange.pair_blacklis
```json ```json
"pairlists": [{ "pairlists": [{
"method": "VolumePairList", "method": "VolumePairList",
"config": { "number_assets": 20,
"number_assets": 20, "sort_key": "quoteVolume",
"sort_key": "quoteVolume", "ttl": 1800,
"ttl": 1800,
}
], ],
``` ```
@ -430,7 +428,7 @@ Filters low-value coins which would not allow setting a stoploss.
#### Low Price Pair Filter #### 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. This option is disabled by default, and will only apply if set to <> 0.
Calculation example: Calculation example:
@ -450,16 +448,12 @@ The below example blacklists `BNB/BTC`, uses `VolumePairList` with `20` assets,
"pairlists": [ "pairlists": [
{ {
"method": "VolumePairList", "method": "VolumePairList",
"config": { "number_assets": 20,
"number_assets": 20, "sort_key": "quoteVolume",
"sort_key": "quoteVolume",
},
}, },
{"method": "PrecisionFilter"}, {"method": "PrecisionFilter"},
{"method": "LowPriceFilter", {"method": "LowPriceFilter", "low_price_ratio": 0.01}
"config": {"low_price_percent": 0.01} ],
}
}],
``` ```
## Switch to Dry-run mode ## Switch to Dry-run mode

View File

@ -13,7 +13,7 @@ class LowPriceFilter(IPairList):
pairlist_pos: int) -> None: pairlist_pos: int) -> None:
super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos) 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 @property
def needstickers(self) -> bool: def needstickers(self) -> bool:
@ -28,7 +28,7 @@ class LowPriceFilter(IPairList):
""" """
Short whitelist method description - used for startup-messages 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: def _validate_ticker_lowprice(self, ticker) -> bool:
""" """
@ -41,7 +41,7 @@ class LowPriceFilter(IPairList):
compare = ticker['last'] + 1 / pow(10, precision) compare = ticker['last'] + 1 / pow(10, precision)
changeperc = (compare - ticker['last']) / ticker['last'] 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, " logger.info(f"Removed {ticker['symbol']} from whitelist, "
f"because 1 unit is {changeperc * 100:.3f}%") f"because 1 unit is {changeperc * 100:.3f}%")
return False return False
@ -63,7 +63,7 @@ class LowPriceFilter(IPairList):
pairlist.remove(p) pairlist.remove(p)
# Filter out assets which would not allow setting a stoploss # 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) pairlist.remove(p)
return pairlist return pairlist

View File

@ -32,7 +32,7 @@ class PairListManager():
exchange=exchange, exchange=exchange,
pairlistmanager=self, pairlistmanager=self,
config=config, config=config,
pairlistconfig=pl.get('config'), pairlistconfig=pl,
pairlist_pos=len(self._pairlists) pairlist_pos=len(self._pairlists)
).pairlist ).pairlist
self._tickers_needed = pairl.needstickers or self._tickers_needed self._tickers_needed = pairl.needstickers or self._tickers_needed

View File

@ -29,10 +29,8 @@ def whitelist_conf(default_conf):
default_conf['pairlists'] = [ default_conf['pairlists'] = [
{ {
"method": "VolumePairList", "method": "VolumePairList",
"config": { "number_assets": 5,
"number_assets": 5, "sort_key": "quoteVolume",
"sort_key": "quoteVolume",
}
}, },
] ]
return default_conf 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", [ @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']), "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'HOT/BTC', 'FUEL/BTC']),
# Different sorting depending on quote or bid volume # 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']), "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']), "USDT", ['ETH/USDT']),
# No pair for ETH ... # No pair for ETH ...
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}], ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}],
"ETH", []), "ETH", []),
# Precisionfilter and quote volume # 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']), {"method": "PrecisionFilter"}], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'FUEL/BTC']),
# Precisionfilter bid # 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']), {"method": "PrecisionFilter"}], "BTC", ['FUEL/BTC', 'LTC/BTC', 'TKN/BTC', 'ETH/BTC']),
# Lowpricefilter and VolumePairList # Lowpricefilter and VolumePairList
([{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "quoteVolume"}}, ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"},
{"method": "LowPriceFilter", "config": {"low_price_percent": 0.03}}], {"method": "LowPriceFilter", "low_price_ratio": 0.03}],
"BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'FUEL/BTC']), "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC', 'FUEL/BTC']),
# Hot is removed by precision_filter, Fuel by low_price_filter. # 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": "PrecisionFilter"},
{"method": "LowPriceFilter", "config": {"low_price_percent": 0.02}} {"method": "LowPriceFilter", "low_price_ratio": 0.02}
], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']), ], "BTC", ['ETH/BTC', 'TKN/BTC', 'LTC/BTC']),
# StaticPairlist Only # StaticPairlist Only
([{"method": "StaticPairList"}, ([{"method": "StaticPairList"},
], "BTC", ['ETH/BTC', 'TKN/BTC']), ], "BTC", ['ETH/BTC', 'TKN/BTC']),
# Static Pairlist before VolumePairList - sorting changes # Static Pairlist before VolumePairList - sorting changes
([{"method": "StaticPairList"}, ([{"method": "StaticPairList"},
{"method": "VolumePairList", "config": {"number_assets": 5, "sort_key": "bidVolume"}}, {"method": "VolumePairList", "number_assets": 5, "sort_key": "bidVolume"},
], "BTC", ['TKN/BTC', 'ETH/BTC']), ], "BTC", ['TKN/BTC', 'ETH/BTC']),
]) ])
def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, tickers, 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): 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)) mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
with pytest.raises(OperationalException, with pytest.raises(OperationalException,

View File

@ -726,7 +726,7 @@ def test_rpc_whitelist(mocker, default_conf) -> None:
def test_rpc_whitelist_dynamic(mocker, default_conf) -> None: def test_rpc_whitelist_dynamic(mocker, default_conf) -> None:
default_conf['pairlists'] = [{'method': 'VolumePairList', 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.exchange.Exchange.exchange_has', MagicMock(return_value=True))
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock()) mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())

View File

@ -1063,7 +1063,7 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None:
) )
mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True))
default_conf['pairlists'] = [{'method': 'VolumePairList', default_conf['pairlists'] = [{'method': 'VolumePairList',
'config': {'number_assets': 4} 'number_assets': 4
}] }]
freqtradebot = get_patched_freqtradebot(mocker, default_conf) freqtradebot = get_patched_freqtradebot(mocker, default_conf)