From 768a51cb9bebb70e3bd2b3b468d7e8d8a4896d1e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 6 Jul 2024 18:26:36 +0200 Subject: [PATCH] Extract rich_table print to utils --- freqtrade/commands/list_commands.py | 16 ++-------------- freqtrade/util/__init__.py | 2 ++ freqtrade/util/rich_tables.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 freqtrade/util/rich_tables.py diff --git a/freqtrade/commands/list_commands.py b/freqtrade/commands/list_commands.py index e473d6e90..ea2c84ae9 100644 --- a/freqtrade/commands/list_commands.py +++ b/freqtrade/commands/list_commands.py @@ -15,6 +15,7 @@ from freqtrade.exchange import list_available_exchanges, market_is_active from freqtrade.misc import parse_db_uri_for_logging, plural from freqtrade.resolvers import ExchangeResolver, StrategyResolver from freqtrade.types.valid_exchanges_type import ValidExchangesType +from freqtrade.util import print_rich_table logger = logging.getLogger(__name__) @@ -77,19 +78,6 @@ def start_list_exchanges(args: Dict[str, Any]) -> None: console.print(table) -def _print_rich_table(summary: str, headers: List[str], tabular_data: List[Dict[str, Any]]) -> None: - table = Table(title=summary) - - for header in headers: - 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) - - def _print_objs_tabular(objs: List, print_colorized: bool) -> None: names = [s["name"] for s in objs] objs_to_print = [ @@ -292,7 +280,7 @@ def start_list_markets(args: Dict[str, Any], pairs_only: bool = False) -> None: writer.writeheader() writer.writerows(tabular_data) else: - _print_rich_table(summary_str, headers, tabular_data) + print_rich_table(summary_str, headers, tabular_data) elif not ( args.get("print_one_column", False) or args.get("list_pairs_print_json", False) diff --git a/freqtrade/util/__init__.py b/freqtrade/util/__init__.py index 503f5861a..f478829e6 100644 --- a/freqtrade/util/__init__.py +++ b/freqtrade/util/__init__.py @@ -15,6 +15,7 @@ from freqtrade.util.formatters import decimals_per_coin, fmt_coin, round_value from freqtrade.util.ft_precise import FtPrecise from freqtrade.util.measure_time import MeasureTime from freqtrade.util.periodic_cache import PeriodicCache +from freqtrade.util.rich_tables import print_rich_table from freqtrade.util.template_renderer import render_template, render_template_with_fallback # noqa @@ -36,4 +37,5 @@ __all__ = [ "round_value", "fmt_coin", "MeasureTime", + "print_rich_table", ] diff --git a/freqtrade/util/rich_tables.py b/freqtrade/util/rich_tables.py new file mode 100644 index 000000000..f773a4fd1 --- /dev/null +++ b/freqtrade/util/rich_tables.py @@ -0,0 +1,17 @@ +from typing import Any, Dict, List + +from rich.console import Console +from rich.table import Table + + +def print_rich_table(summary: str, headers: List[str], tabular_data: List[Dict[str, Any]]) -> None: + table = Table(title=summary) + + for header in headers: + 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)