Allow more settings to come from strategy

This commit is contained in:
Matthias 2019-01-13 19:28:20 +01:00
parent ad8b1bbb79
commit 97f6a45819

View File

@ -38,24 +38,38 @@ class StrategyResolver(IResolver):
self.strategy: IStrategy = self._load_strategy(strategy_name, self.strategy: IStrategy = self._load_strategy(strategy_name,
config=config, config=config,
extra_dir=config.get('strategy_path')) extra_dir=config.get('strategy_path'))
# make sure experimental dict is available
if 'experimental' not in config:
config['experimental'] = {}
# Set attributes # Set attributes
# Check if we need to override configuration # Check if we need to override configuration
attributes = ["minimal_roi", # (Attribute name, default, experimental)
"ticker_interval", attributes = [("minimal_roi", None, False),
"stoploss", ("ticker_interval", None, False),
"trailing_stop", ("stoploss", None, False),
"trailing_stop_positive", ("trailing_stop", None, False),
"trailing_stop_positive_offset", ("trailing_stop_positive", None, False),
"process_only_new_candles", ("trailing_stop_positive_offset", 0.0, False),
"order_types", ("process_only_new_candles", None, False),
"order_time_in_force" ("order_types", None, False),
("order_time_in_force", None, False),
("use_sell_signal", False, True),
("sell_profit_only", None, True),
("ignore_roi_if_buy_signal", None, True),
] ]
for attribute in attributes: for attribute, default, experimental in attributes:
self._override_attribute_helper(config, attribute) if experimental:
self._override_attribute_helper(config['experimental'], attribute, default)
else:
self._override_attribute_helper(config, attribute, default)
# Loop this list again to have output combined # Loop this list again to have output combined
for attribute in attributes: for attribute, _, exp in attributes:
if attribute in config: if exp and attribute in config['experimental']:
logger.info("Strategy using %s: %s", attribute, config['experimental'][attribute])
elif attribute in config:
logger.info("Strategy using %s: %s", attribute, config[attribute]) logger.info("Strategy using %s: %s", attribute, config[attribute])
# Sort and apply type conversions # Sort and apply type conversions
@ -66,13 +80,24 @@ class StrategyResolver(IResolver):
self._strategy_sanity_validations() self._strategy_sanity_validations()
def _override_attribute_helper(self, config, attribute: str): def _override_attribute_helper(self, config, attribute: str, default):
"""
Override attributes in the strategy.
Prevalence:
- Configuration
- Strategy
- default (if not None)
"""
if attribute in config: if attribute in config:
setattr(self.strategy, attribute, config[attribute]) setattr(self.strategy, attribute, config[attribute])
logger.info("Override strategy '%s' with value in config file: %s.", logger.info("Override strategy '%s' with value in config file: %s.",
attribute, config[attribute]) attribute, config[attribute])
elif hasattr(self.strategy, attribute): elif hasattr(self.strategy, attribute):
config[attribute] = getattr(self.strategy, attribute) config[attribute] = getattr(self.strategy, attribute)
# Explicitly check for None here as other "falsy" values are possible
elif default is not None:
setattr(self.strategy, attribute, default)
config[attribute] = default
def _strategy_sanity_validations(self): def _strategy_sanity_validations(self):
if not all(k in self.strategy.order_types for k in constants.REQUIRED_ORDERTYPES): if not all(k in self.strategy.order_types for k in constants.REQUIRED_ORDERTYPES):