diff --git a/freqtrade/commands/list_commands.py b/freqtrade/commands/list_commands.py index c8d476717..b33421858 100644 --- a/freqtrade/commands/list_commands.py +++ b/freqtrade/commands/list_commands.py @@ -246,88 +246,87 @@ def start_list_markets(args: dict[str, Any], pairs_only: bool = False) -> None: except Exception as e: raise OperationalException(f"Cannot get markets. Reason: {e}") from e - else: - summary_str = ( - (f"Exchange {exchange.name} has {len(pairs)} ") - + ("active " if active_only else "") - + (plural(len(pairs), "pair" if pairs_only else "market")) - + ( - f" with {', '.join(base_currencies)} as base " - f"{plural(len(base_currencies), 'currency', 'currencies')}" - if base_currencies - else "" - ) - + (" and" if base_currencies and quote_currencies else "") - + ( - f" with {', '.join(quote_currencies)} as quote " - f"{plural(len(quote_currencies), 'currency', 'currencies')}" - if quote_currencies - else "" - ) + summary_str = ( + (f"Exchange {exchange.name} has {len(pairs)} ") + + ("active " if active_only else "") + + (plural(len(pairs), "pair" if pairs_only else "market")) + + ( + f" with {', '.join(base_currencies)} as base " + f"{plural(len(base_currencies), 'currency', 'currencies')}" + if base_currencies + else "" ) + + (" and" if base_currencies and quote_currencies else "") + + ( + f" with {', '.join(quote_currencies)} as quote " + f"{plural(len(quote_currencies), 'currency', 'currencies')}" + if quote_currencies + else "" + ) + ) - headers = [ - "Id", - "Symbol", - "Base", - "Quote", - "Active", - "Spot", - "Margin", - "Future", - "Leverage", - ] + headers = [ + "Id", + "Symbol", + "Base", + "Quote", + "Active", + "Spot", + "Margin", + "Future", + "Leverage", + ] - tabular_data = [ - { - "Id": v["id"], - "Symbol": v["symbol"], - "Base": v["base"], - "Quote": v["quote"], - "Active": market_is_active(v), - "Spot": "Spot" if exchange.market_is_spot(v) else "", - "Margin": "Margin" if exchange.market_is_margin(v) else "", - "Future": "Future" if exchange.market_is_future(v) else "", - "Leverage": exchange.get_max_leverage(v["symbol"], 20), - } - for _, v in pairs.items() - ] + tabular_data = [ + { + "Id": v["id"], + "Symbol": v["symbol"], + "Base": v["base"], + "Quote": v["quote"], + "Active": market_is_active(v), + "Spot": "Spot" if exchange.market_is_spot(v) else "", + "Margin": "Margin" if exchange.market_is_margin(v) else "", + "Future": "Future" if exchange.market_is_future(v) else "", + "Leverage": exchange.get_max_leverage(v["symbol"], 20), + } + for _, v in pairs.items() + ] - if ( - args.get("print_one_column", False) - or args.get("list_pairs_print_json", False) - or args.get("print_csv", False) - ): - # Print summary string in the log in case of machine-readable - # regular formats. - logger.info(f"{summary_str}.") + if ( + args.get("print_one_column", False) + or args.get("list_pairs_print_json", False) + or args.get("print_csv", False) + ): + # Print summary string in the log in case of machine-readable + # regular formats. + logger.info(f"{summary_str}.") + else: + # Print empty string separating leading logs and output in case of + # human-readable formats. + print() + + if pairs: + if args.get("print_list", False): + # print data as a list, with human-readable summary + print(f"{summary_str}: {', '.join(pairs.keys())}.") + elif args.get("print_one_column", False): + print("\n".join(pairs.keys())) + elif args.get("list_pairs_print_json", False): + import rapidjson + + print(rapidjson.dumps(list(pairs.keys()), default=str)) + elif args.get("print_csv", False): + writer = csv.DictWriter(sys.stdout, fieldnames=headers) + writer.writeheader() + writer.writerows(tabular_data) else: - # Print empty string separating leading logs and output in case of - # human-readable formats. - print() - - if pairs: - if args.get("print_list", False): - # print data as a list, with human-readable summary - print(f"{summary_str}: {', '.join(pairs.keys())}.") - elif args.get("print_one_column", False): - print("\n".join(pairs.keys())) - elif args.get("list_pairs_print_json", False): - import rapidjson - - print(rapidjson.dumps(list(pairs.keys()), default=str)) - elif args.get("print_csv", False): - writer = csv.DictWriter(sys.stdout, fieldnames=headers) - writer.writeheader() - writer.writerows(tabular_data) - else: - print_rich_table(tabular_data, headers, summary_str) - elif not ( - args.get("print_one_column", False) - or args.get("list_pairs_print_json", False) - or args.get("print_csv", False) - ): - print(f"{summary_str}.") + print_rich_table(tabular_data, headers, summary_str) + elif not ( + args.get("print_one_column", False) + or args.get("list_pairs_print_json", False) + or args.get("print_csv", False) + ): + print(f"{summary_str}.") def start_show_trades(args: dict[str, Any]) -> None: