From e1cb0dbf28cd0ba1c19ccfa33e040d47a6783116 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 21 May 2018 22:31:08 +0300 Subject: [PATCH 1/2] Do not try to redownload pair data if --refresh-pairs-cached is not set --- freqtrade/optimize/__init__.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/freqtrade/optimize/__init__.py b/freqtrade/optimize/__init__.py index 168481920..ab7a6be43 100644 --- a/freqtrade/optimize/__init__.py +++ b/freqtrade/optimize/__init__.py @@ -29,7 +29,7 @@ def trim_tickerlist(tickerlist: List[Dict], timerange: Tuple[Tuple, int, int]) - if stype[0] == 'index': start_index = start elif stype[0] == 'date': - while tickerlist[start_index][0] < start * 1000: + while start_index < len(tickerlist) and tickerlist[start_index][0] < start * 1000: start_index += 1 if stype[1] == 'line': @@ -37,7 +37,7 @@ def trim_tickerlist(tickerlist: List[Dict], timerange: Tuple[Tuple, int, int]) - if stype[1] == 'index': stop_index = stop elif stype[1] == 'date': - while tickerlist[stop_index-1][0] > stop * 1000: + while stop_index > 0 and tickerlist[stop_index-1][0] > stop * 1000: stop_index -= 1 if start_index > stop_index: @@ -100,15 +100,11 @@ def load_data(datadir: str, for pair in _pairs: pairdata = load_tickerdata_file(datadir, pair, ticker_interval, timerange=timerange) - if not pairdata: - # download the tickerdata from exchange - download_backtesting_testdata(datadir, - pair=pair, - tick_interval=ticker_interval, - timerange=timerange) - # and retry reading the pair - pairdata = load_tickerdata_file(datadir, pair, ticker_interval, timerange=timerange) - result[pair] = pairdata + if pairdata: + result[pair] = pairdata + else: + logger.warn('No data for pair %s, use --update-pairs-cached to download the data', pair) + return result From 8c22cfce37cb945ef0c31804cc8056c69d7f1786 Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 21 May 2018 23:15:01 +0300 Subject: [PATCH 2/2] Fix tests; fix codestyle --- freqtrade/optimize/__init__.py | 2 +- freqtrade/tests/optimize/test_optimize.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/freqtrade/optimize/__init__.py b/freqtrade/optimize/__init__.py index ab7a6be43..f6f1ba47a 100644 --- a/freqtrade/optimize/__init__.py +++ b/freqtrade/optimize/__init__.py @@ -104,7 +104,7 @@ def load_data(datadir: str, result[pair] = pairdata else: logger.warn('No data for pair %s, use --update-pairs-cached to download the data', pair) - + return result diff --git a/freqtrade/tests/optimize/test_optimize.py b/freqtrade/tests/optimize/test_optimize.py index e7f3b18fd..8624b500d 100644 --- a/freqtrade/tests/optimize/test_optimize.py +++ b/freqtrade/tests/optimize/test_optimize.py @@ -99,7 +99,20 @@ def test_load_data_with_new_pair_1min(ticker_history, mocker, caplog) -> None: file = os.path.join(os.path.dirname(__file__), '..', 'testdata', 'MEME_BTC-1m.json') _backup_file(file) - optimize.load_data(None, ticker_interval='1m', pairs=['MEME/BTC']) + # do not download a new pair if refresh_pairs isn't set + optimize.load_data(None, + ticker_interval='1m', + refresh_pairs=False, + pairs=['MEME/BTC']) + assert os.path.isfile(file) is False + assert log_has('No data for pair MEME/BTC, use --update-pairs-cached to download the data', + caplog.record_tuples) + + # download a new pair if refresh_pairs is set + optimize.load_data(None, + ticker_interval='1m', + refresh_pairs=True, + pairs=['MEME/BTC']) assert os.path.isfile(file) is True assert log_has('Download the pair: "MEME/BTC", Interval: 1m', caplog.record_tuples) _clean_test_file(file)