Sort tabular and csv data by symbol as well

This commit is contained in:
hroff-1902 2019-10-17 03:06:51 +03:00
parent a8ffd29e18
commit 837d4d82b4

View File

@ -1,5 +1,6 @@
import logging import logging
import sys import sys
from collections import OrderedDict
from pathlib import Path from pathlib import Path
from typing import Any, Dict, List from typing import Any, Dict, List
@ -147,6 +148,8 @@ def start_list_pairs(args: Dict[str, Any], pairs_only: bool = False) -> None: #
quote_currencies=quote_currencies, quote_currencies=quote_currencies,
pairs_only=pairs_only, pairs_only=pairs_only,
active_only=active_only) active_only=active_only)
# Sort the pairs/markets by symbol
pairs = OrderedDict(sorted(pairs.items()))
except Exception as e: except Exception as e:
raise OperationalException(f"Cannot get markets. Reason: {e}") from e raise OperationalException(f"Cannot get markets. Reason: {e}") from e
@ -180,13 +183,13 @@ def start_list_pairs(args: Dict[str, Any], pairs_only: bool = False) -> None: #
if args.get('print_list', False): if args.get('print_list', False):
# print data as a list, with human-readable summary # print data as a list, with human-readable summary
print(summary_str + print(summary_str +
(f": {', '.join(sorted(pairs.keys()))}" if len(pairs) else "") + ".") (f": {', '.join(pairs.keys())}" if len(pairs) else "") + ".")
elif args.get('print_one_column', False): elif args.get('print_one_column', False):
if len(pairs): if len(pairs):
print('\n'.join(sorted(pairs.keys()))) print('\n'.join(pairs.keys()))
elif args.get('list_pairs_print_json', False): elif args.get('list_pairs_print_json', False):
if len(pairs): if len(pairs):
print(rapidjson.dumps(sorted(pairs.keys()), default=str)) print(rapidjson.dumps(pairs.keys(), default=str))
elif args.get('print_csv', False): elif args.get('print_csv', False):
if len(pairs): if len(pairs):
writer = csv.DictWriter(sys.stdout, fieldnames=headers) writer = csv.DictWriter(sys.stdout, fieldnames=headers)