Skip to content

Commit

Permalink
Add second subcommand to allow conversation of ohlcv and trades data
Browse files Browse the repository at this point in the history
seprately
  • Loading branch information
xmatthias committed Dec 28, 2019
1 parent c3064df commit 2a6b542
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
20 changes: 15 additions & 5 deletions freqtrade/configuration/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

ARGS_BUILD_HYPEROPT = ["user_data_dir", "hyperopt", "template"]

ARGS_CONVERT_DATA = []
ARGS_CONVERT_DATA = ["format_from", "format_to"]

ARGS_DOWNLOAD_DATA = ["pairs", "pairs_file", "days", "download_trades", "exchange",
"timeframes", "erase"]
Expand All @@ -65,8 +65,9 @@
ARGS_HYPEROPT_SHOW = ["hyperopt_list_best", "hyperopt_list_profitable", "hyperopt_show_index",
"print_json", "hyperopt_show_no_header"]

NO_CONF_REQURIED = ["convert-data", "download-data", "list-timeframes", "list-markets",
"list-pairs", "list-strategies", "hyperopt-list", "hyperopt-show",
NO_CONF_REQURIED = ["convert-data", "convert-trade-data", "download-data",
"list-timeframes", "list-markets", "list-pairs",
"list-strategies", "hyperopt-list", "hyperopt-show",
"plot-dataframe", "plot-profit"]

NO_CONF_ALLOWED = ["create-userdir", "list-exchanges", "new-hyperopt", "new-strategy"]
Expand Down Expand Up @@ -256,10 +257,19 @@ def _build_subcommands(self) -> None:
# Add convert-data subcommand
convert_data_cmd = subparsers.add_parser(
'convert-data',
help='Convert data from one format to another.',
help='Convert OHLCV data from one format to another.',
parents=[_common_parser],
)
convert_data_cmd.set_defaults(func=start_convert_data)
convert_data_cmd.set_defaults(func=partial(start_convert_data, ohlcv=True))
self._build_args(optionlist=ARGS_CONVERT_DATA, parser=convert_data_cmd)

# Add convert-data subcommand
convert_data_cmd = subparsers.add_parser(
'convert-trade-data',
help='Convert trade-data from one format to another.',
parents=[_common_parser],
)
convert_data_cmd.set_defaults(func=partial(start_convert_data, ohlcv=False))
self._build_args(optionlist=ARGS_CONVERT_DATA, parser=convert_data_cmd)

# Add Plotting subcommand
Expand Down
12 changes: 12 additions & 0 deletions freqtrade/configuration/cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ def __init__(self, *args, **kwargs):
'desired timeframe as specified as --timeframes/-t.',
action='store_true',
),
"format_from": Arg(
'--format-from',
help='Source format for data conversation.',
choices=constants.AVAILABLE_DATAHANDLERS,
required=True,
),
"format_to": Arg(
'--format-to',
help='Destination format for data conversation.',
choices=constants.AVAILABLE_DATAHANDLERS,
required=True,
),
"exchange": Arg(
'--exchange',
help=f'Exchange name (default: `{constants.DEFAULT_EXCHANGE}`). '
Expand Down
10 changes: 7 additions & 3 deletions freqtrade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,19 @@ def convert_ohlcv_format(config: Dict[str, Any], convert_from: str, convert_to:
trg.ohlcv_store(data)


def start_convert_data(args: Dict[str, Any]) -> None:
def start_convert_data(args: Dict[str, Any], ohlcv: bool = True) -> None:
"""
Convert data from one format to another
"""
config = setup_utils_configuration(args, RunMode.UTIL_NO_EXCHANGE)
from pprint import pprint
pprint(config)

# convert_trades_format(config, 'json', 'jsongz')
if ohlcv:
convert_ohlcv_format(config,
convert_from=args['format_from'], convert_to=args['format_to'])
else:
convert_trades_format(config,
convert_from=args['format_from'], convert_to=args['format_to'])


def start_list_timeframes(args: Dict[str, Any]) -> None:
Expand Down

0 comments on commit 2a6b542

Please sign in to comment.