Merge pull request #2944 from freqtrade/move_defaultstrategy

Move defaultstrategy
This commit is contained in:
hroff-1902 2020-02-20 08:52:24 +03:00 committed by GitHub
commit bee28a1061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 26 additions and 24 deletions

View File

@ -22,13 +22,15 @@ class IResolver:
object_type: Type[Any] object_type: Type[Any]
object_type_str: str object_type_str: str
user_subdir: Optional[str] = None user_subdir: Optional[str] = None
initial_search_path: Path initial_search_path: Optional[Path]
@classmethod @classmethod
def build_search_paths(cls, config: Dict[str, Any], user_subdir: Optional[str] = None, def build_search_paths(cls, config: Dict[str, Any], user_subdir: Optional[str] = None,
extra_dir: Optional[str] = None) -> List[Path]: extra_dir: Optional[str] = None) -> List[Path]:
abs_paths: List[Path] = [cls.initial_search_path] abs_paths: List[Path] = []
if cls.initial_search_path:
abs_paths.append(cls.initial_search_path)
if user_subdir: if user_subdir:
abs_paths.insert(0, config['user_data_dir'].joinpath(user_subdir)) abs_paths.insert(0, config['user_data_dir'].joinpath(user_subdir))

View File

@ -27,7 +27,7 @@ class StrategyResolver(IResolver):
object_type = IStrategy object_type = IStrategy
object_type_str = "Strategy" object_type_str = "Strategy"
user_subdir = USERPATH_STRATEGIES user_subdir = USERPATH_STRATEGIES
initial_search_path = Path(__file__).parent.parent.joinpath('strategy').resolve() initial_search_path = None
@staticmethod @staticmethod
def load_strategy(config: Dict[str, Any] = None) -> IStrategy: def load_strategy(config: Dict[str, Any] = None) -> IStrategy:

View File

@ -640,7 +640,7 @@ def test_start_list_strategies(mocker, caplog, capsys):
args = [ args = [
"list-strategies", "list-strategies",
"--strategy-path", "--strategy-path",
str(Path(__file__).parent.parent / "strategy"), str(Path(__file__).parent.parent / "strategy" / "strats"),
"-1" "-1"
] ]
pargs = get_args(args) pargs = get_args(args)
@ -655,7 +655,7 @@ def test_start_list_strategies(mocker, caplog, capsys):
args = [ args = [
"list-strategies", "list-strategies",
"--strategy-path", "--strategy-path",
str(Path(__file__).parent.parent / "strategy"), str(Path(__file__).parent.parent / "strategy" / "strats"),
] ]
pargs = get_args(args) pargs = get_args(args)
# pargs['config'] = None # pargs['config'] = None

View File

@ -257,6 +257,7 @@ def default_conf(testdatadir):
"db_url": "sqlite://", "db_url": "sqlite://",
"user_data_dir": Path("user_data"), "user_data_dir": Path("user_data"),
"verbosity": 3, "verbosity": 3,
"strategy_path": str(Path(__file__).parent / "strategy" / "strats"),
"strategy": "DefaultStrategy" "strategy": "DefaultStrategy"
} }
return configuration return configuration

View File

@ -715,14 +715,14 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog, testdatadir):
'backtesting', 'backtesting',
'--config', 'config.json', '--config', 'config.json',
'--datadir', str(testdatadir), '--datadir', str(testdatadir),
'--strategy-path', str(Path(__file__).parents[2] / 'freqtrade/templates'), '--strategy-path', str(Path(__file__).parents[1] / 'strategy/strats'),
'--ticker-interval', '1m', '--ticker-interval', '1m',
'--timerange', '1510694220-1510700340', '--timerange', '1510694220-1510700340',
'--enable-position-stacking', '--enable-position-stacking',
'--disable-max-market-positions', '--disable-max-market-positions',
'--strategy-list', '--strategy-list',
'DefaultStrategy', 'DefaultStrategy',
'SampleStrategy', 'TestStrategyLegacy',
] ]
args = get_args(args) args = get_args(args)
start_backtesting(args) start_backtesting(args)
@ -745,7 +745,7 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog, testdatadir):
'up to 2017-11-14T22:58:00+00:00 (0 days)..', 'up to 2017-11-14T22:58:00+00:00 (0 days)..',
'Parameter --enable-position-stacking detected ...', 'Parameter --enable-position-stacking detected ...',
'Running backtesting for Strategy DefaultStrategy', 'Running backtesting for Strategy DefaultStrategy',
'Running backtesting for Strategy SampleStrategy', 'Running backtesting for Strategy TestStrategyLegacy',
] ]
for line in exists: for line in exists:

View File

@ -1,6 +1,6 @@
from pandas import DataFrame from pandas import DataFrame
from freqtrade.strategy.default_strategy import DefaultStrategy from .strats.default_strategy import DefaultStrategy
def test_default_strategy_structure(): def test_default_strategy_structure():

View File

@ -10,7 +10,7 @@ from freqtrade.configuration import TimeRange
from freqtrade.data.history import load_data from freqtrade.data.history import load_data
from freqtrade.persistence import Trade from freqtrade.persistence import Trade
from freqtrade.resolvers import StrategyResolver from freqtrade.resolvers import StrategyResolver
from freqtrade.strategy.default_strategy import DefaultStrategy from .strats.default_strategy import DefaultStrategy
from tests.conftest import get_patched_exchange, log_has from tests.conftest import get_patched_exchange, log_has
# Avoid to reinit the same object again and again # Avoid to reinit the same object again and again

View File

@ -2,7 +2,6 @@
import logging import logging
import warnings import warnings
from base64 import urlsafe_b64encode from base64 import urlsafe_b64encode
from os import path
from pathlib import Path from pathlib import Path
import pytest import pytest
@ -15,7 +14,7 @@ from tests.conftest import log_has, log_has_re
def test_search_strategy(): def test_search_strategy():
default_location = Path(__file__).parent.parent.joinpath('strategy').resolve() default_location = Path(__file__).parent / 'strats'
s, _ = StrategyResolver._search_object( s, _ = StrategyResolver._search_object(
directory=default_location, directory=default_location,
@ -31,21 +30,21 @@ def test_search_strategy():
def test_search_all_strategies_no_failed(): def test_search_all_strategies_no_failed():
directory = Path(__file__).parent directory = Path(__file__).parent / "strats"
strategies = StrategyResolver.search_all_objects(directory, enum_failed=False) strategies = StrategyResolver.search_all_objects(directory, enum_failed=False)
assert isinstance(strategies, list) assert isinstance(strategies, list)
assert len(strategies) == 3 assert len(strategies) == 2
assert isinstance(strategies[0], dict) assert isinstance(strategies[0], dict)
def test_search_all_strategies_with_failed(): def test_search_all_strategies_with_failed():
directory = Path(__file__).parent directory = Path(__file__).parent / "strats"
strategies = StrategyResolver.search_all_objects(directory, enum_failed=True) strategies = StrategyResolver.search_all_objects(directory, enum_failed=True)
assert isinstance(strategies, list) assert isinstance(strategies, list)
assert len(strategies) == 4 assert len(strategies) == 3
# with enum_failed=True search_all_objects() shall find 3 good strategies # with enum_failed=True search_all_objects() shall find 2 good strategies
# and 1 which fails to load # and 1 which fails to load
assert len([x for x in strategies if x['class'] is not None]) == 3 assert len([x for x in strategies if x['class'] is not None]) == 2
assert len([x for x in strategies if x['class'] is None]) == 1 assert len([x for x in strategies if x['class'] is None]) == 1
@ -72,13 +71,12 @@ def test_load_strategy_base64(result, caplog, default_conf):
def test_load_strategy_invalid_directory(result, caplog, default_conf): def test_load_strategy_invalid_directory(result, caplog, default_conf):
default_conf['strategy'] = 'DefaultStrategy' default_conf['strategy'] = 'DefaultStrategy'
extra_dir = Path.cwd() / 'some/path' extra_dir = Path.cwd() / 'some/path'
strategy = StrategyResolver._load_strategy('DefaultStrategy', config=default_conf, with pytest.raises(OperationalException):
extra_dir=extra_dir) StrategyResolver._load_strategy('DefaultStrategy', config=default_conf,
extra_dir=extra_dir)
assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog) assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog)
assert 'rsi' in strategy.advise_indicators(result, {'pair': 'ETH/BTC'})
def test_load_not_found_strategy(default_conf): def test_load_not_found_strategy(default_conf):
default_conf['strategy'] = 'NotFoundStrategy' default_conf['strategy'] = 'NotFoundStrategy'
@ -326,7 +324,7 @@ def test_strategy_override_use_sell_profit_only(caplog, default_conf):
@pytest.mark.filterwarnings("ignore:deprecated") @pytest.mark.filterwarnings("ignore:deprecated")
def test_deprecate_populate_indicators(result, default_conf): def test_deprecate_populate_indicators(result, default_conf):
default_location = path.join(path.dirname(path.realpath(__file__))) default_location = Path(__file__).parent / "strats"
default_conf.update({'strategy': 'TestStrategyLegacy', default_conf.update({'strategy': 'TestStrategyLegacy',
'strategy_path': default_location}) 'strategy_path': default_location})
strategy = StrategyResolver.load_strategy(default_conf) strategy = StrategyResolver.load_strategy(default_conf)
@ -360,7 +358,7 @@ def test_deprecate_populate_indicators(result, default_conf):
@pytest.mark.filterwarnings("ignore:deprecated") @pytest.mark.filterwarnings("ignore:deprecated")
def test_call_deprecated_function(result, monkeypatch, default_conf): def test_call_deprecated_function(result, monkeypatch, default_conf):
default_location = path.join(path.dirname(path.realpath(__file__))) default_location = Path(__file__).parent / "strats"
default_conf.update({'strategy': 'TestStrategyLegacy', default_conf.update({'strategy': 'TestStrategyLegacy',
'strategy_path': default_location}) 'strategy_path': default_location})
strategy = StrategyResolver.load_strategy(default_conf) strategy = StrategyResolver.load_strategy(default_conf)

View File

@ -212,6 +212,7 @@ def test_load_config_file_exception(mocker) -> None:
def test_load_config(default_conf, mocker) -> None: def test_load_config(default_conf, mocker) -> None:
del default_conf['strategy_path']
patched_configuration_load_config_file(mocker, default_conf) patched_configuration_load_config_file(mocker, default_conf)
args = Arguments(['trade']).get_parsed_arg() args = Arguments(['trade']).get_parsed_arg()