Reduce caching to 5min to speed up UI refreshes in case of open orders.

This commit is contained in:
Matthias
2024-01-04 14:22:02 +01:00
parent b9786b979a
commit 22307913d8
2 changed files with 8 additions and 7 deletions

View File

@@ -121,11 +121,12 @@ class Exchange:
# Cache for 10 minutes ...
self._cache_lock = Lock()
self._fetch_tickers_cache: TTLCache = TTLCache(maxsize=2, ttl=60 * 10)
# Cache values for 1800 to avoid frequent polling of the exchange for prices
# Cache values for 300 to avoid frequent polling of the exchange for prices
# Caching only applies to RPC methods, so prices for open trades are still
# refreshed once every iteration.
self._exit_rate_cache: TTLCache = TTLCache(maxsize=100, ttl=1800)
self._entry_rate_cache: TTLCache = TTLCache(maxsize=100, ttl=1800)
# Shouldn't be too high either, as it'll freeze UI updates in case of open orders.
self._exit_rate_cache: TTLCache = TTLCache(maxsize=100, ttl=300)
self._entry_rate_cache: TTLCache = TTLCache(maxsize=100, ttl=300)
# Holds candles
self._klines: Dict[PairWithTimeframe, DataFrame] = {}

View File

@@ -2528,13 +2528,13 @@ def test_get_entry_rate(mocker, default_conf, caplog, side, ask, bid,
assert exchange.get_rate('ETH/BTC', side="entry", is_short=False, refresh=True) == expected
assert not log_has(log_msg, caplog)
time_machine.move_to(start_dt + timedelta(minutes=29), tick=False)
time_machine.move_to(start_dt + timedelta(minutes=4), tick=False)
# Running a 2nd time without Refresh!
caplog.clear()
assert exchange.get_rate('ETH/BTC', side="entry", is_short=False, refresh=False) == expected
assert log_has(log_msg, caplog)
time_machine.move_to(start_dt + timedelta(minutes=31), tick=False)
time_machine.move_to(start_dt + timedelta(minutes=6), tick=False)
# Running a 2nd time - forces refresh due to ttl timeout
caplog.clear()
assert exchange.get_rate('ETH/BTC', side="entry", is_short=False, refresh=False) == expected
@@ -2571,13 +2571,13 @@ def test_get_exit_rate(default_conf, mocker, caplog, side, bid, ask,
assert exchange.get_rate(pair, side="exit", is_short=False, refresh=False) == expected
assert log_has(log_msg, caplog)
time_machine.move_to(start_dt + timedelta(minutes=29), tick=False)
time_machine.move_to(start_dt + timedelta(minutes=4), tick=False)
# Caching still active - TTL didn't expire
caplog.clear()
assert exchange.get_rate(pair, side="exit", is_short=False, refresh=False) == expected
assert log_has(log_msg, caplog)
time_machine.move_to(start_dt + timedelta(minutes=32), tick=False)
time_machine.move_to(start_dt + timedelta(minutes=6), tick=False)
# Caching expired - refresh forced
caplog.clear()
assert exchange.get_rate(pair, side="exit", is_short=False, refresh=False) == expected