Merge pull request #3468 from hroff-1902/cleanup_async_markets

Cleanup async markets
This commit is contained in:
Matthias 2020-06-13 17:28:11 +02:00 committed by GitHub
commit d52198d15e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View File

@ -190,7 +190,7 @@ class Exchange:
def markets(self) -> Dict:
"""exchange ccxt markets"""
if not self._api.markets:
logger.warning("Markets were not loaded. Loading them now..")
logger.info("Markets were not loaded. Loading them now..")
self._load_markets()
return self._api.markets
@ -275,8 +275,8 @@ class Exchange:
except ccxt.BaseError as e:
logger.warning('Unable to initialize markets. Reason: %s', e)
def _reload_markets(self) -> None:
"""Reload markets both sync and async, if refresh interval has passed"""
def reload_markets(self) -> None:
"""Reload markets both sync and async if refresh interval has passed """
# Check whether markets have to be reloaded
if (self._last_markets_refresh > 0) and (
self._last_markets_refresh + self.markets_refresh_interval

View File

@ -139,8 +139,8 @@ class FreqtradeBot:
:return: True if one or more trades has been created or closed, False otherwise
"""
# Check whether markets have to be reloaded
self.exchange._reload_markets()
# Check whether markets have to be reloaded and reload them when it's needed
self.exchange.reload_markets()
# Query trades from persistence layer
trades = Trade.get_open_trades()

View File

@ -352,7 +352,7 @@ def test__load_markets(default_conf, mocker, caplog):
assert ex.markets == expected_return
def test__reload_markets(default_conf, mocker, caplog):
def test_reload_markets(default_conf, mocker, caplog):
caplog.set_level(logging.DEBUG)
initial_markets = {'ETH/BTC': {}}
@ -371,17 +371,17 @@ def test__reload_markets(default_conf, mocker, caplog):
assert exchange.markets == initial_markets
# less than 10 minutes have passed, no reload
exchange._reload_markets()
exchange.reload_markets()
assert exchange.markets == initial_markets
# more than 10 minutes have passed, reload is executed
exchange._last_markets_refresh = arrow.utcnow().timestamp - 15 * 60
exchange._reload_markets()
exchange.reload_markets()
assert exchange.markets == updated_markets
assert log_has('Performing scheduled market reload..', caplog)
def test__reload_markets_exception(default_conf, mocker, caplog):
def test_reload_markets_exception(default_conf, mocker, caplog):
caplog.set_level(logging.DEBUG)
api_mock = MagicMock()
@ -390,7 +390,7 @@ def test__reload_markets_exception(default_conf, mocker, caplog):
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="binance")
# less than 10 minutes have passed, no reload
exchange._reload_markets()
exchange.reload_markets()
assert exchange._last_markets_refresh == 0
assert log_has_re(r"Could not reload markets.*", caplog)