From 12a9fda8851bd64de1328bedd57cb5497eb218f9 Mon Sep 17 00:00:00 2001 From: robcaulk Date: Sat, 17 Sep 2022 17:36:48 +0200 Subject: [PATCH] fix spice-rack test --- freqtrade/strategy/interface.py | 12 +++++++++++- tests/freqai/test_freqai_interface.py | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index f4b30ccde..9ab3b7eba 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -205,12 +205,22 @@ class IStrategy(ABC, HyperStrategyMixin): new_corr_pairs = [] new_tfs = [] + if not self.dp: + logger.warning('No dataprovider available.') + config['freqai']['enabled'] = False + return config # find the closest pairs to what the default config wants for pair in corr_pairs: closest_pair = difflib.get_close_matches( pair, self.dp._exchange.markets # type: ignore - )[0] + ) + if not closest_pair: + logger.warning(f'Could not find {pair} in markets, removing from ' + f'corr_pairlist.') + else: + closest_pair = closest_pair[0] + new_corr_pairs.append(closest_pair) logger.info(f'Spice rack will use {closest_pair} as informative in FreqAI model.') diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index 70d6f1d7d..0ad49dac9 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -318,6 +318,11 @@ def test_principal_component_analysis(mocker, freqai_conf): def test_spice_rack(mocker, default_conf, tmpdir): + + strategy = get_patched_freqai_strategy(mocker, default_conf) + exchange = get_patched_exchange(mocker, default_conf) + strategy.dp = DataProvider(default_conf, exchange) + default_conf.update({"freqai_spice_rack": "true"}) default_conf.update({"freqai_config": "test_config.json"}) default_conf.update({"freqai_identifier": "spicy-id"}) @@ -330,6 +335,8 @@ def test_spice_rack(mocker, default_conf, tmpdir): default_conf["user_data_dir"] = Path(tmpdir) freqai_conf = copy.deepcopy(default_conf) - _ = get_patched_freqai_strategy(mocker, freqai_conf) + strategy.config = freqai_conf + strategy.load_freqAI_model() assert 'freqai' in freqai_conf + assert strategy.freqai