rename Strategy into StrategyResolver

This commit is contained in:
gcarq 2018-03-24 18:11:21 +01:00
parent a2c3df3ac5
commit ca9c5edd39
6 changed files with 44 additions and 44 deletions

View File

@ -11,7 +11,7 @@ from pandas import DataFrame, to_datetime
from freqtrade.exchange import get_ticker_history
from freqtrade.logger import Logger
from freqtrade.persistence import Trade
from freqtrade.strategy.strategy import Strategy
from freqtrade.strategy.resolver import StrategyResolver
class SignalType(Enum):
@ -35,7 +35,7 @@ class Analyze(object):
self.logger = Logger(name=__name__, level=config.get('loglevel')).get_logger()
self.config = config
self.strategy = Strategy(self.config)
self.strategy = StrategyResolver(self.config)
@staticmethod
def parse_ticker_dataframe(ticker: list) -> DataFrame:

View File

@ -17,7 +17,7 @@ from freqtrade.strategy.interface import IStrategy
sys.path.insert(0, r'../../user_data/strategies')
class Strategy(object):
class StrategyResolver(object):
"""
This class contains all the logic to load custom strategy class
"""

View File

@ -8,7 +8,7 @@ import pandas as pd
from freqtrade.optimize.__init__ import load_tickerdata_file
from freqtrade.optimize.hyperopt import Hyperopt, start
from freqtrade.strategy.strategy import Strategy
from freqtrade.strategy.resolver import StrategyResolver
from freqtrade.tests.conftest import default_conf, log_has
from freqtrade.tests.optimize.test_backtesting import get_args
@ -62,7 +62,7 @@ def test_start(mocker, default_conf, caplog) -> None:
'--epochs', '5'
]
args = get_args(args)
Strategy({'strategy': 'default_strategy'})
StrategyResolver({'strategy': 'default_strategy'})
start(args)
import pprint
@ -80,7 +80,7 @@ def test_loss_calculation_prefer_correct_trade_count() -> None:
Test Hyperopt.calculate_loss()
"""
hyperopt = _HYPEROPT
Strategy({'strategy': 'default_strategy'})
StrategyResolver({'strategy': 'default_strategy'})
correct = hyperopt.calculate_loss(1, hyperopt.target_trades, 20)
over = hyperopt.calculate_loss(1, hyperopt.target_trades + 100, 20)
@ -171,7 +171,7 @@ def test_fmin_best_results(mocker, default_conf, caplog) -> None:
mocker.patch('freqtrade.optimize.hyperopt.hyperopt_optimize_conf', return_value=conf)
mocker.patch('freqtrade.logger.Logger.set_format', MagicMock())
Strategy({'strategy': 'default_strategy'})
StrategyResolver({'strategy': 'default_strategy'})
hyperopt = Hyperopt(conf)
hyperopt.trials = create_trials(mocker)
hyperopt.tickerdata_to_dataframe = MagicMock()
@ -215,7 +215,7 @@ def test_fmin_throw_value_error(mocker, default_conf, caplog) -> None:
conf.update({'spaces': 'all'})
mocker.patch('freqtrade.optimize.hyperopt.hyperopt_optimize_conf', return_value=conf)
mocker.patch('freqtrade.logger.Logger.set_format', MagicMock())
Strategy({'strategy': 'default_strategy'})
StrategyResolver({'strategy': 'default_strategy'})
hyperopt = Hyperopt(conf)
hyperopt.trials = create_trials(mocker)
hyperopt.tickerdata_to_dataframe = MagicMock()
@ -258,7 +258,7 @@ def test_resuming_previous_hyperopt_results_succeeds(mocker, default_conf) -> No
mocker.patch('freqtrade.optimize.hyperopt.hyperopt_optimize_conf', return_value=conf)
mocker.patch('freqtrade.logger.Logger.set_format', MagicMock())
Strategy({'strategy': 'default_strategy'})
StrategyResolver({'strategy': 'default_strategy'})
hyperopt = Hyperopt(conf)
hyperopt.trials = trials
hyperopt.tickerdata_to_dataframe = MagicMock()

View File

@ -2,49 +2,49 @@
import logging
from freqtrade.strategy.strategy import Strategy
from freqtrade.strategy.resolver import StrategyResolver
def test_sanitize_module_name():
assert Strategy._sanitize_module_name('default_strategy') == 'default_strategy'
assert Strategy._sanitize_module_name('default_strategy.py') == 'default_strategy'
assert Strategy._sanitize_module_name('../default_strategy.py') == 'default_strategy'
assert Strategy._sanitize_module_name('../default_strategy') == 'default_strategy'
assert Strategy._sanitize_module_name('.default_strategy') == '.default_strategy'
assert Strategy._sanitize_module_name('foo-bar') == 'foo-bar'
assert Strategy._sanitize_module_name('foo/bar') == 'bar'
assert StrategyResolver._sanitize_module_name('default_strategy') == 'default_strategy'
assert StrategyResolver._sanitize_module_name('default_strategy.py') == 'default_strategy'
assert StrategyResolver._sanitize_module_name('../default_strategy.py') == 'default_strategy'
assert StrategyResolver._sanitize_module_name('../default_strategy') == 'default_strategy'
assert StrategyResolver._sanitize_module_name('.default_strategy') == '.default_strategy'
assert StrategyResolver._sanitize_module_name('foo-bar') == 'foo-bar'
assert StrategyResolver._sanitize_module_name('foo/bar') == 'bar'
def test_search_strategy():
assert Strategy._search_strategy('default_strategy') == '.'
assert Strategy._search_strategy('test_strategy') == 'user_data.strategies.'
assert Strategy._search_strategy('super_duper') is None
assert StrategyResolver._search_strategy('default_strategy') == '.'
assert StrategyResolver._search_strategy('test_strategy') == 'user_data.strategies.'
assert StrategyResolver._search_strategy('super_duper') is None
def test_strategy_structure():
assert hasattr(Strategy, 'populate_indicators')
assert hasattr(Strategy, 'populate_buy_trend')
assert hasattr(Strategy, 'populate_sell_trend')
assert hasattr(StrategyResolver, 'populate_indicators')
assert hasattr(StrategyResolver, 'populate_buy_trend')
assert hasattr(StrategyResolver, 'populate_sell_trend')
def test_load_strategy(result):
strategy = Strategy()
strategy = StrategyResolver()
strategy.logger = logging.getLogger(__name__)
assert not hasattr(Strategy, 'custom_strategy')
assert not hasattr(StrategyResolver, 'custom_strategy')
strategy._load_strategy('test_strategy')
assert not hasattr(Strategy, 'custom_strategy')
assert not hasattr(StrategyResolver, 'custom_strategy')
assert hasattr(strategy.custom_strategy, 'populate_indicators')
assert 'adx' in strategy.populate_indicators(result)
def test_load_not_found_strategy(caplog):
strategy = Strategy()
strategy = StrategyResolver()
strategy.logger = logging.getLogger(__name__)
assert not hasattr(Strategy, 'custom_strategy')
assert not hasattr(StrategyResolver, 'custom_strategy')
strategy._load_strategy('NotFoundStrategy')
error_msg = "Impossible to load Strategy 'user_data/strategies/{}.py'. This file does not " \
@ -53,7 +53,7 @@ def test_load_not_found_strategy(caplog):
def test_strategy(result):
strategy = Strategy({'strategy': 'default_strategy'})
strategy = StrategyResolver({'strategy': 'default_strategy'})
assert hasattr(strategy.custom_strategy, 'minimal_roi')
assert strategy.minimal_roi[0] == 0.04
@ -81,11 +81,11 @@ def test_strategy_override_minimal_roi(caplog):
"0": 0.5
}
}
strategy = Strategy(config)
strategy = StrategyResolver(config)
assert hasattr(strategy.custom_strategy, 'minimal_roi')
assert strategy.minimal_roi[0] == 0.5
assert ('freqtrade.strategy.strategy',
assert ('freqtrade.strategy.resolver',
logging.INFO,
'Override strategy \'minimal_roi\' with value in config file.'
) in caplog.record_tuples
@ -97,11 +97,11 @@ def test_strategy_override_stoploss(caplog):
'strategy': 'default_strategy',
'stoploss': -0.5
}
strategy = Strategy(config)
strategy = StrategyResolver(config)
assert hasattr(strategy.custom_strategy, 'stoploss')
assert strategy.stoploss == -0.5
assert ('freqtrade.strategy.strategy',
assert ('freqtrade.strategy.resolver',
logging.INFO,
'Override strategy \'stoploss\' with value in config file: -0.5.'
) in caplog.record_tuples
@ -114,31 +114,31 @@ def test_strategy_override_ticker_interval(caplog):
'strategy': 'default_strategy',
'ticker_interval': 60
}
strategy = Strategy(config)
strategy = StrategyResolver(config)
assert hasattr(strategy.custom_strategy, 'ticker_interval')
assert strategy.ticker_interval == 60
assert ('freqtrade.strategy.strategy',
assert ('freqtrade.strategy.resolver',
logging.INFO,
'Override strategy \'ticker_interval\' with value in config file: 60.'
) in caplog.record_tuples
def test_strategy_fallback_default_strategy():
strategy = Strategy()
strategy = StrategyResolver()
strategy.logger = logging.getLogger(__name__)
assert not hasattr(Strategy, 'custom_strategy')
assert not hasattr(StrategyResolver, 'custom_strategy')
strategy._load_strategy('../../super_duper')
assert not hasattr(Strategy, 'custom_strategy')
assert not hasattr(StrategyResolver, 'custom_strategy')
def test_strategy_singleton():
strategy1 = Strategy({'strategy': 'default_strategy'})
strategy1 = StrategyResolver({'strategy': 'default_strategy'})
assert hasattr(strategy1.custom_strategy, 'minimal_roi')
assert strategy1.minimal_roi[0] == 0.04
strategy2 = Strategy()
strategy2 = StrategyResolver()
assert hasattr(strategy2.custom_strategy, 'minimal_roi')
assert strategy2.minimal_roi[0] == 0.04

View File

@ -4,7 +4,7 @@ import pandas
from freqtrade.analyze import Analyze
from freqtrade.optimize import load_data
from freqtrade.strategy.strategy import Strategy
from freqtrade.strategy.resolver import StrategyResolver
_pairs = ['BTC_ETH']
@ -21,13 +21,13 @@ def load_dataframe_pair(pairs):
def test_dataframe_load():
Strategy({'strategy': 'default_strategy'})
StrategyResolver({'strategy': 'default_strategy'})
dataframe = load_dataframe_pair(_pairs)
assert isinstance(dataframe, pandas.core.frame.DataFrame)
def test_dataframe_columns_exists():
Strategy({'strategy': 'default_strategy'})
StrategyResolver({'strategy': 'default_strategy'})
dataframe = load_dataframe_pair(_pairs)
assert 'high' in dataframe.columns
assert 'low' in dataframe.columns

View File

@ -47,7 +47,7 @@ def test_common_datearray(default_conf, mocker) -> None:
Test common_datearray()
:return: None
"""
mocker.patch('freqtrade.strategy.strategy.Strategy', MagicMock())
mocker.patch('freqtrade.strategy.resolver.StrategyResolver', MagicMock())
analyze = Analyze(default_conf)
tick = load_tickerdata_file(None, 'BTC_UNITEST', 1)