Merge pull request #1801 from freqtrade/catch_network_timeout_1789
Catch errors on reload_markets
This commit is contained in:
		| @@ -222,8 +222,11 @@ class Exchange(object): | |||||||
|                 > arrow.utcnow().timestamp): |                 > arrow.utcnow().timestamp): | ||||||
|             return None |             return None | ||||||
|         logger.debug("Performing scheduled market reload..") |         logger.debug("Performing scheduled market reload..") | ||||||
|  |         try: | ||||||
|             self._api.load_markets(reload=True) |             self._api.load_markets(reload=True) | ||||||
|             self._last_markets_refresh = arrow.utcnow().timestamp |             self._last_markets_refresh = arrow.utcnow().timestamp | ||||||
|  |         except ccxt.BaseError: | ||||||
|  |             logger.exception("Could not reload markets.") | ||||||
|  |  | ||||||
|     def validate_pairs(self, pairs: List[str]) -> None: |     def validate_pairs(self, pairs: List[str]) -> None: | ||||||
|         """ |         """ | ||||||
|   | |||||||
| @@ -301,6 +301,20 @@ def test__reload_markets(default_conf, mocker, caplog): | |||||||
|     assert log_has('Performing scheduled market reload..', caplog.record_tuples) |     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 | def test_validate_pairs(default_conf, mocker):  # test exchange.validate_pairs directly | ||||||
|     api_mock = MagicMock() |     api_mock = MagicMock() | ||||||
|     type(api_mock).markets = PropertyMock(return_value={ |     type(api_mock).markets = PropertyMock(return_value={ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user