From 4351a26b4cc84abfab5b0fd901c60918d488175e Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 27 Nov 2020 10:32:23 +0100 Subject: [PATCH] Move stop_duration to parent class avoids reimplementation and enhances standardization --- docs/developer.md | 3 +++ freqtrade/plugins/protections/cooldown_period.py | 2 -- freqtrade/plugins/protections/iprotection.py | 2 ++ freqtrade/plugins/protections/low_profit_pairs.py | 1 - freqtrade/plugins/protections/stoploss_guard.py | 1 - 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/developer.md b/docs/developer.md index 86e9b1078..ebfe8e013 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -200,6 +200,9 @@ For that reason, they must implement the following methods: The `until` portion should be calculated using the provided `calculate_lock_end()` method. +All Protections should use `"stop_duration"` to define how long a a pair (or all pairs) should be locked. +The content of this is made available as `self._stop_duration` to the each Protection. + #### Global vs. local stops Protections can have 2 different ways to stop trading for a limited : diff --git a/freqtrade/plugins/protections/cooldown_period.py b/freqtrade/plugins/protections/cooldown_period.py index 1abec7218..18a73ef5b 100644 --- a/freqtrade/plugins/protections/cooldown_period.py +++ b/freqtrade/plugins/protections/cooldown_period.py @@ -20,8 +20,6 @@ class CooldownPeriod(IProtection): def __init__(self, config: Dict[str, Any], protection_config: Dict[str, Any]) -> None: super().__init__(config, protection_config) - self._stop_duration = protection_config.get('stop_duration', 60) - def _reason(self) -> str: """ LockReason to use diff --git a/freqtrade/plugins/protections/iprotection.py b/freqtrade/plugins/protections/iprotection.py index 0f539bbd3..2053ae741 100644 --- a/freqtrade/plugins/protections/iprotection.py +++ b/freqtrade/plugins/protections/iprotection.py @@ -23,6 +23,8 @@ class IProtection(LoggingMixin, ABC): def __init__(self, config: Dict[str, Any], protection_config: Dict[str, Any]) -> None: self._config = config self._protection_config = protection_config + self._stop_duration = protection_config.get('stop_duration', 60) + LoggingMixin.__init__(self, logger) @property diff --git a/freqtrade/plugins/protections/low_profit_pairs.py b/freqtrade/plugins/protections/low_profit_pairs.py index c45ba3a39..cd850ca0c 100644 --- a/freqtrade/plugins/protections/low_profit_pairs.py +++ b/freqtrade/plugins/protections/low_profit_pairs.py @@ -22,7 +22,6 @@ class LowProfitPairs(IProtection): self._lookback_period = protection_config.get('lookback_period', 60) self._trade_limit = protection_config.get('trade_limit', 1) - self._stop_duration = protection_config.get('stop_duration', 60) self._required_profit = protection_config.get('required_profit', 0.0) def short_desc(self) -> str: diff --git a/freqtrade/plugins/protections/stoploss_guard.py b/freqtrade/plugins/protections/stoploss_guard.py index 1ad839f3d..65403d683 100644 --- a/freqtrade/plugins/protections/stoploss_guard.py +++ b/freqtrade/plugins/protections/stoploss_guard.py @@ -25,7 +25,6 @@ class StoplossGuard(IProtection): self._lookback_period = protection_config.get('lookback_period', 60) self._trade_limit = protection_config.get('trade_limit', 10) - self._stop_duration = protection_config.get('stop_duration', 60) self._disable_global_stop = protection_config.get('only_per_pair', False) def short_desc(self) -> str: