From 4ff035537b01cf454a3cb34b60f232ad48972a2f Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 28 Oct 2019 16:21:00 +0100 Subject: [PATCH] Simplify precision_filter code --- config_full.json.example | 2 +- docs/configuration.md | 5 ++--- freqtrade/pairlist/VolumePairList.py | 21 +++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config_full.json.example b/config_full.json.example index 5789e49ac..a5af0f7a6 100644 --- a/config_full.json.example +++ b/config_full.json.example @@ -55,7 +55,7 @@ "config": { "number_assets": 20, "sort_key": "quoteVolume", - "precision_filter": false + "precision_filter": true } }, "exchange": { diff --git a/docs/configuration.md b/docs/configuration.md index 1ad13c87a..03f15e07d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -423,8 +423,7 @@ section of the configuration. * `VolumePairList` * It selects `number_assets` top pairs based on `sort_key`, which can be one of `askVolume`, `bidVolume` and `quoteVolume`, defaults to `quoteVolume`. - * There is a possibility to filter low-value coins that would not allow setting a stop loss -(set `precision_filter` parameter to `true` for this). + * By default, low-value coins that would not allow setting a stop loss are filtered out. (set `precision_filter` parameter to `false` to disable this behaviour). * `VolumePairList` does not consider `pair_whitelist`, but builds this automatically based the pairlist configuration. * Pairs in `pair_blacklist` are not considered for VolumePairList, even if all other filters would match. @@ -440,7 +439,7 @@ Example: "config": { "number_assets": 20, "sort_key": "quoteVolume", - "precision_filter": false + "precision_filter": true } }, ``` diff --git a/freqtrade/pairlist/VolumePairList.py b/freqtrade/pairlist/VolumePairList.py index 5f53cd17b..5e20f0fb1 100644 --- a/freqtrade/pairlist/VolumePairList.py +++ b/freqtrade/pairlist/VolumePairList.py @@ -26,7 +26,7 @@ class VolumePairList(IPairList): 'for "pairlist.config.number_assets"') self._number_pairs = self._whitelistconf['number_assets'] self._sort_key = self._whitelistconf.get('sort_key', 'quoteVolume') - self._precision_filter = self._whitelistconf.get('precision_filter', False) + self._precision_filter = self._whitelistconf.get('precision_filter', True) if not self._freqtrade.exchange.exchange_has('fetchTickers'): raise OperationalException( @@ -76,18 +76,19 @@ class VolumePairList(IPairList): valid_tickers = [t for t in sorted_tickers if t["symbol"] in valid_pairs] if self._freqtrade.strategy.stoploss is not None and self._precision_filter: + # Precalculate correct stoploss value + stoploss = 1 - abs(self._freqtrade.strategy.stoploss) - stop_prices = [self._freqtrade.get_target_bid(t["symbol"], t) - * (1 - abs(self._freqtrade.strategy.stoploss)) for t in valid_tickers] - rates = [sp * 0.99 for sp in stop_prices] - logger.debug("\n".join([f"{sp} : {r}" for sp, r in zip(stop_prices[:10], rates[:10])])) for i, t in enumerate(valid_tickers): - sp = self._freqtrade.exchange.symbol_price_prec(t["symbol"], stop_prices[i]) - r = self._freqtrade.exchange.symbol_price_prec(t["symbol"], rates[i]) - logger.debug(f"{t['symbol']} - {sp} : {r}") - if sp <= r: + stop_price = (self._freqtrade.get_target_bid(t["symbol"], t) * stoploss) + # Adjust stop-prices to precision + sp = self._freqtrade.exchange.symbol_price_prec(t["symbol"], stop_price) + stop_gap_price = self._freqtrade.exchange.symbol_price_prec(t["symbol"], + stop_price * 0.99) + logger.debug(f"{t['symbol']} - {sp} : {stop_gap_price}") + if sp <= stop_gap_price: logger.info(f"Removed {t['symbol']} from whitelist, " - f"because stop price {sp} would be <= stop limit {r}") + f"because stop price {sp} would be <= stop limit {stop_gap_price}") valid_tickers.remove(t) pairs = [s['symbol'] for s in valid_tickers]