From 2b00a5d90a168df621731ea30687597ef2f44b12 Mon Sep 17 00:00:00 2001 From: hroff-1902 Date: Sun, 8 Sep 2019 02:43:02 +0300 Subject: [PATCH] Get rid of import_strategy() --- freqtrade/optimize/__init__.py | 10 ------ freqtrade/resolvers/strategy_resolver.py | 8 +---- freqtrade/strategy/__init__.py | 42 ------------------------ 3 files changed, 1 insertion(+), 59 deletions(-) diff --git a/freqtrade/optimize/__init__.py b/freqtrade/optimize/__init__.py index 2c7c42c4d..973ea1ff5 100644 --- a/freqtrade/optimize/__init__.py +++ b/freqtrade/optimize/__init__.py @@ -25,16 +25,6 @@ def setup_configuration(args: Namespace, method: RunMode) -> Dict[str, Any]: raise DependencyException('stake amount could not be "%s" for backtesting' % constants.UNLIMITED_STAKE_AMOUNT) - if method == RunMode.HYPEROPT: - # Special cases for Hyperopt - if config.get('strategy') and config.get('strategy') != 'DefaultStrategy': - logger.error("Please don't use --strategy for hyperopt.") - logger.error( - "Read the documentation at " - "https://github.com/freqtrade/freqtrade/blob/develop/docs/hyperopt.md " - "to understand how to configure hyperopt.") - raise DependencyException("--strategy configured but not supported for hyperopt") - return config diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index 514e9f22b..ca7e1165b 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -13,7 +13,6 @@ from typing import Dict, Optional from freqtrade import constants, OperationalException from freqtrade.resolvers import IResolver -from freqtrade.strategy import import_strategy from freqtrade.strategy.interface import IStrategy logger = logging.getLogger(__name__) @@ -158,12 +157,7 @@ class StrategyResolver(IResolver): strategy._sell_fun_len]]): strategy.INTERFACE_VERSION = 1 - try: - return import_strategy(strategy, config=config) - except TypeError as e: - logger.warning( - f"Impossible to load strategy '{strategy_name}'. " - f"Error: {e}") + return strategy raise OperationalException( f"Impossible to load Strategy '{strategy_name}'. This class does not exist " diff --git a/freqtrade/strategy/__init__.py b/freqtrade/strategy/__init__.py index c62bfe5dc..3fcc87ff3 100644 --- a/freqtrade/strategy/__init__.py +++ b/freqtrade/strategy/__init__.py @@ -1,45 +1,3 @@ -import logging -import sys -from copy import deepcopy - from freqtrade.strategy.interface import IStrategy # Import Default-Strategy to have hyperopt correctly resolve from freqtrade.strategy.default_strategy import DefaultStrategy # noqa: F401 - - -logger = logging.getLogger(__name__) - - -def import_strategy(strategy: IStrategy, config: dict) -> IStrategy: - """ - Imports given Strategy instance to global scope - of freqtrade.strategy and returns an instance of it - """ - - # Copy all attributes from base class and class - comb = {**strategy.__class__.__dict__, **strategy.__dict__} - - # Delete '_abc_impl' from dict as deepcopy fails on 3.7 with - # `TypeError: can't pickle _abc_data objects`` - # This will only apply to python 3.7 - if sys.version_info.major == 3 and sys.version_info.minor == 7 and '_abc_impl' in comb: - del comb['_abc_impl'] - - attr = deepcopy(comb) - - # Adjust module name - attr['__module__'] = 'freqtrade.strategy' - - name = strategy.__class__.__name__ - clazz = type(name, (IStrategy,), attr) - - logger.debug( - 'Imported strategy %s.%s as %s.%s', - strategy.__module__, strategy.__class__.__name__, - clazz.__module__, strategy.__class__.__name__, - ) - - # Modify global scope to declare class - globals()[name] = clazz - - return clazz(config)