diff --git a/freqtrade/plugins/protections/cooldown_period.py b/freqtrade/plugins/protections/cooldown_period.py index d9fb5b9a6..3391d175a 100644 --- a/freqtrade/plugins/protections/cooldown_period.py +++ b/freqtrade/plugins/protections/cooldown_period.py @@ -18,23 +18,13 @@ class CooldownPeriod(IProtection): """ LockReason to use """ - reason = "Cooldown period" - - if self.unlock_at_str is not None: - return f"{reason} until {self.unlock_at_str}." - else: - return f"{reason}of {self.stop_duration_str}." + return f"Cooldown period for {self.unlock_reason_time_element}." def short_desc(self) -> str: """ Short method description - used for startup messages """ - result = f"{self.name} - Cooldown period " - - if self.unlock_at_str is not None: - return f"{result} until {self.unlock_at_str}." - else: - return f"{result}of {self.stop_duration_str}." + return f"{self.name} - Cooldown period {self.unlock_reason_time_element}." def _cooldown_period(self, pair: str, date_now: datetime) -> Optional[ProtectionReturn]: """ diff --git a/freqtrade/plugins/protections/iprotection.py b/freqtrade/plugins/protections/iprotection.py index 1d57b3e4d..c02fedfb2 100644 --- a/freqtrade/plugins/protections/iprotection.py +++ b/freqtrade/plugins/protections/iprotection.py @@ -32,6 +32,7 @@ class IProtection(LoggingMixin, ABC): self._config = config self._protection_config = protection_config self._stop_duration_candles: Optional[int] = None + self._stop_duration: int = 0 self._lookback_period_candles: Optional[int] = None self._unlock_at: Optional[datetime] = None @@ -92,6 +93,16 @@ class IProtection(LoggingMixin, ABC): return self._unlock_at.strftime("%H:%M") return None + @property + def unlock_reason_time_element(self) -> str: + """ + Output configured unlock time or stop duration + """ + if self.unlock_at_str is not None: + return f"until {self.unlock_at_str}" + else: + return f"for {self.stop_duration_str}" + def calculate_unlock_at(self) -> datetime: """ Calculate and update the unlock time based on the unlock at config. diff --git a/freqtrade/plugins/protections/low_profit_pairs.py b/freqtrade/plugins/protections/low_profit_pairs.py index 88554d2be..518a20c0f 100644 --- a/freqtrade/plugins/protections/low_profit_pairs.py +++ b/freqtrade/plugins/protections/low_profit_pairs.py @@ -34,12 +34,10 @@ class LowProfitPairs(IProtection): """ LockReason to use """ - reason = f"{profit} < {self._required_profit} in {self.lookback_period_str}, locking" - if self.unlock_at_str is not None: - reason += f" until {self.unlock_at_str}." - else: - reason += f" for {self.stop_duration_str}." - return reason + return ( + f"{profit} < {self._required_profit} in {self.lookback_period_str}, " + f"locking {self.unlock_reason_time_element}." + ) def _low_profit( self, date_now: datetime, pair: str, side: LongShort diff --git a/freqtrade/plugins/protections/max_drawdown_protection.py b/freqtrade/plugins/protections/max_drawdown_protection.py index 1816df303..6f1c1ebf8 100644 --- a/freqtrade/plugins/protections/max_drawdown_protection.py +++ b/freqtrade/plugins/protections/max_drawdown_protection.py @@ -37,15 +37,10 @@ class MaxDrawdown(IProtection): """ LockReason to use """ - reason = ( + return ( f"{drawdown} passed {self._max_allowed_drawdown} in {self.lookback_period_str}, " - f"locking " + f"locking {self.unlock_reason_time_element}." ) - if self.unlock_at_str is not None: - reason += f" until {self.unlock_at_str}." - else: - reason += f" for {self.stop_duration_str}." - return reason def _max_drawdown(self, date_now: datetime) -> Optional[ProtectionReturn]: """ diff --git a/freqtrade/plugins/protections/stoploss_guard.py b/freqtrade/plugins/protections/stoploss_guard.py index 0ef2254e8..21e883bbd 100644 --- a/freqtrade/plugins/protections/stoploss_guard.py +++ b/freqtrade/plugins/protections/stoploss_guard.py @@ -36,12 +36,10 @@ class StoplossGuard(IProtection): """ LockReason to use """ - reason = f"{self._trade_limit} stoplosses in {self._lookback_period} min, " f"locking " - if self.unlock_at_str is not None: - reason += f" until {self.unlock_at_str}." - else: - reason += f" for {self._stop_duration} min." - return reason + return ( + f"{self._trade_limit} stoplosses in {self._lookback_period} min, " + f"locking {self.unlock_reason_time_element}." + ) def _stoploss_guard( self, date_now: datetime, pair: Optional[str], side: LongShort diff --git a/tests/plugins/test_protections.py b/tests/plugins/test_protections.py index 4c76693c8..02252fb64 100644 --- a/tests/plugins/test_protections.py +++ b/tests/plugins/test_protections.py @@ -648,7 +648,7 @@ def test_MaxDrawdown(mocker, default_conf, fee, caplog): ), ( {"method": "CooldownPeriod", "stop_duration": 60}, - "[{'CooldownPeriod': 'CooldownPeriod - Cooldown period of 60 minutes.'}]", + "[{'CooldownPeriod': 'CooldownPeriod - Cooldown period for 60 minutes.'}]", None, ), ( @@ -677,7 +677,7 @@ def test_MaxDrawdown(mocker, default_conf, fee, caplog): ), ( {"method": "CooldownPeriod", "stop_duration_candles": 5}, - "[{'CooldownPeriod': 'CooldownPeriod - Cooldown period of 5 candles.'}]", + "[{'CooldownPeriod': 'CooldownPeriod - Cooldown period for 5 candles.'}]", None, ), (