Only call stop methods when they actually support this method

This commit is contained in:
Matthias 2020-11-19 20:34:29 +01:00
parent 2cd54a5933
commit 5e3d2401f5
5 changed files with 36 additions and 14 deletions

View File

@ -50,22 +50,24 @@ class ProtectionManager():
now = datetime.now(timezone.utc) now = datetime.now(timezone.utc)
result = False result = False
for protection_handler in self._protection_handlers: for protection_handler in self._protection_handlers:
result, until, reason = protection_handler.global_stop(now) if protection_handler.has_global_stop:
result, until, reason = protection_handler.global_stop(now)
# Early stopping - first positive result blocks further trades # Early stopping - first positive result blocks further trades
if result and until: if result and until:
if not PairLocks.is_global_lock(until): if not PairLocks.is_global_lock(until):
PairLocks.lock_pair('*', until, reason, now=now) PairLocks.lock_pair('*', until, reason, now=now)
result = True result = True
return result return result
def stop_per_pair(self, pair) -> bool: def stop_per_pair(self, pair) -> bool:
now = datetime.now(timezone.utc) now = datetime.now(timezone.utc)
result = False result = False
for protection_handler in self._protection_handlers: for protection_handler in self._protection_handlers:
result, until, reason = protection_handler.stop_per_pair(pair, now) if protection_handler.has_local_stop:
if result and until: result, until, reason = protection_handler.stop_per_pair(pair, now)
if not PairLocks.is_pair_locked(pair, until): if result and until:
PairLocks.lock_pair(pair, until, reason, now=now) if not PairLocks.is_pair_locked(pair, until):
result = True PairLocks.lock_pair(pair, until, reason, now=now)
result = True
return result return result

View File

@ -12,6 +12,11 @@ logger = logging.getLogger(__name__)
class CooldownPeriod(IProtection): class CooldownPeriod(IProtection):
# Can globally stop the bot
has_global_stop: bool = False
# Can stop trading for one pair
has_local_stop: bool = True
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)

View File

@ -1,6 +1,6 @@
import logging import logging
from abc import ABC, abstractmethod from abc import ABC, abstractmethod, abstractproperty
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
@ -15,6 +15,11 @@ ProtectionReturn = Tuple[bool, Optional[datetime], Optional[str]]
class IProtection(LoggingMixin, ABC): class IProtection(LoggingMixin, ABC):
# Can globally stop the bot
has_global_stop: bool = False
# Can stop trading for one pair
has_local_stop: bool = False
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:
self._config = config self._config = config
self._protection_config = protection_config self._protection_config = protection_config

View File

@ -12,6 +12,11 @@ logger = logging.getLogger(__name__)
class LowProfitPairs(IProtection): class LowProfitPairs(IProtection):
# Can globally stop the bot
has_global_stop: bool = False
# Can stop trading for one pair
has_local_stop: bool = True
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)

View File

@ -15,6 +15,11 @@ logger = logging.getLogger(__name__)
class StoplossGuard(IProtection): class StoplossGuard(IProtection):
# Can globally stop the bot
has_global_stop: bool = True
# Can stop trading for one pair
has_local_stop: bool = True
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)
@ -67,7 +72,7 @@ class StoplossGuard(IProtection):
:return: Tuple of [bool, until, reason]. :return: Tuple of [bool, until, reason].
If true, all pairs will be locked with <reason> until <until> If true, all pairs will be locked with <reason> until <until>
""" """
return self._stoploss_guard(date_now, pair=None) return self._stoploss_guard(date_now, None)
def stop_per_pair(self, pair: str, date_now: datetime) -> ProtectionReturn: def stop_per_pair(self, pair: str, date_now: datetime) -> ProtectionReturn:
""" """
@ -76,4 +81,4 @@ class StoplossGuard(IProtection):
:return: Tuple of [bool, until, reason]. :return: Tuple of [bool, until, reason].
If true, this pair will be locked with <reason> until <until> If true, this pair will be locked with <reason> until <until>
""" """
return False, None, None return self._stoploss_guard(date_now, pair)