|
|
|
|
@@ -633,21 +633,23 @@ 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, time_machine):
|
|
|
|
|
caplog.set_level(logging.DEBUG)
|
|
|
|
|
initial_markets = {'ETH/BTC': {}}
|
|
|
|
|
updated_markets = {'ETH/BTC': {}, "LTC/BTC": {}}
|
|
|
|
|
|
|
|
|
|
start_dt = dt_now()
|
|
|
|
|
time_machine.move_to(start_dt, tick=False)
|
|
|
|
|
api_mock = MagicMock()
|
|
|
|
|
api_mock.load_markets = MagicMock(return_value=initial_markets)
|
|
|
|
|
default_conf['exchange']['markets_refresh_interval'] = 10
|
|
|
|
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id="binance",
|
|
|
|
|
mock_markets=False)
|
|
|
|
|
exchange._load_async_markets = MagicMock()
|
|
|
|
|
exchange._last_markets_refresh = dt_ts()
|
|
|
|
|
assert exchange._last_markets_refresh == dt_ts()
|
|
|
|
|
|
|
|
|
|
assert exchange.markets == initial_markets
|
|
|
|
|
|
|
|
|
|
time_machine.move_to(start_dt + timedelta(minutes=8), tick=False)
|
|
|
|
|
# less than 10 minutes have passed, no reload
|
|
|
|
|
exchange.reload_markets()
|
|
|
|
|
assert exchange.markets == initial_markets
|
|
|
|
|
@@ -655,12 +657,18 @@ def test_reload_markets(default_conf, mocker, caplog):
|
|
|
|
|
|
|
|
|
|
api_mock.load_markets = MagicMock(return_value=updated_markets)
|
|
|
|
|
# more than 10 minutes have passed, reload is executed
|
|
|
|
|
exchange._last_markets_refresh = dt_ts(dt_now() - timedelta(minutes=15))
|
|
|
|
|
time_machine.move_to(start_dt + timedelta(minutes=11), tick=False)
|
|
|
|
|
exchange.reload_markets()
|
|
|
|
|
assert exchange.markets == updated_markets
|
|
|
|
|
assert exchange._load_async_markets.call_count == 1
|
|
|
|
|
assert log_has('Performing scheduled market reload..', caplog)
|
|
|
|
|
|
|
|
|
|
# Not called again
|
|
|
|
|
exchange._load_async_markets.reset_mock()
|
|
|
|
|
|
|
|
|
|
exchange.reload_markets()
|
|
|
|
|
assert exchange._load_async_markets.call_count == 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_reload_markets_exception(default_conf, mocker, caplog):
|
|
|
|
|
caplog.set_level(logging.DEBUG)
|
|
|
|
|
|