align wording to simplify "locking for" element
This commit is contained in:
@@ -18,23 +18,13 @@ class CooldownPeriod(IProtection):
|
|||||||
"""
|
"""
|
||||||
LockReason to use
|
LockReason to use
|
||||||
"""
|
"""
|
||||||
reason = "Cooldown period"
|
return f"Cooldown period for {self.unlock_reason_time_element}."
|
||||||
|
|
||||||
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}."
|
|
||||||
|
|
||||||
def short_desc(self) -> str:
|
def short_desc(self) -> str:
|
||||||
"""
|
"""
|
||||||
Short method description - used for startup messages
|
Short method description - used for startup messages
|
||||||
"""
|
"""
|
||||||
result = f"{self.name} - Cooldown period "
|
return f"{self.name} - Cooldown period {self.unlock_reason_time_element}."
|
||||||
|
|
||||||
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}."
|
|
||||||
|
|
||||||
def _cooldown_period(self, pair: str, date_now: datetime) -> Optional[ProtectionReturn]:
|
def _cooldown_period(self, pair: str, date_now: datetime) -> Optional[ProtectionReturn]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class IProtection(LoggingMixin, ABC):
|
|||||||
self._config = config
|
self._config = config
|
||||||
self._protection_config = protection_config
|
self._protection_config = protection_config
|
||||||
self._stop_duration_candles: Optional[int] = None
|
self._stop_duration_candles: Optional[int] = None
|
||||||
|
self._stop_duration: int = 0
|
||||||
self._lookback_period_candles: Optional[int] = None
|
self._lookback_period_candles: Optional[int] = None
|
||||||
self._unlock_at: Optional[datetime] = None
|
self._unlock_at: Optional[datetime] = None
|
||||||
|
|
||||||
@@ -92,6 +93,16 @@ class IProtection(LoggingMixin, ABC):
|
|||||||
return self._unlock_at.strftime("%H:%M")
|
return self._unlock_at.strftime("%H:%M")
|
||||||
return None
|
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:
|
def calculate_unlock_at(self) -> datetime:
|
||||||
"""
|
"""
|
||||||
Calculate and update the unlock time based on the unlock at config.
|
Calculate and update the unlock time based on the unlock at config.
|
||||||
|
|||||||
@@ -34,12 +34,10 @@ class LowProfitPairs(IProtection):
|
|||||||
"""
|
"""
|
||||||
LockReason to use
|
LockReason to use
|
||||||
"""
|
"""
|
||||||
reason = f"{profit} < {self._required_profit} in {self.lookback_period_str}, locking"
|
return (
|
||||||
if self.unlock_at_str is not None:
|
f"{profit} < {self._required_profit} in {self.lookback_period_str}, "
|
||||||
reason += f" until {self.unlock_at_str}."
|
f"locking {self.unlock_reason_time_element}."
|
||||||
else:
|
)
|
||||||
reason += f" for {self.stop_duration_str}."
|
|
||||||
return reason
|
|
||||||
|
|
||||||
def _low_profit(
|
def _low_profit(
|
||||||
self, date_now: datetime, pair: str, side: LongShort
|
self, date_now: datetime, pair: str, side: LongShort
|
||||||
|
|||||||
@@ -37,15 +37,10 @@ class MaxDrawdown(IProtection):
|
|||||||
"""
|
"""
|
||||||
LockReason to use
|
LockReason to use
|
||||||
"""
|
"""
|
||||||
reason = (
|
return (
|
||||||
f"{drawdown} passed {self._max_allowed_drawdown} in {self.lookback_period_str}, "
|
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]:
|
def _max_drawdown(self, date_now: datetime) -> Optional[ProtectionReturn]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -36,12 +36,10 @@ class StoplossGuard(IProtection):
|
|||||||
"""
|
"""
|
||||||
LockReason to use
|
LockReason to use
|
||||||
"""
|
"""
|
||||||
reason = f"{self._trade_limit} stoplosses in {self._lookback_period} min, " f"locking "
|
return (
|
||||||
if self.unlock_at_str is not None:
|
f"{self._trade_limit} stoplosses in {self._lookback_period} min, "
|
||||||
reason += f" until {self.unlock_at_str}."
|
f"locking {self.unlock_reason_time_element}."
|
||||||
else:
|
)
|
||||||
reason += f" for {self._stop_duration} min."
|
|
||||||
return reason
|
|
||||||
|
|
||||||
def _stoploss_guard(
|
def _stoploss_guard(
|
||||||
self, date_now: datetime, pair: Optional[str], side: LongShort
|
self, date_now: datetime, pair: Optional[str], side: LongShort
|
||||||
|
|||||||
@@ -648,7 +648,7 @@ def test_MaxDrawdown(mocker, default_conf, fee, caplog):
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
{"method": "CooldownPeriod", "stop_duration": 60},
|
{"method": "CooldownPeriod", "stop_duration": 60},
|
||||||
"[{'CooldownPeriod': 'CooldownPeriod - Cooldown period of 60 minutes.'}]",
|
"[{'CooldownPeriod': 'CooldownPeriod - Cooldown period for 60 minutes.'}]",
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@@ -677,7 +677,7 @@ def test_MaxDrawdown(mocker, default_conf, fee, caplog):
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
{"method": "CooldownPeriod", "stop_duration_candles": 5},
|
{"method": "CooldownPeriod", "stop_duration_candles": 5},
|
||||||
"[{'CooldownPeriod': 'CooldownPeriod - Cooldown period of 5 candles.'}]",
|
"[{'CooldownPeriod': 'CooldownPeriod - Cooldown period for 5 candles.'}]",
|
||||||
None,
|
None,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|
|||||||
Reference in New Issue
Block a user