stable/freqtrade/plugins/protectionmanager.py

59 lines
1.8 KiB
Python
Raw Normal View History

"""
Protection manager class
"""
import logging
2020-10-15 05:38:00 +00:00
from datetime import datetime
from typing import Dict, List
from freqtrade.exceptions import OperationalException
from freqtrade.plugins.protections import IProtection
from freqtrade.resolvers import ProtectionResolver
2020-10-15 05:38:00 +00:00
logger = logging.getLogger(__name__)
class ProtectionManager():
2020-10-14 05:40:44 +00:00
def __init__(self, config: dict) -> None:
self._config = config
self._protection_handlers: List[IProtection] = []
2020-10-14 18:03:56 +00:00
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
protection_handler = ProtectionResolver.load_protection(
protection_handler_config['method'],
config=config,
protection_config=protection_handler_config,
)
self._protection_handlers.append(protection_handler)
if not self._protection_handlers:
2020-10-14 18:03:56 +00:00
logger.info("No protection Handlers defined.")
@property
def name_list(self) -> List[str]:
"""
Get list of loaded Protection Handler names
"""
return [p.name for p in self._protection_handlers]
def short_desc(self) -> List[Dict]:
"""
List of short_desc for each Pairlist Handler
"""
2020-10-14 18:03:56 +00:00
return [{p.name: p.short_desc()} for p in self._protection_handlers]
def global_stop(self) -> bool:
now = datetime.utcnow()
2020-10-15 05:38:00 +00:00
2020-10-14 18:03:56 +00:00
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