From be8506b45eb8d1ff8b0babc0d28ff6cb4aaf4479 Mon Sep 17 00:00:00 2001 From: Samuel Husso Date: Fri, 5 Jan 2018 08:15:46 +0200 Subject: [PATCH 1/3] log exceptions, catch *all* exceptions when analysing ticker --- freqtrade/analyze.py | 3 +++ freqtrade/misc.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/freqtrade/analyze.py b/freqtrade/analyze.py index d586077db..733146e11 100644 --- a/freqtrade/analyze.py +++ b/freqtrade/analyze.py @@ -144,6 +144,9 @@ def get_signal(pair: str, signal: SignalType) -> bool: except ValueError as ex: logger.warning('Unable to analyze ticker for pair %s: %s', pair, str(ex)) return False + except Exception as ex: + logger.exception('Unexpected error when analyzing ticker for pair %s: %s', pair, str(ex)) + return False if dataframe.empty: return False diff --git a/freqtrade/misc.py b/freqtrade/misc.py index 9f414a72f..900aa8763 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -57,8 +57,8 @@ def load_config(path: str) -> Dict: try: validate(conf, CONF_SCHEMA) return conf - except ValidationError: - logger.fatal('Configuration is not valid! See config.json.example') + except ValidationError as ex: + logger.fatal('Invalid configuration. See config.json.example. Reason: %s', ex) raise ValidationError( best_match(Draft4Validator(CONF_SCHEMA).iter_errors(conf)).message ) From ae967a4f4003c84e901428805c2eddae7593c99d Mon Sep 17 00:00:00 2001 From: Samuel Husso Date: Fri, 5 Jan 2018 13:43:56 +0200 Subject: [PATCH 2/3] add test to handle analyze_ticker raising exception --- freqtrade/tests/test_analyze.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/freqtrade/tests/test_analyze.py b/freqtrade/tests/test_analyze.py index 47a557e10..b726474c8 100644 --- a/freqtrade/tests/test_analyze.py +++ b/freqtrade/tests/test_analyze.py @@ -9,7 +9,6 @@ from pandas import DataFrame from freqtrade.analyze import parse_ticker_dataframe, populate_buy_trend, populate_indicators, \ get_signal, SignalType, populate_sell_trend - @pytest.fixture def result(): with open('freqtrade/tests/testdata/BTC_ETH-1.json') as data_file: @@ -63,3 +62,10 @@ def test_returns_latest_sell_signal(mocker): return_value=DataFrame([{'sell': 0, 'date': arrow.utcnow()}]) ) assert not get_signal('BTC-ETH', SignalType.SELL) + +def test_get_signal_handles_exceptions(mocker): + mocker.patch('freqtrade.analyze.get_ticker_history', return_value=MagicMock()) + mocker.patch('freqtrade.analyze.analyze_ticker', + side_effect=Exception('invalid ticker history ')) + + assert not get_signal('BTC-ETH', SignalType.BUY) From 2d39759d342eaaca3476ef5943f190953aa5337f Mon Sep 17 00:00:00 2001 From: Samuel Husso Date: Sat, 6 Jan 2018 10:08:25 +0200 Subject: [PATCH 3/3] pep8 fix --- freqtrade/tests/test_analyze.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/freqtrade/tests/test_analyze.py b/freqtrade/tests/test_analyze.py index b726474c8..040c45f26 100644 --- a/freqtrade/tests/test_analyze.py +++ b/freqtrade/tests/test_analyze.py @@ -9,6 +9,7 @@ from pandas import DataFrame from freqtrade.analyze import parse_ticker_dataframe, populate_buy_trend, populate_indicators, \ get_signal, SignalType, populate_sell_trend + @pytest.fixture def result(): with open('freqtrade/tests/testdata/BTC_ETH-1.json') as data_file: @@ -63,6 +64,7 @@ def test_returns_latest_sell_signal(mocker): ) assert not get_signal('BTC-ETH', SignalType.SELL) + def test_get_signal_handles_exceptions(mocker): mocker.patch('freqtrade.analyze.get_ticker_history', return_value=MagicMock()) mocker.patch('freqtrade.analyze.analyze_ticker',