From 65dcb6acea016a1248480e8eb262b89e1579695d Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 24 Apr 2019 21:56:24 +0200 Subject: [PATCH 1/2] Catch errors on reload_markets --- freqtrade/exchange/exchange.py | 7 +++++-- freqtrade/tests/exchange/test_exchange.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 94673fdc3..475baad67 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -222,8 +222,11 @@ class Exchange(object): > arrow.utcnow().timestamp): return None logger.debug("Performing scheduled market reload..") - self._api.load_markets(reload=True) - self._last_markets_refresh = arrow.utcnow().timestamp + try: + self._api.load_markets(reload=True) + self._last_markets_refresh = arrow.utcnow().timestamp + except ccxt.NetworkError: + logger.exception("Could not reload markets.") def validate_pairs(self, pairs: List[str]) -> None: """ diff --git a/freqtrade/tests/exchange/test_exchange.py b/freqtrade/tests/exchange/test_exchange.py index 9e471d551..924ed538f 100644 --- a/freqtrade/tests/exchange/test_exchange.py +++ b/freqtrade/tests/exchange/test_exchange.py @@ -301,6 +301,20 @@ def test__reload_markets(default_conf, mocker, caplog): assert log_has('Performing scheduled market reload..', caplog.record_tuples) +def test__reload_markets_exception(default_conf, mocker, caplog): + caplog.set_level(logging.DEBUG) + + api_mock = MagicMock() + api_mock.load_markets = MagicMock(side_effect=ccxt.NetworkError) + default_conf['exchange']['markets_refresh_interval'] = 10 + exchange = get_patched_exchange(mocker, default_conf, api_mock, id="binance") + + # less than 10 minutes have passed, no reload + exchange._reload_markets() + assert exchange._last_markets_refresh == 0 + assert log_has_re(r"Could not reload markets.*", caplog.record_tuples) + + def test_validate_pairs(default_conf, mocker): # test exchange.validate_pairs directly api_mock = MagicMock() type(api_mock).markets = PropertyMock(return_value={ From 45ecbc91e8c0d47398e2c20463f84befd64bb2b7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 24 Apr 2019 22:20:05 +0200 Subject: [PATCH 2/2] Use BaseError, not NetworkError in exception handler --- freqtrade/exchange/exchange.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 475baad67..66857a7a5 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -225,7 +225,7 @@ class Exchange(object): try: self._api.load_markets(reload=True) self._last_markets_refresh = arrow.utcnow().timestamp - except ccxt.NetworkError: + except ccxt.BaseError: logger.exception("Could not reload markets.") def validate_pairs(self, pairs: List[str]) -> None: