diff --git a/freqtrade/optimize/__init__.py b/freqtrade/optimize/__init__.py index a0eb5b8a2..803c721a9 100644 --- a/freqtrade/optimize/__init__.py +++ b/freqtrade/optimize/__init__.py @@ -10,6 +10,7 @@ from freqtrade.analyze import populate_indicators, parse_ticker_dataframe from freqtrade import misc from user_data.hyperopt_conf import hyperopt_optimize_conf +import gzip logger = logging.getLogger(__name__) @@ -38,13 +39,19 @@ def load_tickerdata_file(datadir, pair, ticker_interval, pair=pair, ticker_interval=ticker_interval, ) - # The file does not exist we download it - if not os.path.isfile(file): + gzipfile = file + '.gz' + + # If the file does not exist we download it when None is returned. + # If file exists, read the file, load the json + if os.path.isfile(gzipfile): + with gzip.open(gzipfile) as tickerdata: + pairdata = json.load(tickerdata) + elif os.path.isfile(file): + with open(file) as tickerdata: + pairdata = json.load(tickerdata) + else: return None - # Read the file, load the json - with open(file) as tickerdata: - pairdata = json.load(tickerdata) if timerange: pairdata = trim_tickerlist(pairdata, timerange) return pairdata diff --git a/freqtrade/tests/optimize/test_optimize.py b/freqtrade/tests/optimize/test_optimize.py index 646959669..808e4aa70 100644 --- a/freqtrade/tests/optimize/test_optimize.py +++ b/freqtrade/tests/optimize/test_optimize.py @@ -202,9 +202,14 @@ def test_download_backtesting_testdata2(mocker): def test_load_tickerdata_file(): + # 7 does not exist in either format. assert not load_tickerdata_file(None, 'BTC_UNITEST', 7) + # 1 exists only as a .json tickerdata = load_tickerdata_file(None, 'BTC_UNITEST', 1) assert _BTC_UNITTEST_LENGTH == len(tickerdata) + # 8 .json is empty and will fail if it's loaded. .json.gz is a copy of 1.json + tickerdata = load_tickerdata_file(None, 'BTC_UNITEST', 8) + assert _BTC_UNITTEST_LENGTH == len(tickerdata) def test_init(default_conf, mocker): diff --git a/freqtrade/tests/testdata/BTC_UNITEST-8.json b/freqtrade/tests/testdata/BTC_UNITEST-8.json new file mode 100644 index 000000000..e4766ad4f --- /dev/null +++ b/freqtrade/tests/testdata/BTC_UNITEST-8.json @@ -0,0 +1,3 @@ +[ + {"O": 0.00162008, "H": 0.00162008, "L": 0.00162008, "C": 0.00162008, "V": 108.14853839, "T": "2017-11-04T23:02:00", "BV": 0.17520927} +] \ No newline at end of file diff --git a/freqtrade/tests/testdata/BTC_UNITEST-8.json.gz b/freqtrade/tests/testdata/BTC_UNITEST-8.json.gz new file mode 100644 index 000000000..38194582c Binary files /dev/null and b/freqtrade/tests/testdata/BTC_UNITEST-8.json.gz differ