Better wording for config options

This commit is contained in:
Matthias 2020-11-11 07:48:27 +01:00
parent 8dbef6bbea
commit 9f6c2a583f
3 changed files with 19 additions and 16 deletions

View File

@ -203,8 +203,11 @@ CONF_SCHEMA = {
'type': 'object', 'type': 'object',
'properties': { 'properties': {
'method': {'type': 'string', 'enum': AVAILABLE_PROTECTIONS}, 'method': {'type': 'string', 'enum': AVAILABLE_PROTECTIONS},
'stop_duration': {'type': 'number', 'minimum': 0.0},
'trade_limit': {'type': 'number', 'integer': 1},
'lookback_period': {'type': 'number', 'integer': 1},
}, },
'required': ['method'], 'required': ['method', 'trade_limit'],
} }
}, },
'telegram': { 'telegram': {

View File

@ -15,25 +15,25 @@ class CooldownPeriod(IProtection):
def __init__(self, config: Dict[str, Any], protection_config: Dict[str, Any]) -> None: def __init__(self, config: Dict[str, Any], protection_config: Dict[str, Any]) -> None:
super().__init__(config, protection_config) super().__init__(config, protection_config)
self._stopduration = protection_config.get('stopduration', 60) self._stop_duration = protection_config.get('stop_duration', 60)
def _reason(self) -> str: def _reason(self) -> str:
""" """
LockReason to use LockReason to use
""" """
return (f'Cooldown period for {self._stopduration} min.') return (f'Cooldown period for {self._stop_duration} min.')
def short_desc(self) -> str: def short_desc(self) -> str:
""" """
Short method description - used for startup-messages Short method description - used for startup-messages
""" """
return (f"{self.name} - Cooldown period of {self._stopduration} min.") return (f"{self.name} - Cooldown period of {self._stop_duration} min.")
def _cooldown_period(self, pair: str, date_now: datetime, ) -> ProtectionReturn: def _cooldown_period(self, pair: str, date_now: datetime, ) -> ProtectionReturn:
""" """
Get last trade for this pair Get last trade for this pair
""" """
look_back_until = date_now - timedelta(minutes=self._stopduration) look_back_until = date_now - timedelta(minutes=self._stop_duration)
filters = [ filters = [
Trade.is_open.is_(False), Trade.is_open.is_(False),
Trade.close_date > look_back_until, Trade.close_date > look_back_until,
@ -41,9 +41,9 @@ class CooldownPeriod(IProtection):
] ]
trade = Trade.get_trades(filters).first() trade = Trade.get_trades(filters).first()
if trade: if trade:
self.log_on_refresh(logger.info, f"Cooldown for {pair} for {self._stopduration}.") self.log_on_refresh(logger.info, f"Cooldown for {pair} for {self._stop_duration}.")
until = trade.close_date.replace( until = trade.close_date.replace(
tzinfo=timezone.utc) + timedelta(minutes=self._stopduration) tzinfo=timezone.utc) + timedelta(minutes=self._stop_duration)
return True, until, self._reason() return True, until, self._reason()
return False, None, None return False, None, None

View File

@ -20,14 +20,7 @@ class StoplossGuard(IProtection):
self._lookback_period = protection_config.get('lookback_period', 60) self._lookback_period = protection_config.get('lookback_period', 60)
self._trade_limit = protection_config.get('trade_limit', 10) self._trade_limit = protection_config.get('trade_limit', 10)
self._stopduration = protection_config.get('stopduration', 60) self._stop_duration = protection_config.get('stop_duration', 60)
def _reason(self) -> str:
"""
LockReason to use
"""
return (f'{self._trade_limit} stoplosses in {self._lookback_period} min, '
f'locking for {self._stopduration} min.')
def short_desc(self) -> str: def short_desc(self) -> str:
""" """
@ -36,6 +29,13 @@ class StoplossGuard(IProtection):
return (f"{self.name} - Frequent Stoploss Guard, {self._trade_limit} stoplosses " return (f"{self.name} - Frequent Stoploss Guard, {self._trade_limit} stoplosses "
f"within {self._lookback_period} minutes.") f"within {self._lookback_period} minutes.")
def _reason(self) -> str:
"""
LockReason to use
"""
return (f'{self._trade_limit} stoplosses in {self._lookback_period} min, '
f'locking for {self._stop_duration} min.')
def _stoploss_guard(self, date_now: datetime, pair: str = None) -> ProtectionReturn: def _stoploss_guard(self, date_now: datetime, pair: str = None) -> ProtectionReturn:
""" """
Evaluate recent trades Evaluate recent trades
@ -55,7 +55,7 @@ class StoplossGuard(IProtection):
if len(trades) > self._trade_limit: if len(trades) > self._trade_limit:
self.log_on_refresh(logger.info, f"Trading stopped due to {self._trade_limit} " self.log_on_refresh(logger.info, f"Trading stopped due to {self._trade_limit} "
f"stoplosses within {self._lookback_period} minutes.") f"stoplosses within {self._lookback_period} minutes.")
until = date_now + timedelta(minutes=self._stopduration) until = date_now + timedelta(minutes=self._stop_duration)
return True, until, self._reason() return True, until, self._reason()
return False, None, None return False, None, None