Add create-userdir command to initialize a user directory

This commit is contained in:
Matthias 2019-07-21 14:13:38 +02:00
parent 6c3a0eb1d6
commit 23435512c4
5 changed files with 37 additions and 4 deletions

View File

@ -31,6 +31,8 @@ ARGS_EDGE = ARGS_COMMON_OPTIMIZE + ["stoploss_range"]
ARGS_LIST_EXCHANGES = ["print_one_column"] ARGS_LIST_EXCHANGES = ["print_one_column"]
ARGS_CREATE_USERDIR = ["user_data_dir"]
ARGS_DOWNLOADER = ARGS_COMMON + ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"] ARGS_DOWNLOADER = ARGS_COMMON + ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"]
ARGS_PLOT_DATAFRAME = (ARGS_COMMON + ARGS_STRATEGY + ARGS_PLOT_DATAFRAME = (ARGS_COMMON + ARGS_STRATEGY +
@ -106,8 +108,7 @@ class Arguments(object):
:return: None :return: None
""" """
from freqtrade.optimize import start_backtesting, start_hyperopt, start_edge from freqtrade.optimize import start_backtesting, start_hyperopt, start_edge
from freqtrade.utils import start_list_exchanges from freqtrade.utils import start_create_userdir, start_list_exchanges
subparsers = self.parser.add_subparsers(dest='subparser') subparsers = self.parser.add_subparsers(dest='subparser')
# Add backtesting subcommand # Add backtesting subcommand
@ -125,6 +126,11 @@ class Arguments(object):
hyperopt_cmd.set_defaults(func=start_hyperopt) hyperopt_cmd.set_defaults(func=start_hyperopt)
self._build_args(optionlist=ARGS_HYPEROPT, parser=hyperopt_cmd) self._build_args(optionlist=ARGS_HYPEROPT, parser=hyperopt_cmd)
create_userdir_cmd = subparsers.add_parser('create-userdir',
help="Create user-data directory.")
create_userdir_cmd.set_defaults(func=start_create_userdir)
self._build_args(optionlist=ARGS_CREATE_USERDIR, parser=create_userdir_cmd)
# Add list-exchanges subcommand # Add list-exchanges subcommand
list_exchanges_cmd = subparsers.add_parser( list_exchanges_cmd = subparsers.add_parser(
'list-exchanges', 'list-exchanges',

View File

@ -58,6 +58,11 @@ AVAILABLE_CLI_OPTIONS = {
help='Path to backtest data.', help='Path to backtest data.',
metavar='PATH', metavar='PATH',
), ),
"user_data_dir": Arg(
'--userdir', '--user-data-dir',
help='Path to Userdata Directory.',
metavar='PATH',
),
# Main options # Main options
"strategy": Arg( "strategy": Arg(
'-s', '--strategy', '-s', '--strategy',

View File

@ -6,11 +6,12 @@ import logging
import sys import sys
import warnings import warnings
from argparse import Namespace from argparse import Namespace
from pathlib import Path
from typing import Any, Callable, Dict, Optional from typing import Any, Callable, Dict, Optional
from freqtrade import OperationalException, constants from freqtrade import OperationalException, constants
from freqtrade.configuration.check_exchange import check_exchange from freqtrade.configuration.check_exchange import check_exchange
from freqtrade.configuration.folder_operations import create_datadir from freqtrade.configuration.folder_operations import create_datadir, create_userdata_dir
from freqtrade.configuration.json_schema import validate_config_schema from freqtrade.configuration.json_schema import validate_config_schema
from freqtrade.loggers import setup_logging from freqtrade.loggers import setup_logging
from freqtrade.misc import deep_merge_dicts from freqtrade.misc import deep_merge_dicts
@ -173,6 +174,12 @@ class Configuration(object):
Extract information for sys.argv and load datadir configuration: Extract information for sys.argv and load datadir configuration:
the --datadir option the --datadir option
""" """
if 'user_data_dir' in self.args and self.args.user_data_dir:
config.update({'user_data_dir': self.args.user_data_dir})
create_userdata_dir(config['user_data_dir'])
elif 'user_data_dir' not in config:
config.update({'user_data_dir': str(Path.cwd() / "user_data")})
if 'datadir' in self.args and self.args.datadir: if 'datadir' in self.args and self.args.datadir:
config.update({'datadir': create_datadir(config, self.args.datadir)}) config.update({'datadir': create_datadir(config, self.args.datadir)})
else: else:

View File

@ -234,6 +234,7 @@ def default_conf():
}, },
"initial_state": "running", "initial_state": "running",
"db_url": "sqlite://", "db_url": "sqlite://",
"user_data_dir": "user_data",
"verbosity": 3, "verbosity": 3,
} }
return configuration return configuration

View File

@ -1,12 +1,13 @@
import logging import logging
import sys
from argparse import Namespace from argparse import Namespace
from typing import Any, Dict from typing import Any, Dict
from freqtrade.configuration import Configuration from freqtrade.configuration import Configuration
from freqtrade.configuration.folder_operations import create_userdata_dir
from freqtrade.exchange import available_exchanges from freqtrade.exchange import available_exchanges
from freqtrade.state import RunMode from freqtrade.state import RunMode
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -39,3 +40,16 @@ def start_list_exchanges(args: Namespace) -> None:
else: else:
print(f"Exchanges supported by ccxt and available for Freqtrade: " print(f"Exchanges supported by ccxt and available for Freqtrade: "
f"{', '.join(available_exchanges())}") f"{', '.join(available_exchanges())}")
def start_create_userdir(args: Namespace) -> None:
"""
Create "user_data" directory to contain user data strategies, hyperopts, ...)
:param args: Cli args from Arguments()
:return: None
"""
if "user_data_dir" in args and args.user_data_dir:
create_userdata_dir(args.user_data_dir)
else:
logger.warning("`create-userdir` requires --userdir to be set.")
sys.exit(1)