diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index 3143abc1f..e13d2b39d 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -79,13 +79,12 @@ def analyze_ticker(pair: str) -> DataFrame: add several TA indicators and buy signal to it :return DataFrame with ticker data and indicator data """ - data = get_ticker_history(pair) - dataframe = parse_ticker_dataframe(data) - - if dataframe.empty: - logger.warning('Empty dataframe for pair %s', pair) - return dataframe + ticker_hist = get_ticker_history(pair) + if not ticker_hist: + logger.warning('Empty ticker history for pair %s', pair) + return DataFrame() + dataframe = parse_ticker_dataframe(ticker_hist) dataframe = populate_indicators(dataframe) dataframe = populate_buy_trend(dataframe) return dataframe @@ -98,7 +97,6 @@ def get_buy_signal(pair: str) -> bool: :return: True if pair is good for buying, False otherwise """ dataframe = analyze_ticker(pair) - if dataframe.empty: return False diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 523274079..10de18b14 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -129,7 +129,7 @@ def get_ticker(pair: str) -> dict: @cached(TTLCache(maxsize=100, ttl=30)) -def get_ticker_history(pair: str, tick_interval: Optional[int] = 5) -> List: +def get_ticker_history(pair: str, tick_interval: Optional[int] = 5) -> List[Dict]: return _API.get_ticker_history(pair, tick_interval) diff --git a/freqtrade/exchange/bittrex.py b/freqtrade/exchange/bittrex.py index 51ddd17e0..b1d8e68fb 100644 --- a/freqtrade/exchange/bittrex.py +++ b/freqtrade/exchange/bittrex.py @@ -88,7 +88,7 @@ class Bittrex(Exchange): 'last': float(data['result']['Last']), } - def get_ticker_history(self, pair: str, tick_interval: int): + def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]: if tick_interval == 1: interval = 'oneMin' elif tick_interval == 5: @@ -97,6 +97,13 @@ class Bittrex(Exchange): raise ValueError('Cannot parse tick_interval: {}'.format(tick_interval)) data = _API_V2.get_candles(pair.replace('_', '-'), interval) + # This sanity check is necessary because bittrex returns nonsense sometimes + for prop in ['C', 'V', 'O', 'H', 'L', 'T']: + for tick in data['result']: + if prop not in tick.keys(): + logger.warning('Required property {} not present in response'.format(prop)) + return [] + if not data['success']: raise RuntimeError('{message} params=({pair})'.format( message=data['message'], diff --git a/freqtrade/exchange/interface.py b/freqtrade/exchange/interface.py index 0000461d2..60e6b03cd 100644 --- a/freqtrade/exchange/interface.py +++ b/freqtrade/exchange/interface.py @@ -74,7 +74,7 @@ class Exchange(ABC): """ @abstractmethod - def get_ticker_history(self, pair: str, tick_interval: int) -> List: + def get_ticker_history(self, pair: str, tick_interval: int) -> List[Dict]: """ Gets ticker history for given pair. :param pair: Pair as str, format: BTC_ETC