Add --print-json and -1/--one-column options

This commit is contained in:
hroff-1902 2019-10-15 22:31:23 +03:00
parent ad89d19955
commit 89e0c76a3f
3 changed files with 13 additions and 1 deletions

View File

@ -34,7 +34,8 @@ ARGS_LIST_EXCHANGES = ["print_one_column", "list_exchanges_all"]
ARGS_LIST_TIMEFRAMES = ["exchange", "print_one_column"]
ARGS_LIST_PAIRS = ["exchange", "print_list", "base_currency", "quote_currency", "active_only"]
ARGS_LIST_PAIRS = ["exchange", "print_list", "list_pairs_print_json", "print_one_column",
"base_currency", "quote_currency", "active_only"]
ARGS_CREATE_USERDIR = ["user_data_dir"]

View File

@ -262,6 +262,12 @@ AVAILABLE_CLI_OPTIONS = {
'printed in the tabular format.',
action='store_true',
),
"list_pairs_print_json": Arg(
'--print-json',
help='Print list of pairs or market symbols in JSON format.',
action='store_true',
default=False,
),
"quote_currency": Arg(
'--quote-currency',
help='Select quote currency.',

View File

@ -4,6 +4,7 @@ from pathlib import Path
from typing import Any, Dict, List
import arrow
import rapidjson
from tabulate import tabulate
from freqtrade import OperationalException
@ -156,6 +157,10 @@ def start_list_pairs(args: Dict[str, Any], pairs_only: bool = False) -> None:
(" and" if base_currency and quote_currency else "") +
(f" with {quote_currency} as quote currency" if quote_currency else "") +
(f": {', '.join(sorted(pairs.keys()))}" if len(pairs) else "") + ".")
elif args.get('print_one_column', False):
print('\n'.join(sorted(pairs.keys())))
elif args.get('list_pairs_print_json', False):
print(rapidjson.dumps(sorted(pairs.keys()), default=str))
else:
# print data as a table
headers = ['Id', 'Symbol', 'Base', 'Quote', 'Active']