Keeping cached Klines only in exchange and renaming _cached_klines to

klines.
This commit is contained in:
misagh 2018-08-16 11:37:31 +02:00
parent a2d9126917
commit e6e2799f03
3 changed files with 10 additions and 11 deletions

View File

@ -56,7 +56,7 @@ class Exchange(object):
_pairs_last_refresh_time: Dict[str, int] = {}
# Holds candles
_cached_klines: Dict[str, Any] = {}
klines: Dict[str, Any] = {}
# Holds all open sell orders for dry_run
_dry_run_open_orders: Dict[str, Any] = {}
@ -412,7 +412,7 @@ class Exchange(object):
if (not since_ms and
self._pairs_last_refresh_time.get(pair, 0) + interval_in_sec >=
arrow.utcnow().timestamp):
data = self._cached_klines[pair]
data = self.klines[pair]
logger.debug("Using cached klines data for %s ...", pair)
else:
data = await self._api_async.fetch_ohlcv(pair, timeframe=tick_interval,
@ -427,7 +427,7 @@ class Exchange(object):
self._pairs_last_refresh_time[pair] = data[-1][0] // 1000
# keeping candles in cache
self._cached_klines[pair] = data
self.klines[pair] = data
logger.debug("done fetching %s ...", pair)
return pair, data

View File

@ -55,8 +55,6 @@ class FreqtradeBot(object):
self.persistence = None
self.exchange = Exchange(self.config)
self._init_modules()
self._klines: Dict[str, List[Dict]] = {}
self._klines_last_fetched_time = 0
def _init_modules(self) -> None:
"""
@ -173,7 +171,8 @@ class FreqtradeBot(object):
self.exchange.async_get_candles_history(pair_list, self.strategy.ticker_interval))
# updating cached klines available to bot
self._klines = {pair: data for (pair, data) in datatups}
#self.exchange.klines = {pair: data for (pair, data) in datatups}
# self.exchange.klines = datatups
return True
@ -385,7 +384,7 @@ class FreqtradeBot(object):
# running get_signal on historical data fetched
# to find buy signals
for _pair in whitelist:
(buy, sell) = self.strategy.get_signal(_pair, interval, self._klines.get(_pair))
(buy, sell) = self.strategy.get_signal(_pair, interval, self.exchange.klines.get(_pair))
if buy and not sell:
return self.execute_buy(_pair, stake_amount)
@ -551,7 +550,7 @@ class FreqtradeBot(object):
(buy, sell) = (False, False)
experimental = self.config.get('experimental', {})
if experimental.get('use_sell_signal') or experimental.get('ignore_roi_if_buy_signal'):
ticker = self._klines.get(trade.pair)
ticker = self.exchange.klines.get(trade.pair)
(buy, sell) = self.strategy.get_signal(trade.pair, self.strategy.ticker_interval,
ticker)

View File

@ -158,13 +158,13 @@ def test_refresh_tickers(mocker, default_conf, caplog) -> None:
pairs = ['IOTA/ETH', 'XRP/ETH']
# empty dicts
assert not freqtrade._klines
assert not freqtrade.exchange.klines
freqtrade.refresh_tickers(['IOTA/ETH', 'XRP/ETH'])
assert log_has(f'Refreshing klines for {len(pairs)} pairs', caplog.record_tuples)
assert freqtrade._klines
assert freqtrade.exchange.klines
for pair in pairs:
assert freqtrade._klines[pair]
assert freqtrade.exchange.klines[pair]
def test_gen_pair_whitelist(mocker, default_conf, tickers) -> None: