Use Rich table for pair list output
This commit is contained in:
@@ -280,9 +280,14 @@ def start_list_markets(args: Dict[str, Any], pairs_only: bool = False) -> None:
|
|||||||
writer.writeheader()
|
writer.writeheader()
|
||||||
writer.writerows(tabular_data)
|
writer.writerows(tabular_data)
|
||||||
else:
|
else:
|
||||||
# print data as a table, with the human-readable summary
|
table = Table(title=summary_str)
|
||||||
print(f"{summary_str}:")
|
for header in headers:
|
||||||
print(tabulate(tabular_data, headers="keys", tablefmt="psql", stralign="right"))
|
table.add_column(header, justify="right")
|
||||||
|
for row in tabular_data:
|
||||||
|
table.add_row(*[str(row[header]) for header in headers])
|
||||||
|
|
||||||
|
console = Console()
|
||||||
|
console.print(table)
|
||||||
elif not (
|
elif not (
|
||||||
args.get("print_one_column", False)
|
args.get("print_one_column", False)
|
||||||
or args.get("list_pairs_print_json", False)
|
or args.get("list_pairs_print_json", False)
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
|||||||
pargs["config"] = None
|
pargs["config"] = None
|
||||||
start_list_markets(pargs, False)
|
start_list_markets(pargs, False)
|
||||||
captured = capsys.readouterr()
|
captured = capsys.readouterr()
|
||||||
assert re.match("\nExchange Binance has 12 active markets:\n", captured.out)
|
assert re.search(r".*Exchange Binance has 12 active markets.*", captured.out)
|
||||||
|
|
||||||
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
|
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
|
||||||
# Test with --all: all markets
|
# Test with --all: all markets
|
||||||
@@ -491,7 +491,7 @@ def test_list_markets(mocker, markets_static, capsys):
|
|||||||
]
|
]
|
||||||
start_list_markets(get_args(args), False)
|
start_list_markets(get_args(args), False)
|
||||||
captured = capsys.readouterr()
|
captured = capsys.readouterr()
|
||||||
assert "Exchange Binance has 12 active markets:\n" in captured.out
|
assert "Exchange Binance has 12 active markets" in captured.out
|
||||||
|
|
||||||
# Test tabular output, no markets found
|
# Test tabular output, no markets found
|
||||||
args = [
|
args = [
|
||||||
|
|||||||
Reference in New Issue
Block a user