fix: align profit calculations between best pair and /performance

part of #11236
This commit is contained in:
Matthias
2025-01-26 20:16:27 +01:00
parent eb24d11259
commit 99b2857d3d
4 changed files with 8 additions and 8 deletions

View File

@@ -2111,13 +2111,9 @@ class Trade(ModelBase, LocalTrade):
if start_date:
filters.append(Trade.close_date >= start_date)
best_pair = Trade.session.execute(
select(Trade.pair, func.sum(Trade.close_profit).label("profit_sum"))
.filter(*filters)
.group_by(Trade.pair)
.order_by(desc("profit_sum"))
).first()
pair_rates_query = Trade._generic_performance_query([Trade.pair], filters)
best_pair = Trade.session.execute(pair_rates_query).first()
# returns pair, profit_ratio, abs_profit, count
return best_pair
@staticmethod

View File

@@ -150,6 +150,7 @@ class Profit(BaseModel):
best_pair: str
best_rate: float
best_pair_profit_ratio: float
best_pair_profit_abs: float
winning_trades: int
losing_trades: int
profit_factor: float

View File

@@ -665,6 +665,7 @@ class RPC:
"best_pair": best_pair[0] if best_pair else "",
"best_rate": round(best_pair[1] * 100, 2) if best_pair else 0, # Deprecated
"best_pair_profit_ratio": best_pair[1] if best_pair else 0,
"best_pair_profit_abs": best_pair[2] if best_pair else 0,
"winning_trades": winning_trades,
"losing_trades": losing_trades,
"profit_factor": profit_factor,

View File

@@ -1028,6 +1028,7 @@ class Telegram(RPCHandler):
avg_duration = stats["avg_duration"]
best_pair = stats["best_pair"]
best_pair_profit_ratio = stats["best_pair_profit_ratio"]
best_pair_profit_abs = fmt_coin(stats["best_pair_profit_abs"], stake_cur)
winrate = stats["winrate"]
expectancy = stats["expectancy"]
expectancy_ratio = stats["expectancy_ratio"]
@@ -1067,7 +1068,8 @@ class Telegram(RPCHandler):
if stats["closed_trade_count"] > 0:
markdown_msg += (
f"\n*Avg. Duration:* `{avg_duration}`\n"
f"*Best Performing:* `{best_pair}: {best_pair_profit_ratio:.2%}`\n"
f"*Best Performing:* `{best_pair}: {best_pair_profit_abs} "
f"({best_pair_profit_ratio:.2%})`\n"
f"*Trading volume:* `{fmt_coin(stats['trading_volume'], stake_cur)}`\n"
f"*Profit factor:* `{stats['profit_factor']:.2f}`\n"
f"*Max Drawdown:* `{stats['max_drawdown']:.2%} "