Implement global stop (First try)

This commit is contained in:
Matthias
2020-10-14 20:03:56 +02:00
parent 246b4a57a4
commit f39a534fc0
6 changed files with 23 additions and 9 deletions

View File

@@ -0,0 +1,2 @@
# flake8: noqa: F401
# from freqtrade.plugins.protectionmanager import ProtectionManager

View File

@@ -7,7 +7,7 @@ from typing import Dict, List
from freqtrade.exceptions import OperationalException
from freqtrade.plugins.protections import IProtection
from freqtrade.resolvers import ProtectionResolver
from datetime import datetime
logger = logging.getLogger(__name__)
@@ -18,8 +18,7 @@ class ProtectionManager():
self._config = config
self._protection_handlers: List[IProtection] = []
self._tickers_needed = False
for protection_handler_config in self._config.get('protections', None):
for protection_handler_config in self._config.get('protections', []):
if 'method' not in protection_handler_config:
logger.warning(f"No method found in {protection_handler_config}, ignoring.")
continue
@@ -28,11 +27,10 @@ class ProtectionManager():
config=config,
protection_config=protection_handler_config,
)
self._tickers_needed |= protection_handler.needstickers
self._protection_handlers.append(protection_handler)
if not self._protection_handlers:
raise OperationalException("No protection Handlers defined")
logger.info("No protection Handlers defined.")
@property
def name_list(self) -> List[str]:
@@ -45,4 +43,14 @@ class ProtectionManager():
"""
List of short_desc for each Pairlist Handler
"""
return [{p.name: p.short_desc()} for p in self._pairlist_handlers]
return [{p.name: p.short_desc()} for p in self._protection_handlers]
def global_stop(self) -> bool:
now = datetime.utcnow()
for protection_handler in self._protection_handlers:
result = protection_handler.global_stop(now)
# Early stopping - first positive result stops the application
if result:
return True
return False

View File

@@ -26,7 +26,7 @@ class IProtection(ABC):
"""
@abstractmethod
def stop_trade_enters_global(self, date_now: datetime) -> bool:
def global_stop(self, date_now: datetime) -> bool:
"""
Stops trading (position entering) for all pairs
This must evaluate to true for the whole period of the "cooldown period".

View File

@@ -47,7 +47,7 @@ class StoplossGuard(IProtection):
return False
def stop_trade_enters_global(self, date_now: datetime) -> bool:
def global_stop(self, date_now: datetime) -> bool:
"""
Stops trading (position entering) for all pairs
This must evaluate to true for the whole period of the "cooldown period".