cob heatmap was broken - fixed
This commit is contained in:
@ -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.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))
|
fig.update_layout(margin=dict(l=10, r=10, t=20, b=10))
|
||||||
return fig
|
return fig
|
||||||
|
# Prepare data safely for Plotly
|
||||||
z = np.array(matrix, dtype=float)
|
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]
|
# Normalize per-time column (visual only) and transpose to [buckets x time]
|
||||||
col_max = np.maximum(z.max(axis=0), 1e-9)
|
col_max = np.maximum(z.max(axis=0), 1e-9)
|
||||||
zn = (z / col_max).T
|
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(
|
fig = go.Figure(data=go.Heatmap(
|
||||||
z=zn,
|
z=zn,
|
||||||
x=times,
|
x=x_vals,
|
||||||
y=prices,
|
y=prices,
|
||||||
colorscale='Turbo',
|
colorscale='Turbo',
|
||||||
colorbar=dict(title='Norm'),
|
colorbar=dict(title='Norm'),
|
||||||
@ -1512,8 +1526,8 @@ class CleanTradingDashboard:
|
|||||||
else:
|
else:
|
||||||
y_vals.append(None)
|
y_vals.append(None)
|
||||||
fig.add_trace(go.Scatter(
|
fig.add_trace(go.Scatter(
|
||||||
x=[t.strftime('%H:%M:%S') for t in times],
|
x=times,
|
||||||
y=[f"{yv:.2f}" if yv is not None else None for yv in y_vals],
|
y=y_vals,
|
||||||
mode='lines',
|
mode='lines',
|
||||||
line=dict(color='white', width=1.5),
|
line=dict(color='white', width=1.5),
|
||||||
name='Mid Price'
|
name='Mid Price'
|
||||||
@ -1551,11 +1565,23 @@ class CleanTradingDashboard:
|
|||||||
fig.update_layout(margin=dict(l=10, r=10, t=20, b=10))
|
fig.update_layout(margin=dict(l=10, r=10, t=20, b=10))
|
||||||
return fig
|
return fig
|
||||||
z = np.array(matrix, dtype=float)
|
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)
|
col_max = np.maximum(z.max(axis=0), 1e-9)
|
||||||
zn = (z / col_max).T
|
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(
|
fig = go.Figure(data=go.Heatmap(
|
||||||
z=zn,
|
z=zn,
|
||||||
x=times,
|
x=x_vals,
|
||||||
y=prices,
|
y=prices,
|
||||||
colorscale='Turbo',
|
colorscale='Turbo',
|
||||||
colorbar=dict(title='Norm'),
|
colorbar=dict(title='Norm'),
|
||||||
@ -1576,8 +1602,8 @@ class CleanTradingDashboard:
|
|||||||
else:
|
else:
|
||||||
y_vals.append(None)
|
y_vals.append(None)
|
||||||
fig.add_trace(go.Scatter(
|
fig.add_trace(go.Scatter(
|
||||||
x=[t.strftime('%H:%M:%S') for t in times],
|
x=times,
|
||||||
y=[f"{yv:.2f}" if yv is not None else None for yv in y_vals],
|
y=y_vals,
|
||||||
mode='lines',
|
mode='lines',
|
||||||
line=dict(color='white', width=1.5),
|
line=dict(color='white', width=1.5),
|
||||||
name='Mid Price'
|
name='Mid Price'
|
||||||
|
Reference in New Issue
Block a user