diff --git a/web/clean_dashboard.py b/web/clean_dashboard.py index f6cf239..4ec4ce8 100644 --- a/web/clean_dashboard.py +++ b/web/clean_dashboard.py @@ -1482,13 +1482,27 @@ class CleanTradingDashboard: 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 + # Prepare data safely for Plotly z = np.array(matrix, dtype=float) + z = np.nan_to_num(z, nan=0.0, posinf=0.0, neginf=0.0) # Normalize per-time column (visual only) and transpose to [buckets x time] col_max = np.maximum(z.max(axis=0), 1e-9) zn = (z / col_max).T + # Ensure x axis has tz-naive datetimes + try: + local_tz = datetime.now().astimezone().tzinfo + x_vals = [] + for t in times: + if hasattr(t, 'tzinfo') and t.tzinfo is not None: + tt = t.astimezone(local_tz).replace(tzinfo=None) + x_vals.append(tt) + else: + x_vals.append(t) + except Exception: + x_vals = times fig = go.Figure(data=go.Heatmap( z=zn, - x=times, + x=x_vals, y=prices, colorscale='Turbo', colorbar=dict(title='Norm'), @@ -1512,8 +1526,8 @@ class CleanTradingDashboard: else: y_vals.append(None) fig.add_trace(go.Scatter( - x=[t.strftime('%H:%M:%S') for t in times], - y=[f"{yv:.2f}" if yv is not None else None for yv in y_vals], + x=times, + y=y_vals, mode='lines', line=dict(color='white', width=1.5), name='Mid Price' @@ -1551,11 +1565,23 @@ class CleanTradingDashboard: fig.update_layout(margin=dict(l=10, r=10, t=20, b=10)) return fig z = np.array(matrix, dtype=float) + z = np.nan_to_num(z, nan=0.0, posinf=0.0, neginf=0.0) col_max = np.maximum(z.max(axis=0), 1e-9) zn = (z / col_max).T + try: + local_tz = datetime.now().astimezone().tzinfo + x_vals = [] + for t in times: + if hasattr(t, 'tzinfo') and t.tzinfo is not None: + tt = t.astimezone(local_tz).replace(tzinfo=None) + x_vals.append(tt) + else: + x_vals.append(t) + except Exception: + x_vals = times fig = go.Figure(data=go.Heatmap( z=zn, - x=times, + x=x_vals, y=prices, colorscale='Turbo', colorbar=dict(title='Norm'), @@ -1576,8 +1602,8 @@ class CleanTradingDashboard: else: y_vals.append(None) fig.add_trace(go.Scatter( - x=[t.strftime('%H:%M:%S') for t in times], - y=[f"{yv:.2f}" if yv is not None else None for yv in y_vals], + x=times, + y=y_vals, mode='lines', line=dict(color='white', width=1.5), name='Mid Price'