diff --git a/freqtrade/optimize/edge_cli.py b/freqtrade/optimize/edge_cli.py index 9bd8ff1c9..65dd30efc 100644 --- a/freqtrade/optimize/edge_cli.py +++ b/freqtrade/optimize/edge_cli.py @@ -52,4 +52,4 @@ class EdgeCli: result = self.edge.calculate(self.config["exchange"]["pair_whitelist"]) if result: print("") # blank line for readability - print(generate_edge_table(self.edge._cached_pairs)) + generate_edge_table(self.edge._cached_pairs) diff --git a/freqtrade/optimize/optimize_reports/bt_output.py b/freqtrade/optimize/optimize_reports/bt_output.py index 3ef35236b..c88a9bd06 100644 --- a/freqtrade/optimize/optimize_reports/bt_output.py +++ b/freqtrade/optimize/optimize_reports/bt_output.py @@ -475,7 +475,6 @@ def show_sorted_pairlist(config: Config, backtest_stats: BacktestResultType): def generate_edge_table(results: dict) -> str: - floatfmt = ("s", ".10g", ".2f", ".2f", ".2f", ".2f", "d", "d", "d") tabular_data = [] headers = [ "Pair", @@ -493,17 +492,13 @@ def generate_edge_table(results: dict) -> str: tabular_data.append( [ result[0], - result[1].stoploss, - result[1].winrate, - result[1].risk_reward_ratio, - result[1].required_risk_reward, - result[1].expectancy, + f"{result[1].stoploss:.10g}", + f"{result[1].winrate:.2f}", + f"{result[1].risk_reward_ratio:.2f}", + f"{result[1].required_risk_reward:.2f}", + f"{result[1].expectancy:.2f}", result[1].nb_trades, round(result[1].avg_trade_duration), ] ) - - # Ignore type as floatfmt does allow tuples but mypy does not know that - return tabulate( - tabular_data, headers=headers, floatfmt=floatfmt, tablefmt="orgtbl", stralign="right" - ) + print_rich_table(tabular_data, headers, summary="EDGE TABLE") diff --git a/tests/optimize/test_optimize_reports.py b/tests/optimize/test_optimize_reports.py index 53366a234..4c7ce06e8 100644 --- a/tests/optimize/test_optimize_reports.py +++ b/tests/optimize/test_optimize_reports.py @@ -538,12 +538,12 @@ def test_text_table_strategy(testdatadir, capsys): ) -def test_generate_edge_table(): +def test_generate_edge_table(capsys): results = {} results["ETH/BTC"] = PairInfo(-0.01, 0.60, 2, 1, 3, 10, 60) - text = generate_edge_table(results) - assert text.count("+") == 7 - assert text.count("| ETH/BTC |") == 1 + generate_edge_table(results) + text = capsys.readouterr().out + assert re.search(r".* ETH/BTC .*", text) assert re.search(r".* Risk Reward Ratio .* Required Risk Reward .* Expectancy .*", text)