From e66808bb02cb3e697033252c8261ebb168d99ab0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 22 Jan 2019 06:55:40 +0100 Subject: [PATCH] Add additional pairs to refresh call --- freqtrade/data/dataprovider.py | 9 +++++-- freqtrade/freqtradebot.py | 3 ++- freqtrade/tests/data/test_dataprovider.py | 30 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/freqtrade/data/dataprovider.py b/freqtrade/data/dataprovider.py index ce1b480f9..f69b1287d 100644 --- a/freqtrade/data/dataprovider.py +++ b/freqtrade/data/dataprovider.py @@ -23,11 +23,16 @@ class DataProvider(object): self._config = config self._exchange = exchange - def refresh(self, pairlist: List[Tuple[str, str]]) -> None: + def refresh(self, + pairlist: List[Tuple[str, str]], + helping_pairs: List[Tuple[str, str]] = None) -> None: """ Refresh data, called with each cycle """ - self._exchange.refresh_latest_ohlcv(pairlist) + if helping_pairs: + self._exchange.refresh_latest_ohlcv(pairlist + helping_pairs) + else: + self._exchange.refresh_latest_ohlcv(pairlist) @property def available_pairs(self) -> List[Tuple[str, str]]: diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 74d2cc43d..22ccab8c0 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -174,7 +174,8 @@ class FreqtradeBot(object): pair_whitelist_tuple = [(pair, self.config['ticker_interval']) for pair in self.active_pair_whitelist] # Refreshing candles - self.dataprovider.refresh(pair_whitelist_tuple) + self.dataprovider.refresh(pair_whitelist_tuple, + self.strategy.additional_pairs()) # First process current opened trades for trade in trades: diff --git a/freqtrade/tests/data/test_dataprovider.py b/freqtrade/tests/data/test_dataprovider.py index 834ff94b5..0fed86a4e 100644 --- a/freqtrade/tests/data/test_dataprovider.py +++ b/freqtrade/tests/data/test_dataprovider.py @@ -61,3 +61,33 @@ def test_available_pairs(mocker, default_conf, ticker_history): assert len(dp.available_pairs) == 2 assert dp.available_pairs == [('XRP/BTC', tick_interval), ('UNITTEST/BTC', tick_interval)] + + +def test_refresh(mocker, default_conf, ticker_history): + refresh_mock = MagicMock() + mocker.patch('freqtrade.exchange.Exchange.refresh_latest_ohlcv', refresh_mock) + + exchange = get_patched_exchange(mocker, default_conf, id='binance') + tick_interval = default_conf['ticker_interval'] + pairs = [('XRP/BTC', tick_interval), + ('UNITTEST/BTC', tick_interval), + ] + + pairs_non_trad = [('ETH/USDT', tick_interval), + ('BTC/TUSD', "1h"), + ] + + dp = DataProvider(default_conf, exchange) + dp.refresh(pairs) + + assert refresh_mock.call_count == 1 + assert len(refresh_mock.call_args[0]) == 1 + assert len(refresh_mock.call_args[0][0]) == len(pairs) + assert refresh_mock.call_args[0][0] == pairs + + refresh_mock.reset_mock() + dp.refresh(pairs, pairs_non_trad) + assert refresh_mock.call_count == 1 + assert len(refresh_mock.call_args[0]) == 1 + assert len(refresh_mock.call_args[0][0]) == len(pairs) + len(pairs_non_trad) + assert refresh_mock.call_args[0][0] == pairs + pairs_non_trad