mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 02:12:01 +00:00
Implement ticker caching
This commit is contained in:
parent
4b15873ee1
commit
085aa3084e
|
@ -4,6 +4,7 @@ Static List provider
|
|||
Provides lists as configured in config.json
|
||||
|
||||
"""
|
||||
from cachetools import TTLCache, cached
|
||||
import logging
|
||||
from typing import Dict, List
|
||||
|
||||
|
@ -68,6 +69,10 @@ class PairListManager():
|
|||
"""
|
||||
return [{p.name: p.short_desc()} for p in self._pairlists]
|
||||
|
||||
@cached(TTLCache(maxsize=1, ttl=1800))
|
||||
def _get_cached_tickers(self):
|
||||
return self._exchange.get_tickers()
|
||||
|
||||
def refresh_pairlist(self) -> None:
|
||||
"""
|
||||
Run pairlist through all configured pairlists.
|
||||
|
@ -78,7 +83,7 @@ class PairListManager():
|
|||
# tickers should be cached to avoid calling the exchange on each call.
|
||||
tickers: Dict = {}
|
||||
if self._tickers_needed:
|
||||
tickers = self._exchange.get_tickers()
|
||||
tickers = self._get_cached_tickers()
|
||||
|
||||
# Process all pairlists in chain
|
||||
for pl in self._pairlists:
|
||||
|
|
|
@ -4,6 +4,7 @@ ccxt==1.19.14
|
|||
SQLAlchemy==1.3.10
|
||||
python-telegram-bot==12.2.0
|
||||
arrow==0.15.4
|
||||
cachetools==3.1.1
|
||||
requests==2.22.0
|
||||
urllib3==1.25.6
|
||||
wrapt==1.11.2
|
||||
|
|
1
setup.py
1
setup.py
|
@ -66,6 +66,7 @@ setup(name='freqtrade',
|
|||
'SQLAlchemy',
|
||||
'python-telegram-bot',
|
||||
'arrow',
|
||||
'cachetools',
|
||||
'requests',
|
||||
'urllib3',
|
||||
'wrapt',
|
||||
|
|
|
@ -268,12 +268,14 @@ def test_volumepairlist_caching(mocker, markets, whitelist_conf, tickers):
|
|||
)
|
||||
bot = get_patched_freqtradebot(mocker, whitelist_conf)
|
||||
assert bot.pairlists._pairlists[0]._last_refresh == 0
|
||||
|
||||
assert tickers.call_count == 0
|
||||
bot.pairlists.refresh_pairlist()
|
||||
assert tickers.call_count == 1
|
||||
|
||||
assert bot.pairlists._pairlists[0]._last_refresh != 0
|
||||
lrf = bot.pairlists._pairlists[0]._last_refresh
|
||||
bot.pairlists.refresh_pairlist()
|
||||
assert tickers.call_count == 1
|
||||
# Time should not be updated.
|
||||
assert bot.pairlists._pairlists[0]._last_refresh == lrf
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user