From fa3c00c673ad5d875b2f131c97a2c4f1013816e7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 22 Mar 2022 07:13:38 +0100 Subject: [PATCH] Remove some default arguments in history_utils --- freqtrade/data/history/history_utils.py | 9 ++++----- freqtrade/edge/edge_positioning.py | 4 ++++ tests/data/test_history.py | 27 ++++++++++++++++--------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/freqtrade/data/history/history_utils.py b/freqtrade/data/history/history_utils.py index 557d2b09b..515a345f1 100644 --- a/freqtrade/data/history/history_utils.py +++ b/freqtrade/data/history/history_utils.py @@ -106,13 +106,13 @@ def load_data(datadir: Path, return result -def refresh_data(datadir: Path, +def refresh_data(*, datadir: Path, timeframe: str, pairs: List[str], exchange: Exchange, data_format: str = None, timerange: Optional[TimeRange] = None, - candle_type: CandleType = CandleType.SPOT + candle_type: CandleType, ) -> None: """ Refresh ohlcv history data for a list of pairs. @@ -139,7 +139,7 @@ def _load_cached_data_for_updating( timeframe: str, timerange: Optional[TimeRange], data_handler: IDataHandler, - candle_type: CandleType = CandleType.SPOT + candle_type: CandleType ) -> Tuple[DataFrame, Optional[int]]: """ Load cached data to download more data. @@ -178,7 +178,7 @@ def _download_pair_history(pair: str, *, new_pairs_days: int = 30, data_handler: IDataHandler = None, timerange: Optional[TimeRange] = None, - candle_type: CandleType = CandleType.SPOT + candle_type: CandleType, ) -> bool: """ Download latest candles from the exchange for the pair and timeframe passed in parameters @@ -202,7 +202,6 @@ def _download_pair_history(pair: str, *, f'candle type: {candle_type} and store in {datadir}.' ) - # data, since_ms = _load_cached_data_for_updating_old(datadir, pair, timeframe, timerange) data, since_ms = _load_cached_data_for_updating(pair, timeframe, timerange, data_handler=data_handler, candle_type=candle_type) diff --git a/freqtrade/edge/edge_positioning.py b/freqtrade/edge/edge_positioning.py index 772cc4293..f38d25188 100644 --- a/freqtrade/edge/edge_positioning.py +++ b/freqtrade/edge/edge_positioning.py @@ -14,6 +14,7 @@ from freqtrade.configuration import TimeRange from freqtrade.constants import DATETIME_PRINT_FORMAT, UNLIMITED_STAKE_AMOUNT from freqtrade.data.history import get_timerange, load_data, refresh_data from freqtrade.enums import RunMode, SellType +from freqtrade.enums.candletype import CandleType from freqtrade.exceptions import OperationalException from freqtrade.exchange.exchange import timeframe_to_seconds from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist @@ -116,6 +117,7 @@ class Edge: timeframe=self.strategy.timeframe, timerange=timerange_startup, data_format=self.config.get('dataformat_ohlcv', 'json'), + candle_type=self.config.get('candle_type_def', CandleType.SPOT), ) # Download informative pairs too res = defaultdict(list) @@ -132,6 +134,7 @@ class Edge: timeframe=timeframe, timerange=timerange_startup, data_format=self.config.get('dataformat_ohlcv', 'json'), + candle_type=self.config.get('candle_type_def', CandleType.SPOT), ) data = load_data( @@ -141,6 +144,7 @@ class Edge: timerange=self._timerange, startup_candles=self.strategy.startup_candle_count, data_format=self.config.get('dataformat_ohlcv', 'json'), + candle_type=self.config.get('candle_type_def', CandleType.SPOT), ) if not data: diff --git a/tests/data/test_history.py b/tests/data/test_history.py index 148b22973..43a3aaefd 100644 --- a/tests/data/test_history.py +++ b/tests/data/test_history.py @@ -144,7 +144,8 @@ def test_load_data_with_new_pair_1min(ohlcv_history_list, mocker, caplog, # download a new pair if refresh_pairs is set refresh_data(datadir=tmpdir1, timeframe='1m', pairs=['MEME/BTC'], - exchange=exchange) + exchange=exchange, candle_type=CandleType.SPOT + ) load_pair_history(datadir=tmpdir1, timeframe='1m', pair='MEME/BTC', candle_type=candle_type) assert file.is_file() assert log_has_re( @@ -222,14 +223,16 @@ def test_load_cached_data_for_updating(mocker, testdatadir) -> None: # timeframe starts earlier than the cached data # should fully update data timerange = TimeRange('date', None, test_data[0][0] / 1000 - 1, 0) - data, start_ts = _load_cached_data_for_updating('UNITTEST/BTC', '1m', timerange, data_handler) + data, start_ts = _load_cached_data_for_updating( + 'UNITTEST/BTC', '1m', timerange, data_handler, CandleType.SPOT) assert data.empty assert start_ts == test_data[0][0] - 1000 # timeframe starts in the center of the cached data # should return the cached data w/o the last item timerange = TimeRange('date', None, test_data[0][0] / 1000 + 1, 0) - data, start_ts = _load_cached_data_for_updating('UNITTEST/BTC', '1m', timerange, data_handler) + data, start_ts = _load_cached_data_for_updating( + 'UNITTEST/BTC', '1m', timerange, data_handler, CandleType.SPOT) assert_frame_equal(data, test_data_df.iloc[:-1]) assert test_data[-2][0] <= start_ts < test_data[-1][0] @@ -237,20 +240,23 @@ def test_load_cached_data_for_updating(mocker, testdatadir) -> None: # timeframe starts after the cached data # should return the cached data w/o the last item timerange = TimeRange('date', None, test_data[-1][0] / 1000 + 100, 0) - data, start_ts = _load_cached_data_for_updating('UNITTEST/BTC', '1m', timerange, data_handler) + data, start_ts = _load_cached_data_for_updating( + 'UNITTEST/BTC', '1m', timerange, data_handler, CandleType.SPOT) assert_frame_equal(data, test_data_df.iloc[:-1]) assert test_data[-2][0] <= start_ts < test_data[-1][0] # no datafile exist # should return timestamp start time timerange = TimeRange('date', None, now_ts - 10000, 0) - data, start_ts = _load_cached_data_for_updating('NONEXIST/BTC', '1m', timerange, data_handler) + data, start_ts = _load_cached_data_for_updating( + 'NONEXIST/BTC', '1m', timerange, data_handler, CandleType.SPOT) assert data.empty assert start_ts == (now_ts - 10000) * 1000 # no datafile exist, no timeframe is set # should return an empty array and None - data, start_ts = _load_cached_data_for_updating('NONEXIST/BTC', '1m', None, data_handler) + data, start_ts = _load_cached_data_for_updating( + 'NONEXIST/BTC', '1m', None, data_handler, CandleType.SPOT) assert data.empty assert start_ts is None @@ -322,9 +328,9 @@ def test_download_pair_history2(mocker, default_conf, testdatadir) -> None: mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=tick) exchange = get_patched_exchange(mocker, default_conf) _download_pair_history(datadir=testdatadir, exchange=exchange, pair="UNITTEST/BTC", - timeframe='1m') + timeframe='1m', candle_type='spot') _download_pair_history(datadir=testdatadir, exchange=exchange, pair="UNITTEST/BTC", - timeframe='3m') + timeframe='3m', candle_type='spot') _download_pair_history(datadir=testdatadir, exchange=exchange, pair="UNITTEST/USDT", timeframe='1h', candle_type='mark') assert json_dump_mock.call_count == 3 @@ -338,7 +344,7 @@ def test_download_backtesting_data_exception(mocker, caplog, default_conf, tmpdi assert not _download_pair_history(datadir=tmpdir1, exchange=exchange, pair='MEME/BTC', - timeframe='1m') + timeframe='1m', candle_type='spot') assert log_has('Failed to download history data for pair: "MEME/BTC", timeframe: 1m.', caplog) @@ -389,7 +395,8 @@ def test_init_with_refresh(default_conf, mocker) -> None: datadir=Path(''), pairs=[], timeframe=default_conf['timeframe'], - exchange=exchange + exchange=exchange, + candle_type=CandleType.SPOT ) assert {} == load_data( datadir=Path(''),