2020-02-06 19:26:04 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from freqtrade.exceptions import StrategyError
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2020-02-06 19:30:17 +00:00
|
|
|
def strategy_safe_wrapper(f, message: str = "", default_retval=None):
|
2020-02-06 19:26:04 +00:00
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
try:
|
|
|
|
return f(*args, **kwargs)
|
|
|
|
except ValueError as error:
|
|
|
|
logger.warning(
|
|
|
|
f"{message}"
|
|
|
|
f"Strategy caused the following exception: {error}"
|
|
|
|
f"{f}"
|
|
|
|
)
|
|
|
|
if not default_retval:
|
|
|
|
raise StrategyError(str(error)) from error
|
|
|
|
return default_retval
|
|
|
|
except Exception as error:
|
|
|
|
logger.exception(
|
|
|
|
f"Unexpected error {error} calling {f}"
|
|
|
|
)
|
|
|
|
if not default_retval:
|
|
|
|
raise StrategyError(str(error)) from error
|
|
|
|
return default_retval
|
|
|
|
|
|
|
|
return wrapper
|