From 09fe3c6f5e1f9f0a42882782e3caac6607e34600 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 2 Jun 2020 09:50:56 +0200 Subject: [PATCH] create compatibility code --- freqtrade/configuration/deprecated_settings.py | 6 ++++++ freqtrade/constants.py | 1 - freqtrade/resolvers/strategy_resolver.py | 11 +++++++++++ freqtrade/strategy/interface.py | 4 ++-- tests/strategy/test_default_strategy.py | 1 - 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/freqtrade/configuration/deprecated_settings.py b/freqtrade/configuration/deprecated_settings.py index 3999ea422..2d5dba9ca 100644 --- a/freqtrade/configuration/deprecated_settings.py +++ b/freqtrade/configuration/deprecated_settings.py @@ -67,3 +67,9 @@ def process_temporary_deprecated_settings(config: Dict[str, Any]) -> None: "'tradable_balance_ratio' and remove 'capital_available_percentage' " "from the edge configuration." ) + if 'ticker_interval' in config: + logger.warning( + "DEPRECATED: " + "Please use 'timeframe' instead of 'ticker_interval." + ) + config['timeframe'] = config['ticker_interval'] diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 511c2993d..3afb4b0f1 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -71,7 +71,6 @@ CONF_SCHEMA = { 'type': 'object', 'properties': { 'max_open_trades': {'type': ['integer', 'number'], 'minimum': -1}, - 'ticker_interval': {'type': 'string'}, 'timeframe': {'type': 'string'}, 'stake_currency': {'type': 'string'}, 'stake_amount': { diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index 99cf2d785..26bce01ca 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -50,6 +50,14 @@ class StrategyResolver(IResolver): if 'ask_strategy' not in config: config['ask_strategy'] = {} + if hasattr(strategy, 'ticker_interval') and not hasattr(strategy, 'timeframe'): + # Assign ticker_interval to timeframe to keep compatibility + if 'timeframe' not in config: + logger.warning( + "DEPRECATED: Please migrate to using timeframe instead of ticker_interval." + ) + strategy.timeframe = strategy.ticker_interval + # Set attributes # Check if we need to override configuration # (Attribute name, default, subkey) @@ -80,6 +88,9 @@ class StrategyResolver(IResolver): StrategyResolver._override_attribute_helper(strategy, config, attribute, default) + # Assign deprecated variable - to not break users code relying on this. + strategy.ticker_interval = strategy.timeframe + # Loop this list again to have output combined for attribute, _, subkey in attributes: if subkey and attribute in config[subkey]: diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 17c4aa5ca..7bf750249 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -85,8 +85,8 @@ class IStrategy(ABC): trailing_stop_positive_offset: float = 0.0 trailing_only_offset_is_reached = False - # associated ticker interval - ticker_interval: str + # associated timeframe + timeframe: str # Optional order types order_types: Dict = { diff --git a/tests/strategy/test_default_strategy.py b/tests/strategy/test_default_strategy.py index 315f80440..df7e35197 100644 --- a/tests/strategy/test_default_strategy.py +++ b/tests/strategy/test_default_strategy.py @@ -18,7 +18,6 @@ def test_default_strategy(result): metadata = {'pair': 'ETH/BTC'} assert type(strategy.minimal_roi) is dict assert type(strategy.stoploss) is float - assert type(strategy.ticker_interval) is str assert type(strategy.timeframe) is str indicators = strategy.populate_indicators(result, metadata) assert type(indicators) is DataFrame