diff --git a/web/clean_dashboard.py b/web/clean_dashboard.py index 5ac0097..7da33db 100644 --- a/web/clean_dashboard.py +++ b/web/clean_dashboard.py @@ -1417,6 +1417,50 @@ class CleanTradingDashboard: logger.error(f"Error updating COB data: {e}") error_msg = html.P(f"COB Error: {str(e)}", className="text-danger small") return error_msg, error_msg + + @self.app.callback( + Output('cob-heatmap-eth', 'figure'), + [Input('interval-component', 'n_intervals')] + ) + def update_cob_heatmap_eth(n): + """Render ETH COB 1s heatmap (±10 buckets, last 5 minutes).""" + try: + times, prices, matrix = [], [], [] + if hasattr(self.data_provider, 'get_cob_heatmap_matrix'): + times, prices, matrix = self.data_provider.get_cob_heatmap_matrix( + 'ETH/USDT', seconds=300, bucket_radius=10, metric='liquidity' + ) + if not times or not prices or not matrix: + fig = go.Figure() + fig.add_annotation(text="No COB heatmap data", xref="paper", yref="paper", x=0.5, y=0.5, showarrow=False) + fig.update_layout(margin=dict(l=10, r=10, t=20, b=10)) + return fig + z = np.array(matrix, dtype=float) + # Normalize per-column for visualization stability (visual only) + col_max = np.maximum(z.max(axis=0), 1e-9) + zn = z / col_max + fig = go.Figure(data=go.Heatmap( + z=zn.T, + x=[t.strftime('%H:%M:%S') for t in times], + y=[f"{p:.2f}" for p in prices], + colorscale='Turbo', + colorbar=dict(title='Norm'), + zmin=0.0, + zmax=1.0 + )) + fig.update_layout( + title="ETH COB Heatmap (liquidity, per-bucket normalized)", + xaxis_title="Time", + yaxis_title="Price", + margin=dict(l=10, r=10, t=30, b=10) + ) + return fig + except Exception as e: + logger.error(f"Error rendering ETH COB heatmap: {e}") + fig = go.Figure() + fig.add_annotation(text=f"Heatmap Error: {str(e)}", xref="paper", yref="paper", x=0.5, y=0.5, showarrow=False) + fig.update_layout(margin=dict(l=10, r=10, t=20, b=10)) + return fig # Original training metrics callback - temporarily disabled for testing # @self.app.callback( diff --git a/web/layout_manager.py b/web/layout_manager.py index f2d53e3..b6d6c08 100644 --- a/web/layout_manager.py +++ b/web/layout_manager.py @@ -409,6 +409,17 @@ class DashboardLayoutManager: ], className="card") ], style={"width": "38%", "marginLeft": "2%"}), ], className="d-flex mb-3"), + + # COB Heatmap (ETH) + html.Div([ + html.Div([ + html.H6([ + html.I(className="fas fa-fire me-2"), + "ETH/USDT COB Heatmap (last 5m, ±10 buckets)" + ], className="card-title mb-2"), + dcc.Graph(id='cob-heatmap-eth', config={'displayModeBar': False}, style={"height": "300px"}) + ], className="card-body p-2") + ], className="card"), # Second row: Pending Orders (left) and Closed Trades (right) html.Div([