From af3eea38055acdcf533f9810d282205bc315399e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 23 Nov 2019 15:49:46 +0100 Subject: [PATCH] Move config json validation to after strategy loading Otherwise attributes are mandatory in configuration while they could be set in the strategy --- freqtrade/configuration/config_validation.py | 5 +++++ freqtrade/configuration/configuration.py | 8 -------- freqtrade/optimize/backtesting.py | 5 ++++- freqtrade/optimize/edge_cli.py | 5 ++++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/freqtrade/configuration/config_validation.py b/freqtrade/configuration/config_validation.py index 8a7641a08..bfba59385 100644 --- a/freqtrade/configuration/config_validation.py +++ b/freqtrade/configuration/config_validation.py @@ -61,6 +61,11 @@ def validate_config_consistency(conf: Dict[str, Any]) -> None: :param conf: Config in JSON format :return: Returns None if everything is ok, otherwise throw an OperationalException """ + + # validate configuration before returning + logger.info('Validating configuration ...') + validate_config_schema(conf) + # validating trailing stoploss _validate_trailing_stoploss(conf) _validate_edge(conf) diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index 93eee3912..277bf8da9 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -9,8 +9,6 @@ from typing import Any, Callable, Dict, List, Optional from freqtrade import OperationalException, constants from freqtrade.configuration.check_exchange import check_exchange -from freqtrade.configuration.config_validation import (validate_config_consistency, - validate_config_schema) from freqtrade.configuration.deprecated_settings import process_temporary_deprecated_settings from freqtrade.configuration.directory_operations import (create_datadir, create_userdata_dir) @@ -84,10 +82,6 @@ class Configuration: if 'pairlists' not in config: config['pairlists'] = [] - # validate configuration before returning - logger.info('Validating configuration ...') - validate_config_schema(config) - return config def load_config(self) -> Dict[str, Any]: @@ -118,8 +112,6 @@ class Configuration: process_temporary_deprecated_settings(config) - validate_config_consistency(config) - return config def _process_logging_options(self, config: Dict[str, Any]) -> None: diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 2c2d116a4..d9fb1f2d1 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -13,7 +13,8 @@ from pandas import DataFrame from tabulate import tabulate from freqtrade import OperationalException -from freqtrade.configuration import TimeRange, remove_credentials +from freqtrade.configuration import (TimeRange, remove_credentials, + validate_config_consistency) from freqtrade.data import history from freqtrade.data.dataprovider import DataProvider from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds @@ -75,10 +76,12 @@ class Backtesting: stratconf = deepcopy(self.config) stratconf['strategy'] = strat self.strategylist.append(StrategyResolver(stratconf).strategy) + validate_config_consistency(stratconf) else: # No strategy list specified, only one strategy self.strategylist.append(StrategyResolver(self.config).strategy) + validate_config_consistency(self.config) if "ticker_interval" not in self.config: raise OperationalException("Ticker-interval needs to be set in either configuration " diff --git a/freqtrade/optimize/edge_cli.py b/freqtrade/optimize/edge_cli.py index 5a4543884..a667ebb92 100644 --- a/freqtrade/optimize/edge_cli.py +++ b/freqtrade/optimize/edge_cli.py @@ -9,7 +9,8 @@ from typing import Any, Dict from tabulate import tabulate from freqtrade import constants -from freqtrade.configuration import TimeRange, remove_credentials +from freqtrade.configuration import (TimeRange, remove_credentials, + validate_config_consistency) from freqtrade.edge import Edge from freqtrade.exchange import Exchange from freqtrade.resolvers import StrategyResolver @@ -35,6 +36,8 @@ class EdgeCli: self.exchange = Exchange(self.config) self.strategy = StrategyResolver(self.config).strategy + validate_config_consistency(self.config) + self.edge = Edge(config, self.exchange, self.strategy) # Set refresh_pairs to false for edge-cli (it must be true for edge) self.edge._refresh_pairs = False