Don't load protections from config if strategy defines a property
This commit is contained in:
parent
8562e19776
commit
e1010ff592
@ -70,7 +70,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
|
|
||||||
PairLocks.timeframe = self.config['timeframe']
|
PairLocks.timeframe = self.config['timeframe']
|
||||||
|
|
||||||
self.protections = ProtectionManager(self.config)
|
self.protections = ProtectionManager(self.config, self.strategy.protections)
|
||||||
|
|
||||||
# RPC runs in separate threads, can start handling external commands just after
|
# RPC runs in separate threads, can start handling external commands just after
|
||||||
# initialization, even before Freqtradebot has a chance to start its throttling,
|
# initialization, even before Freqtradebot has a chance to start its throttling,
|
||||||
|
@ -137,7 +137,7 @@ class Backtesting:
|
|||||||
if hasattr(strategy, 'protections'):
|
if hasattr(strategy, 'protections'):
|
||||||
conf = deepcopy(conf)
|
conf = deepcopy(conf)
|
||||||
conf['protections'] = strategy.protections
|
conf['protections'] = strategy.protections
|
||||||
self.protections = ProtectionManager(conf)
|
self.protections = ProtectionManager(self.config, strategy.protections)
|
||||||
|
|
||||||
def load_bt_data(self) -> Tuple[Dict[str, DataFrame], TimeRange]:
|
def load_bt_data(self) -> Tuple[Dict[str, DataFrame], TimeRange]:
|
||||||
"""
|
"""
|
||||||
|
@ -15,11 +15,11 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class ProtectionManager():
|
class ProtectionManager():
|
||||||
|
|
||||||
def __init__(self, config: dict) -> None:
|
def __init__(self, config: Dict, protections: List) -> None:
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
self._protection_handlers: List[IProtection] = []
|
self._protection_handlers: List[IProtection] = []
|
||||||
for protection_handler_config in self._config.get('protections', []):
|
for protection_handler_config in protections:
|
||||||
protection_handler = ProtectionResolver.load_protection(
|
protection_handler = ProtectionResolver.load_protection(
|
||||||
protection_handler_config['method'],
|
protection_handler_config['method'],
|
||||||
config=config,
|
config=config,
|
||||||
|
@ -113,7 +113,9 @@ class StrategyResolver(IResolver):
|
|||||||
- Strategy
|
- Strategy
|
||||||
- default (if not None)
|
- default (if not None)
|
||||||
"""
|
"""
|
||||||
if attribute in config:
|
if (attribute in config
|
||||||
|
and not isinstance(getattr(type(strategy), 'my_property', None), property)):
|
||||||
|
# Ensure Properties are not overwritten
|
||||||
setattr(strategy, attribute, config[attribute])
|
setattr(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])
|
||||||
|
@ -107,7 +107,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
startup_candle_count: int = 0
|
startup_candle_count: int = 0
|
||||||
|
|
||||||
# Protections
|
# Protections
|
||||||
protections: List
|
protections: List = []
|
||||||
|
|
||||||
# Class level variables (intentional) containing
|
# Class level variables (intentional) containing
|
||||||
# the dataprovider (dp) (access to other candles, historic data, ...)
|
# the dataprovider (dp) (access to other candles, historic data, ...)
|
||||||
|
@ -70,8 +70,7 @@ def test_protectionmanager(mocker, default_conf):
|
|||||||
])
|
])
|
||||||
def test_protections_init(mocker, default_conf, timeframe, expected, protconf):
|
def test_protections_init(mocker, default_conf, timeframe, expected, protconf):
|
||||||
default_conf['timeframe'] = timeframe
|
default_conf['timeframe'] = timeframe
|
||||||
default_conf['protections'] = protconf
|
man = ProtectionManager(default_conf, protconf)
|
||||||
man = ProtectionManager(default_conf)
|
|
||||||
assert len(man._protection_handlers) == len(protconf)
|
assert len(man._protection_handlers) == len(protconf)
|
||||||
assert man._protection_handlers[0]._lookback_period == expected[0]
|
assert man._protection_handlers[0]._lookback_period == expected[0]
|
||||||
assert man._protection_handlers[0]._stop_duration == expected[1]
|
assert man._protection_handlers[0]._stop_duration == expected[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user