From b578e3125570e49a0f0d1c75d332ac2f4b1eac87 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 3 Dec 2021 07:20:00 +0100 Subject: [PATCH] Align tests to have futures data in futures/ directory --- freqtrade/data/history/hdf5datahandler.py | 1 + freqtrade/data/history/idatahandler.py | 3 +- freqtrade/data/history/jsondatahandler.py | 1 + tests/commands/test_commands.py | 25 ++++++++++++--- tests/data/test_history.py | 32 +++++++++++-------- tests/rpc/test_rpc_apiserver.py | 2 +- .../{ => futures}/UNITTEST_USDT-1h-mark.json | 0 .../{ => futures}/XRP_USDT-1h-mark.json | 0 tests/testdata/{ => futures}/XRP_USDT-1h.json | 0 9 files changed, 45 insertions(+), 19 deletions(-) rename tests/testdata/{ => futures}/UNITTEST_USDT-1h-mark.json (100%) rename tests/testdata/{ => futures}/XRP_USDT-1h-mark.json (100%) rename tests/testdata/{ => futures}/XRP_USDT-1h.json (100%) diff --git a/freqtrade/data/history/hdf5datahandler.py b/freqtrade/data/history/hdf5datahandler.py index a390e887a..e8fcad70d 100644 --- a/freqtrade/data/history/hdf5datahandler.py +++ b/freqtrade/data/history/hdf5datahandler.py @@ -50,6 +50,7 @@ class HDF5DataHandler(IDataHandler): """ if candle_type: + datadir = datadir.joinpath('futures') candle_type = f"-{candle_type}" else: candle_type = "" diff --git a/freqtrade/data/history/idatahandler.py b/freqtrade/data/history/idatahandler.py index 2d7df6ca5..bb5e83c5d 100644 --- a/freqtrade/data/history/idatahandler.py +++ b/freqtrade/data/history/idatahandler.py @@ -200,7 +200,8 @@ class IDataHandler(ABC): if candle_type: datadir = datadir.joinpath('futures') candle_type = f"-{candle_type}" - filename = datadir.joinpath(f'{pair_s}-{timeframe}{candle_type}.{cls._get_file_extension()}') + filename = datadir.joinpath( + f'{pair_s}-{timeframe}{candle_type}.{cls._get_file_extension()}') return filename @classmethod diff --git a/freqtrade/data/history/jsondatahandler.py b/freqtrade/data/history/jsondatahandler.py index deacda338..00ba5d095 100644 --- a/freqtrade/data/history/jsondatahandler.py +++ b/freqtrade/data/history/jsondatahandler.py @@ -50,6 +50,7 @@ class JsonDataHandler(IDataHandler): :return: List of Pairs """ if candle_type: + datadir = datadir.joinpath('futures') candle_type = f"-{candle_type}" else: candle_type = "" diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 1981e9413..5e5cb3c2f 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -1338,10 +1338,9 @@ def test_start_list_data(testdatadir, capsys): pargs['config'] = None start_list_data(pargs) captured = capsys.readouterr() - assert "Found 20 pair / timeframe combinations." in captured.out - assert "\n| Pair | Timeframe | Type |\n" in captured.out - assert "\n| UNITTEST/BTC | 1m, 5m, 8m, 30m | |\n" in captured.out - assert "\n| UNITTEST/USDT | 1h | mark |\n" in captured.out + assert "Found 17 pair / timeframe combinations." in captured.out + assert "\n| Pair | Timeframe | Type |\n" in captured.out + assert "\n| UNITTEST/BTC | 1m, 5m, 8m, 30m | |\n" in captured.out args = [ "list-data", @@ -1360,6 +1359,24 @@ def test_start_list_data(testdatadir, capsys): assert "UNITTEST/BTC" not in captured.out assert "\n| XRP/ETH | 1m, 5m | |\n" in captured.out + args = [ + "list-data", + "--data-format-ohlcv", + "json", + "--trading-mode", "futures", + "--datadir", + str(testdatadir), + ] + pargs = get_args(args) + pargs['config'] = None + start_list_data(pargs) + captured = capsys.readouterr() + + assert "Found 3 pair / timeframe combinations." in captured.out + assert "\n| Pair | Timeframe | Type |\n" in captured.out + assert "\n| XRP/USDT | 1h | |\n" in captured.out + assert "\n| XRP/USDT | 1h | mark |\n" in captured.out + @pytest.mark.usefixtures("init_persistence") # TODO-lev: Short trades? diff --git a/tests/data/test_history.py b/tests/data/test_history.py index bf3c1a1de..a36f933c9 100644 --- a/tests/data/test_history.py +++ b/tests/data/test_history.py @@ -98,7 +98,7 @@ def test_load_data_1min_timeframe(ohlcv_history, mocker, caplog, testdatadir) -> def test_load_data_mark(ohlcv_history, mocker, caplog, testdatadir) -> None: mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=ohlcv_history) - file = testdatadir / 'UNITTEST_USDT-1h-mark.json' + file = testdatadir / 'futures/UNITTEST_USDT-1h-mark.json' load_data(datadir=testdatadir, timeframe='1h', pairs=['UNITTEST/BTC'], candle_type='mark') assert file.is_file() assert not log_has( @@ -163,8 +163,8 @@ def test_testdata_path(testdatadir) -> None: (".XBTBON2H", 'freqtrade/hello/world/_XBTBON2H-5m.json', ""), ("ETHUSD.d", 'freqtrade/hello/world/ETHUSD_d-5m.json', ""), ("ACC_OLD/BTC", 'freqtrade/hello/world/ACC_OLD_BTC-5m.json', ""), - ("ETH/BTC", 'freqtrade/hello/world/ETH_BTC-5m-mark.json', "mark"), - ("ACC_OLD/BTC", 'freqtrade/hello/world/ACC_OLD_BTC-5m-index.json', "index"), + ("ETH/BTC", 'freqtrade/hello/world/futures/ETH_BTC-5m-mark.json', "mark"), + ("ACC_OLD/BTC", 'freqtrade/hello/world/futures/ACC_OLD_BTC-5m-index.json', "index"), ]) def test_json_pair_data_filename(pair, expected_result, candle_type): fn = JsonDataHandler._pair_data_filename( @@ -254,9 +254,9 @@ def test_load_cached_data_for_updating(mocker, testdatadir) -> None: assert start_ts is None -@pytest.mark.parametrize('candle_type, file_tail', [ - ('mark', '-mark'), - ('', ''), +@pytest.mark.parametrize('candle_type,subdir,file_tail', [ + ('mark', 'futures/', '-mark'), + ('', '', ''), ]) def test_download_pair_history( ohlcv_history_list, @@ -264,15 +264,16 @@ def test_download_pair_history( default_conf, tmpdir, candle_type, + subdir, file_tail ) -> None: mocker.patch('freqtrade.exchange.Exchange.get_historic_ohlcv', return_value=ohlcv_history_list) exchange = get_patched_exchange(mocker, default_conf) tmpdir1 = Path(tmpdir) - file1_1 = tmpdir1 / f'MEME_BTC-1m{file_tail}.json' - file1_5 = tmpdir1 / f'MEME_BTC-5m{file_tail}.json' - file2_1 = tmpdir1 / f'CFI_BTC-1m{file_tail}.json' - file2_5 = tmpdir1 / f'CFI_BTC-5m{file_tail}.json' + file1_1 = tmpdir1 / f'{subdir}MEME_BTC-1m{file_tail}.json' + file1_5 = tmpdir1 / f'{subdir}MEME_BTC-5m{file_tail}.json' + file2_1 = tmpdir1 / f'{subdir}CFI_BTC-1m{file_tail}.json' + file2_5 = tmpdir1 / f'{subdir}CFI_BTC-5m{file_tail}.json' assert not file1_1.is_file() assert not file2_1.is_file() @@ -707,7 +708,7 @@ def test_rebuild_pair_from_filename(input, expected): def test_datahandler_ohlcv_get_available_data(testdatadir): - paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir) + paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, 'spot') # Convert to set to avoid failures due to sorting assert set(paircombs) == { ('UNITTEST/BTC', '5m', ''), @@ -727,14 +728,19 @@ def test_datahandler_ohlcv_get_available_data(testdatadir): ('UNITTEST/BTC', '30m', ''), ('UNITTEST/BTC', '8m', ''), ('NOPAIR/XXX', '4m', ''), + } + + paircombs = JsonDataHandler.ohlcv_get_available_data(testdatadir, 'futures') + # Convert to set to avoid failures due to sorting + assert set(paircombs) == { ('UNITTEST/USDT', '1h', 'mark'), ('XRP/USDT', '1h', ''), ('XRP/USDT', '1h', 'mark'), } - paircombs = JsonGzDataHandler.ohlcv_get_available_data(testdatadir) + paircombs = JsonGzDataHandler.ohlcv_get_available_data(testdatadir, 'spot') assert set(paircombs) == {('UNITTEST/BTC', '8m', '')} - paircombs = HDF5DataHandler.ohlcv_get_available_data(testdatadir) + paircombs = HDF5DataHandler.ohlcv_get_available_data(testdatadir, 'spot') assert set(paircombs) == {('UNITTEST/BTC', '5m', '')} diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index a62b1f2c5..75455982e 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -1334,7 +1334,7 @@ def test_list_available_pairs(botclient): rc = client_get(client, f"{BASE_URI}/available_pairs") assert_response(rc) - assert rc.json()['length'] == 14 + assert rc.json()['length'] == 13 assert isinstance(rc.json()['pairs'], list) rc = client_get(client, f"{BASE_URI}/available_pairs?timeframe=5m") diff --git a/tests/testdata/UNITTEST_USDT-1h-mark.json b/tests/testdata/futures/UNITTEST_USDT-1h-mark.json similarity index 100% rename from tests/testdata/UNITTEST_USDT-1h-mark.json rename to tests/testdata/futures/UNITTEST_USDT-1h-mark.json diff --git a/tests/testdata/XRP_USDT-1h-mark.json b/tests/testdata/futures/XRP_USDT-1h-mark.json similarity index 100% rename from tests/testdata/XRP_USDT-1h-mark.json rename to tests/testdata/futures/XRP_USDT-1h-mark.json diff --git a/tests/testdata/XRP_USDT-1h.json b/tests/testdata/futures/XRP_USDT-1h.json similarity index 100% rename from tests/testdata/XRP_USDT-1h.json rename to tests/testdata/futures/XRP_USDT-1h.json