From eb08b921802a6db6c2faa53df36e501a4a64e4af Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Mar 2022 09:01:18 +0100 Subject: [PATCH] Raise exception when ticker_interval is set. --- freqtrade/configuration/deprecated_settings.py | 11 +++-------- tests/optimize/test_backtesting.py | 9 ++++----- tests/optimize/test_edge_cli.py | 4 +--- tests/optimize/test_hyperopt.py | 1 - tests/strategy/test_strategy_loading.py | 2 -- tests/test_arguments.py | 6 +++--- tests/test_configuration.py | 16 ++++------------ 7 files changed, 15 insertions(+), 34 deletions(-) diff --git a/freqtrade/configuration/deprecated_settings.py b/freqtrade/configuration/deprecated_settings.py index 5efe26bd2..cafa8957b 100644 --- a/freqtrade/configuration/deprecated_settings.py +++ b/freqtrade/configuration/deprecated_settings.py @@ -100,16 +100,11 @@ def process_temporary_deprecated_settings(config: Dict[str, Any]) -> None: "from the edge configuration." ) if 'ticker_interval' in config: - logger.warning( - "DEPRECATED: " + + raise OperationalException( + "DEPRECATED: 'ticker_interval' detected. " "Please use 'timeframe' instead of 'ticker_interval." ) - if 'timeframe' in config: - raise OperationalException( - "Both 'timeframe' and 'ticker_interval' detected." - "Please remove 'ticker_interval' from your configuration to continue operating." - ) - config['timeframe'] = config['ticker_interval'] if 'protections' in config: logger.warning("DEPRECATED: Setting 'protections' in the configuration is deprecated.") diff --git a/tests/optimize/test_backtesting.py b/tests/optimize/test_backtesting.py index a8998eb63..7a72747c0 100644 --- a/tests/optimize/test_backtesting.py +++ b/tests/optimize/test_backtesting.py @@ -314,16 +314,15 @@ def test_backtesting_init_no_timeframe(mocker, default_conf, caplog) -> None: patch_exchange(mocker) del default_conf['timeframe'] default_conf['strategy_list'] = ['StrategyTestV2', - 'SampleStrategy'] + 'HyperoptableStrategy'] mocker.patch('freqtrade.exchange.Exchange.get_fee', MagicMock(return_value=0.5)) - with pytest.raises(OperationalException): + with pytest.raises(OperationalException, + match=r"Timeframe needs to be set in either configuration"): Backtesting(default_conf) - log_has("Ticker-interval needs to be set in either configuration " - "or as cli argument `--ticker-interval 5m`", caplog) -def test_data_with_fee(default_conf, mocker, testdatadir) -> None: +def test_data_with_fee(default_conf, mocker) -> None: patch_exchange(mocker) default_conf['fee'] = 0.1234 diff --git a/tests/optimize/test_edge_cli.py b/tests/optimize/test_edge_cli.py index 18d5f1c76..466a5f1cd 100644 --- a/tests/optimize/test_edge_cli.py +++ b/tests/optimize/test_edge_cli.py @@ -6,8 +6,7 @@ from unittest.mock import MagicMock from freqtrade.commands.optimize_commands import setup_optimize_configuration, start_edge from freqtrade.enums import RunMode from freqtrade.optimize.edge_cli import EdgeCli -from tests.conftest import (get_args, log_has, log_has_re, patch_exchange, - patched_configuration_load_config_file) +from tests.conftest import get_args, log_has, patch_exchange, patched_configuration_load_config_file def test_setup_optimize_configuration_without_arguments(mocker, default_conf, caplog) -> None: @@ -30,7 +29,6 @@ def test_setup_optimize_configuration_without_arguments(mocker, default_conf, ca assert 'datadir' in config assert log_has('Using data directory: {} ...'.format(config['datadir']), caplog) assert 'timeframe' in config - assert not log_has_re('Parameter -i/--ticker-interval detected .*', caplog) assert 'timerange' not in config assert 'stoploss_range' not in config diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index 2328585dd..cc551277a 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -63,7 +63,6 @@ def test_setup_hyperopt_configuration_without_arguments(mocker, default_conf, ca assert 'datadir' in config assert log_has('Using data directory: {} ...'.format(config['datadir']), caplog) assert 'timeframe' in config - assert not log_has_re('Parameter -i/--ticker-interval detected .*', caplog) assert 'position_stacking' not in config assert not log_has('Parameter --enable-position-stacking detected ...', caplog) diff --git a/tests/strategy/test_strategy_loading.py b/tests/strategy/test_strategy_loading.py index 3590c3e01..3fe14a8de 100644 --- a/tests/strategy/test_strategy_loading.py +++ b/tests/strategy/test_strategy_loading.py @@ -111,7 +111,6 @@ def test_strategy(result, default_conf): assert default_conf['stoploss'] == -0.10 assert strategy.timeframe == '5m' - assert strategy.ticker_interval == '5m' assert default_conf['timeframe'] == '5m' df_indicators = strategy.advise_indicators(result, metadata=metadata) @@ -376,7 +375,6 @@ def test_call_deprecated_function(result, monkeypatch, default_conf, caplog): assert strategy._sell_fun_len == 2 assert strategy.INTERFACE_VERSION == 1 assert strategy.timeframe == '5m' - assert strategy.ticker_interval == '5m' indicator_df = strategy.advise_indicators(result, metadata=metadata) assert isinstance(indicator_df, DataFrame) diff --git a/tests/test_arguments.py b/tests/test_arguments.py index fca5c6ab9..ba9d154e5 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -111,17 +111,17 @@ def test_parse_args_strategy_path_invalid() -> None: def test_parse_args_backtesting_invalid() -> None: with pytest.raises(SystemExit, match=r'2'): - Arguments(['backtesting --ticker-interval']).get_parsed_arg() + Arguments(['backtesting --timeframe']).get_parsed_arg() with pytest.raises(SystemExit, match=r'2'): - Arguments(['backtesting --ticker-interval', 'abc']).get_parsed_arg() + Arguments(['backtesting --timeframe', 'abc']).get_parsed_arg() def test_parse_args_backtesting_custom() -> None: args = [ 'backtesting', '-c', 'test_conf.json', - '--ticker-interval', '1m', + '--timeframe', '1m', '--strategy-list', 'StrategyTestV2', 'SampleStrategy' diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 0a6935649..1cd9b0ff7 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -443,7 +443,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non '--strategy', 'StrategyTestV2', '--datadir', '/foo/bar', '--userdir', "/tmp/freqtrade", - '--ticker-interval', '1m', + '--timeframe', '1m', '--enable-position-stacking', '--disable-max-market-positions', '--timerange', ':100', @@ -494,7 +494,7 @@ def test_setup_configuration_with_stratlist(mocker, default_conf, caplog) -> Non arglist = [ 'backtesting', '--config', 'config.json', - '--ticker-interval', '1m', + '--timeframe', '1m', '--export', 'trades', '--strategy-list', 'StrategyTestV2', @@ -1320,22 +1320,14 @@ def test_process_removed_setting(mocker, default_conf, caplog): def test_process_deprecated_ticker_interval(default_conf, caplog): message = "DEPRECATED: Please use 'timeframe' instead of 'ticker_interval." config = deepcopy(default_conf) + process_temporary_deprecated_settings(config) assert not log_has(message, caplog) del config['timeframe'] config['ticker_interval'] = '15m' - process_temporary_deprecated_settings(config) - assert log_has(message, caplog) - assert config['ticker_interval'] == '15m' - - config = deepcopy(default_conf) - # Have both timeframe and ticker interval in config - # Can also happen when using ticker_interval in configuration, and --timeframe as cli argument - config['timeframe'] = '5m' - config['ticker_interval'] = '4h' with pytest.raises(OperationalException, - match=r"Both 'timeframe' and 'ticker_interval' detected."): + match=r"DEPRECATED: 'ticker_interval' detected. Please use.*"): process_temporary_deprecated_settings(config)