Refactor whitelist handling

fixes #2413
This commit is contained in:
Matthias 2019-10-26 09:38:29 +02:00
parent 2e896462c1
commit d0521d33ce

View File

@ -72,7 +72,7 @@ class FreqtradeBot:
self.edge = Edge(self.config, self.exchange, self.strategy) if \ self.edge = Edge(self.config, self.exchange, self.strategy) if \
self.config.get('edge', {}).get('enabled', False) else None self.config.get('edge', {}).get('enabled', False) else None
self.active_pair_whitelist: List[str] = self.config['exchange']['pair_whitelist'] self.active_pair_whitelist = self._refresh_whitelist()
persistence.init(self.config.get('db_url', None), persistence.init(self.config.get('db_url', None),
clean_open_orders=self.config.get('dry_run', False)) clean_open_orders=self.config.get('dry_run', False))
@ -118,21 +118,10 @@ class FreqtradeBot:
# Check whether markets have to be reloaded # Check whether markets have to be reloaded
self.exchange._reload_markets() self.exchange._reload_markets()
# Refresh whitelist
self.pairlists.refresh_pairlist()
self.active_pair_whitelist = self.pairlists.whitelist
# Calculating Edge positioning
if self.edge:
self.edge.calculate()
self.active_pair_whitelist = self.edge.adjust(self.active_pair_whitelist)
# Query trades from persistence layer # Query trades from persistence layer
trades = Trade.get_open_trades() trades = Trade.get_open_trades()
# Extend active-pair whitelist with pairs from open trades self.active_pair_whitelist = self._refresh_whitelist(trades)
# It ensures that tickers are downloaded for open trades
self._extend_whitelist_with_trades(self.active_pair_whitelist, trades)
# Refreshing candles # Refreshing candles
self.dataprovider.refresh(self._create_pair_whitelist(self.active_pair_whitelist), self.dataprovider.refresh(self._create_pair_whitelist(self.active_pair_whitelist),
@ -150,11 +139,24 @@ class FreqtradeBot:
self.check_handle_timedout() self.check_handle_timedout()
Trade.session.flush() Trade.session.flush()
def _extend_whitelist_with_trades(self, whitelist: List[str], trades: List[Any]): def _refresh_whitelist(self, trades: List[Trade] = []) -> List[str]:
""" """
Extend whitelist with pairs from open trades Refresh whitelist from pairlist or edge and extend it with trades.
""" """
whitelist.extend([trade.pair for trade in trades if trade.pair not in whitelist]) # Refresh whitelist
self.pairlists.refresh_pairlist()
_whitelist = self.pairlists.whitelist
# Calculating Edge positioning
if self.edge:
self.edge.calculate()
_whitelist = self.edge.adjust(_whitelist)
if trades:
# Extend active-pair whitelist with pairs from open trades
# It ensures that tickers are downloaded for open trades
_whitelist.extend([trade.pair for trade in trades if trade.pair not in _whitelist])
return _whitelist
def _create_pair_whitelist(self, pairs: List[str]) -> List[Tuple[str, str]]: def _create_pair_whitelist(self, pairs: List[str]) -> List[Tuple[str, str]]:
""" """