align wording to simplify "locking for" element

This commit is contained in:
Matthias 2024-07-16 06:48:30 +02:00
parent 1e36bc98b9
commit d13f47ec0b
6 changed files with 25 additions and 33 deletions

View File

@ -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]:
"""

View File

@ -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.

View File

@ -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

View File

@ -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]:
"""

View File

@ -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

View File

@ -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,
),
(