diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index c2f32db0b..a47acec20 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -226,6 +226,23 @@ def get_balances() -> dict: raise OperationalException(e) +@retrier +def get_tickers() -> Dict: + try: + return _API.fetch_tickers() + except ccxt.NetworkError as e: + raise NetworkException( + 'Could not load tickers due to networking error. Message: {}'.format(e) + ) + except ccxt.BaseError as e: + raise OperationalException(e) + except ccxt.NotSupported as e: + raise OperationalException( + 'Exchange {} does not support fetching tickers in batch.' + 'Message: {}'.format(_API.name, e) + ) + + # TODO: remove refresh argument, keeping it to keep track of where it was intended to be used @retrier def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict: diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index e2b40f85a..2d041471b 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -185,18 +185,27 @@ class FreqtradeBot(object): return state_changed @cached(TTLCache(maxsize=1, ttl=1800)) - def _gen_pair_whitelist(self, base_currency: str, key: str = 'BaseVolume') -> List[str]: + def _gen_pair_whitelist(self, base_currency: str, key: str = 'quoteVolume') -> List[str]: """ Updates the whitelist with with a dynamically generated list :param base_currency: base currency as str - :param key: sort key (defaults to 'BaseVolume') + :param key: sort key (defaults to 'quoteVolume') :return: List of pairs """ - pairs = sorted( - [s['symbol'] for s in exchange.get_markets() if s['quote'] == base_currency], - reverse=True - ) + if not exchange.exchange_has('fetchTickers'): + raise OperationalException( + 'Exchange does not support dynamic whitelist.' + 'Please edit your config and restart the bot' + ) + + tickers = exchange.get_tickers() + # check length so that we make sure that '/' is actually in the string + tickers = [v for k, v in tickers.items() + if len(k.split('/')) == 2 and k.split('/')[1] == base_currency] + + sorted_tickers = sorted(tickers, reverse=True, key=lambda t: t[key]) + pairs = [s['symbol'] for s in sorted_tickers] return pairs def _refresh_whitelist(self, whitelist: List[str]) -> List[str]: @@ -349,7 +358,7 @@ class FreqtradeBot(object): if trade.open_order_id: # Update trade with order values self.logger.info('Found open order for %s', trade) - trade.update(exchange.get_order(trade.open_order_id)) + trade.update(exchange.get_order(trade.open_order_id, trade.pair)) if trade.is_open and trade.open_order_id is None: # Check if we can sell our current pair