Merge pull request #1988 from freqtrade/fix/timeframes_crash

Gracefully fail on timeframes exception
This commit is contained in:
Matthias 2019-07-01 11:19:37 +02:00 committed by GitHub
commit 80bf5c9756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -269,6 +269,12 @@ class Exchange(object):
""" """
Checks if ticker interval from config is a supported timeframe on the exchange Checks if ticker interval from config is a supported timeframe on the exchange
""" """
if not hasattr(self._api, "timeframes"):
# If timeframes is missing, the exchange probably has no fetchOHLCV method.
# Therefore we also show that.
raise OperationalException(
f"This exchange ({self.name}) does not have a `timeframes` attribute and "
f"is therefore not supported. fetchOHLCV: {self.exchange_has('fetchOHLCV')}")
timeframes = self._api.timeframes timeframes = self._api.timeframes
if timeframe not in timeframes: if timeframe not in timeframes:
raise OperationalException( raise OperationalException(

View File

@ -28,6 +28,7 @@ class ExchangeResolver(IResolver):
except ImportError: except ImportError:
logger.info( logger.info(
f"No {exchange_name} specific subclass found. Using the generic class instead.") f"No {exchange_name} specific subclass found. Using the generic class instead.")
if not hasattr(self, "exchange"):
self.exchange = Exchange(config) self.exchange = Exchange(config)
def _load_exchange( def _load_exchange(

View File

@ -396,6 +396,23 @@ def test_validate_timeframes_failed(default_conf, mocker):
Exchange(default_conf) Exchange(default_conf)
def test_validate_timeframes_emulated_ohlcv(default_conf, mocker):
default_conf["ticker_interval"] = "3m"
api_mock = MagicMock()
id_mock = PropertyMock(return_value='test_exchange')
type(api_mock).id = id_mock
# delete timeframes so magicmock does not autocreate it
del api_mock.timeframes
mocker.patch('freqtrade.exchange.Exchange._init_ccxt', MagicMock(return_value=api_mock))
mocker.patch('freqtrade.exchange.Exchange._load_markets', MagicMock(return_value={}))
mocker.patch('freqtrade.exchange.Exchange.validate_pairs', MagicMock())
with pytest.raises(OperationalException,
match=r'This exchange (.*) does not have a `timeframes` attribute and*'):
Exchange(default_conf)
def test_validate_timeframes_not_in_config(default_conf, mocker): def test_validate_timeframes_not_in_config(default_conf, mocker):
del default_conf["ticker_interval"] del default_conf["ticker_interval"]
api_mock = MagicMock() api_mock = MagicMock()