trading performance stats

This commit is contained in:
Dobromir Popov
2025-06-26 18:36:07 +03:00
parent 99386dbc50
commit e6cd98ff10
3 changed files with 623 additions and 163 deletions

View File

@ -73,11 +73,48 @@ class DashboardComponentManager:
logger.error(f"Error formatting trading signals: {e}")
return [html.P(f"Error: {str(e)}", className="text-danger small")]
def format_closed_trades_table(self, closed_trades):
"""Format closed trades table for display"""
def format_closed_trades_table(self, closed_trades, trading_stats=None):
"""Format closed trades table for display with trading statistics"""
try:
# Create statistics header if trading stats are provided
stats_header = []
if trading_stats and trading_stats.get('total_trades', 0) > 0:
win_rate = trading_stats.get('win_rate', 0)
avg_win = trading_stats.get('avg_win_size', 0)
avg_loss = trading_stats.get('avg_loss_size', 0)
total_trades = trading_stats.get('total_trades', 0)
winning_trades = trading_stats.get('winning_trades', 0)
losing_trades = trading_stats.get('losing_trades', 0)
win_rate_class = "text-success" if win_rate >= 50 else "text-warning" if win_rate >= 30 else "text-danger"
stats_header = [
html.Div([
html.H6("Trading Performance", className="mb-2"),
html.Div([
html.Div([
html.Span("Win Rate: ", className="small text-muted"),
html.Span(f"{win_rate:.1f}%", className=f"fw-bold {win_rate_class}"),
html.Span(f" ({winning_trades}W/{losing_trades}L)", className="small text-muted")
], className="col-4"),
html.Div([
html.Span("Avg Win: ", className="small text-muted"),
html.Span(f"${avg_win:.2f}", className="fw-bold text-success")
], className="col-4"),
html.Div([
html.Span("Avg Loss: ", className="small text-muted"),
html.Span(f"${avg_loss:.2f}", className="fw-bold text-danger")
], className="col-4")
], className="row"),
html.Hr(className="my-2")
], className="mb-3")
]
if not closed_trades:
return html.P("No closed trades", className="text-muted small")
if stats_header:
return html.Div(stats_header + [html.P("No closed trades", className="text-muted small")])
else:
return html.P("No closed trades", className="text-muted small")
# Create table headers
headers = html.Thead([
@ -138,7 +175,13 @@ class DashboardComponentManager:
tbody = html.Tbody(rows)
return html.Table([headers, tbody], className="table table-sm table-striped")
table = html.Table([headers, tbody], className="table table-sm table-striped")
# Combine statistics header with table
if stats_header:
return html.Div(stats_header + [table])
else:
return table
except Exception as e:
logger.error(f"Error formatting closed trades: {e}")