Disable Defaulting to DefaultStrategy

This commit is contained in:
Matthias 2019-09-21 19:54:44 +02:00
parent 52ff391c8a
commit b73426b91f
11 changed files with 25 additions and 14 deletions

View File

@ -28,11 +28,11 @@ jobs:
name: pytest name: pytest
- script: - script:
- cp config.json.example config.json - cp config.json.example config.json
- freqtrade backtesting --datadir tests/testdata - freqtrade backtesting --datadir tests/testdata --strategy DefaultStrategy
name: backtest name: backtest
- script: - script:
- cp config.json.example config.json - cp config.json.example config.json
- freqtrade hyperopt --datadir tests/testdata -e 5 - freqtrade hyperopt --datadir tests/testdata -e 5 --strategy DefaultStrategy
name: hyperopt name: hyperopt
- script: flake8 - script: flake8
name: flake8 name: flake8

View File

@ -23,7 +23,7 @@ if [ $? -ne 0 ]; then
fi fi
# Run backtest # Run backtest
docker run --rm -it -v $(pwd)/config.json.example:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG} --datadir /tests/testdata backtesting docker run --rm -it -v $(pwd)/config.json.example:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG} backtesting --datadir /tests/testdata --strategy DefaultStrategy
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "failed running backtest" echo "failed running backtest"

View File

@ -60,8 +60,8 @@ Common arguments:
Strategy arguments: Strategy arguments:
-s NAME, --strategy NAME -s NAME, --strategy NAME
Specify strategy class name (default: Specify strategy class name which will be used by the
`DefaultStrategy`). bot.
--strategy-path PATH Specify additional strategy lookup path. --strategy-path PATH Specify additional strategy lookup path.
``` ```

View File

@ -95,7 +95,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `db_url` | `sqlite:///tradesv3.sqlite`| Declares database URL to use. NOTE: This defaults to `sqlite://` if `dry_run` is `True`. | `db_url` | `sqlite:///tradesv3.sqlite`| Declares database URL to use. NOTE: This defaults to `sqlite://` if `dry_run` is `True`.
| `initial_state` | running | Defines the initial application state. More information below. | `initial_state` | running | Defines the initial application state. More information below.
| `forcebuy_enable` | false | Enables the RPC Commands to force a buy. More information below. | `forcebuy_enable` | false | Enables the RPC Commands to force a buy. More information below.
| `strategy` | DefaultStrategy | Defines Strategy class to use. | `strategy` | None | **Required** Defines Strategy class to use. Recommended to set via `--strategy NAME`.
| `strategy_path` | null | Adds an additional strategy lookup path (must be a directory). | `strategy_path` | null | Adds an additional strategy lookup path (must be a directory).
| `internals.process_throttle_secs` | 5 | **Required.** Set the process throttle. Value in second. | `internals.process_throttle_secs` | 5 | **Required.** Set the process throttle. Value in second.
| `internals.sd_notify` | false | Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See [here](installation.md#7-optional-configure-freqtrade-as-a-systemd-service) for more details. | `internals.sd_notify` | false | Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See [here](installation.md#7-optional-configure-freqtrade-as-a-systemd-service) for more details.

View File

@ -66,9 +66,8 @@ AVAILABLE_CLI_OPTIONS = {
# Main options # Main options
"strategy": Arg( "strategy": Arg(
'-s', '--strategy', '-s', '--strategy',
help='Specify strategy class name (default: `%(default)s`).', help='Specify strategy class name which will be used by the bot.',
metavar='NAME', metavar='NAME',
default='DefaultStrategy',
), ),
"strategy_path": Arg( "strategy_path": Arg(
'--strategy-path', '--strategy-path',

View File

@ -128,7 +128,7 @@ class Configuration:
self._process_logging_options(config) self._process_logging_options(config)
# Set strategy if not specified in config and or if it's non default # Set strategy if not specified in config and or if it's non default
if self.args.get("strategy") != constants.DEFAULT_STRATEGY or not config.get('strategy'): if self.args.get("strategy") or not config.get('strategy'):
config.update({'strategy': self.args.get("strategy")}) config.update({'strategy': self.args.get("strategy")})
self._args_to_config(config, argname='strategy_path', self._args_to_config(config, argname='strategy_path',

View File

@ -9,7 +9,6 @@ PROCESS_THROTTLE_SECS = 5 # sec
DEFAULT_TICKER_INTERVAL = 5 # min DEFAULT_TICKER_INTERVAL = 5 # min
HYPEROPT_EPOCH = 100 # epochs HYPEROPT_EPOCH = 100 # epochs
RETRY_TIMEOUT = 30 # sec RETRY_TIMEOUT = 30 # sec
DEFAULT_STRATEGY = 'DefaultStrategy'
DEFAULT_HYPEROPT = 'DefaultHyperOpts' DEFAULT_HYPEROPT = 'DefaultHyperOpts'
DEFAULT_HYPEROPT_LOSS = 'DefaultHyperOptLoss' DEFAULT_HYPEROPT_LOSS = 'DefaultHyperOptLoss'
DEFAULT_DB_PROD_URL = 'sqlite:///tradesv3.sqlite' DEFAULT_DB_PROD_URL = 'sqlite:///tradesv3.sqlite'

View File

@ -32,8 +32,11 @@ class StrategyResolver(IResolver):
""" """
config = config or {} config = config or {}
# Verify the strategy is in the configuration, otherwise fallback to the default strategy if not config.get('strategy'):
strategy_name = config.get('strategy') or constants.DEFAULT_STRATEGY raise OperationalException("No strategy set. Please use `--strategy` to specify "
"the strategy class to use.")
strategy_name = config['strategy']
self.strategy: IStrategy = self._load_strategy(strategy_name, self.strategy: IStrategy = self._load_strategy(strategy_name,
config=config, config=config,
extra_dir=config.get('strategy_path')) extra_dir=config.get('strategy_path'))

View File

@ -242,6 +242,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": "DefaultStrategy"
} }
return configuration return configuration

View File

@ -55,6 +55,7 @@ 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'] = 'SampleStrategy'
resolver = StrategyResolver(default_conf) resolver = StrategyResolver(default_conf)
extra_dir = Path.cwd() / 'some/path' extra_dir = Path.cwd() / 'some/path'
resolver._load_strategy('SampleStrategy', config=default_conf, extra_dir=extra_dir) resolver._load_strategy('SampleStrategy', config=default_conf, extra_dir=extra_dir)
@ -65,13 +66,22 @@ def test_load_strategy_invalid_directory(result, caplog, default_conf):
def test_load_not_found_strategy(default_conf): def test_load_not_found_strategy(default_conf):
strategy = StrategyResolver(default_conf) default_conf['strategy'] = 'NotFoundStrategy'
with pytest.raises(OperationalException, with pytest.raises(OperationalException,
match=r"Impossible to load Strategy 'NotFoundStrategy'. " match=r"Impossible to load Strategy 'NotFoundStrategy'. "
r"This class does not exist or contains Python code errors."): r"This class does not exist or contains Python code errors."):
strategy = StrategyResolver(default_conf)
strategy._load_strategy(strategy_name='NotFoundStrategy', config=default_conf) strategy._load_strategy(strategy_name='NotFoundStrategy', config=default_conf)
def test_load_strategy_noname(default_conf):
default_conf['strategy'] = ''
with pytest.raises(OperationalException,
match="No strategy set. Please use `--strategy` to specify "
"the strategy class to use."):
StrategyResolver(default_conf)
def test_strategy(result, default_conf): def test_strategy(result, default_conf):
default_conf.update({'strategy': 'DefaultStrategy'}) default_conf.update({'strategy': 'DefaultStrategy'})

View File

@ -212,7 +212,6 @@ def test_load_config(default_conf, mocker) -> None:
configuration = Configuration(args) configuration = Configuration(args)
validated_conf = configuration.load_config() validated_conf = configuration.load_config()
assert validated_conf.get('strategy') == 'DefaultStrategy'
assert validated_conf.get('strategy_path') is None assert validated_conf.get('strategy_path') is None
assert 'edge' not in validated_conf assert 'edge' not in validated_conf