From 5e3d2401f5957de2cbea427f671cb4b013c0e1b4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 19 Nov 2020 20:34:29 +0100 Subject: [PATCH] Only call stop methods when they actually support this method --- freqtrade/plugins/protectionmanager.py | 24 ++++++++++--------- .../plugins/protections/cooldown_period.py | 5 ++++ freqtrade/plugins/protections/iprotection.py | 7 +++++- .../plugins/protections/low_profit_pairs.py | 5 ++++ .../plugins/protections/stoploss_guard.py | 9 +++++-- 5 files changed, 36 insertions(+), 14 deletions(-) diff --git a/freqtrade/plugins/protectionmanager.py b/freqtrade/plugins/protectionmanager.py index e58a50c80..d12f4ba80 100644 --- a/freqtrade/plugins/protectionmanager.py +++ b/freqtrade/plugins/protectionmanager.py @@ -50,22 +50,24 @@ class ProtectionManager(): now = datetime.now(timezone.utc) result = False 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 - if result and until: - if not PairLocks.is_global_lock(until): - PairLocks.lock_pair('*', until, reason, now=now) - result = True + # Early stopping - first positive result blocks further trades + if result and until: + if not PairLocks.is_global_lock(until): + PairLocks.lock_pair('*', until, reason, now=now) + result = True return result def stop_per_pair(self, pair) -> bool: now = datetime.now(timezone.utc) result = False for protection_handler in self._protection_handlers: - result, until, reason = protection_handler.stop_per_pair(pair, now) - if result and until: - if not PairLocks.is_pair_locked(pair, until): - PairLocks.lock_pair(pair, until, reason, now=now) - result = True + if protection_handler.has_local_stop: + result, until, reason = protection_handler.stop_per_pair(pair, now) + if result and until: + if not PairLocks.is_pair_locked(pair, until): + PairLocks.lock_pair(pair, until, reason, now=now) + result = True return result diff --git a/freqtrade/plugins/protections/cooldown_period.py b/freqtrade/plugins/protections/cooldown_period.py index 447ca4363..4fe0a4fdc 100644 --- a/freqtrade/plugins/protections/cooldown_period.py +++ b/freqtrade/plugins/protections/cooldown_period.py @@ -12,6 +12,11 @@ logger = logging.getLogger(__name__) 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: super().__init__(config, protection_config) diff --git a/freqtrade/plugins/protections/iprotection.py b/freqtrade/plugins/protections/iprotection.py index 8048fccf0..49fccb0e6 100644 --- a/freqtrade/plugins/protections/iprotection.py +++ b/freqtrade/plugins/protections/iprotection.py @@ -1,6 +1,6 @@ import logging -from abc import ABC, abstractmethod +from abc import ABC, abstractmethod, abstractproperty from datetime import datetime, timedelta, timezone from typing import Any, Dict, List, Optional, Tuple @@ -15,6 +15,11 @@ ProtectionReturn = Tuple[bool, Optional[datetime], Optional[str]] 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: self._config = config self._protection_config = protection_config diff --git a/freqtrade/plugins/protections/low_profit_pairs.py b/freqtrade/plugins/protections/low_profit_pairs.py index 96fb2b08e..48efa3c9a 100644 --- a/freqtrade/plugins/protections/low_profit_pairs.py +++ b/freqtrade/plugins/protections/low_profit_pairs.py @@ -12,6 +12,11 @@ logger = logging.getLogger(__name__) 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: super().__init__(config, protection_config) diff --git a/freqtrade/plugins/protections/stoploss_guard.py b/freqtrade/plugins/protections/stoploss_guard.py index 8b6871915..51a2fded8 100644 --- a/freqtrade/plugins/protections/stoploss_guard.py +++ b/freqtrade/plugins/protections/stoploss_guard.py @@ -15,6 +15,11 @@ logger = logging.getLogger(__name__) 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: super().__init__(config, protection_config) @@ -67,7 +72,7 @@ class StoplossGuard(IProtection): :return: Tuple of [bool, until, reason]. If true, all pairs will be locked with 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: """ @@ -76,4 +81,4 @@ class StoplossGuard(IProtection): :return: Tuple of [bool, until, reason]. If true, this pair will be locked with until """ - return False, None, None + return self._stoploss_guard(date_now, pair)