Add create-userdir command to initialize a user directory
This commit is contained in:
parent
6c3a0eb1d6
commit
23435512c4
@ -31,6 +31,8 @@ ARGS_EDGE = ARGS_COMMON_OPTIMIZE + ["stoploss_range"]
|
||||
|
||||
ARGS_LIST_EXCHANGES = ["print_one_column"]
|
||||
|
||||
ARGS_CREATE_USERDIR = ["user_data_dir"]
|
||||
|
||||
ARGS_DOWNLOADER = ARGS_COMMON + ["pairs", "pairs_file", "days", "exchange", "timeframes", "erase"]
|
||||
|
||||
ARGS_PLOT_DATAFRAME = (ARGS_COMMON + ARGS_STRATEGY +
|
||||
@ -106,8 +108,7 @@ class Arguments(object):
|
||||
:return: None
|
||||
"""
|
||||
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')
|
||||
|
||||
# Add backtesting subcommand
|
||||
@ -125,6 +126,11 @@ class Arguments(object):
|
||||
hyperopt_cmd.set_defaults(func=start_hyperopt)
|
||||
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
|
||||
list_exchanges_cmd = subparsers.add_parser(
|
||||
'list-exchanges',
|
||||
|
@ -58,6 +58,11 @@ AVAILABLE_CLI_OPTIONS = {
|
||||
help='Path to backtest data.',
|
||||
metavar='PATH',
|
||||
),
|
||||
"user_data_dir": Arg(
|
||||
'--userdir', '--user-data-dir',
|
||||
help='Path to Userdata Directory.',
|
||||
metavar='PATH',
|
||||
),
|
||||
# Main options
|
||||
"strategy": Arg(
|
||||
'-s', '--strategy',
|
||||
|
@ -6,11 +6,12 @@ import logging
|
||||
import sys
|
||||
import warnings
|
||||
from argparse import Namespace
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Dict, Optional
|
||||
|
||||
from freqtrade import OperationalException, constants
|
||||
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.loggers import setup_logging
|
||||
from freqtrade.misc import deep_merge_dicts
|
||||
@ -173,6 +174,12 @@ class Configuration(object):
|
||||
Extract information for sys.argv and load datadir configuration:
|
||||
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:
|
||||
config.update({'datadir': create_datadir(config, self.args.datadir)})
|
||||
else:
|
||||
|
@ -234,6 +234,7 @@ def default_conf():
|
||||
},
|
||||
"initial_state": "running",
|
||||
"db_url": "sqlite://",
|
||||
"user_data_dir": "user_data",
|
||||
"verbosity": 3,
|
||||
}
|
||||
return configuration
|
||||
|
@ -1,12 +1,13 @@
|
||||
import logging
|
||||
import sys
|
||||
from argparse import Namespace
|
||||
from typing import Any, Dict
|
||||
|
||||
from freqtrade.configuration import Configuration
|
||||
from freqtrade.configuration.folder_operations import create_userdata_dir
|
||||
from freqtrade.exchange import available_exchanges
|
||||
from freqtrade.state import RunMode
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -39,3 +40,16 @@ def start_list_exchanges(args: Namespace) -> None:
|
||||
else:
|
||||
print(f"Exchanges supported by ccxt and available for Freqtrade: "
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user