working with errors
This commit is contained in:
@ -296,6 +296,27 @@ class DashboardComponentManager:
|
||||
html.P(f"Mode: {cob_mode}", className="text-muted small")
|
||||
])
|
||||
|
||||
# Defensive: If cob_snapshot is a list, log and return error
|
||||
if isinstance(cob_snapshot, list):
|
||||
logger.error(f"COB snapshot for {symbol} is a list, expected object. Data: {cob_snapshot}")
|
||||
return html.Div([
|
||||
html.H6(f"{symbol} COB", className="mb-2"),
|
||||
html.P("Invalid COB data format (list)", className="text-danger small"),
|
||||
html.P(f"Mode: {cob_mode}", className="text-muted small")
|
||||
])
|
||||
|
||||
# Debug: Log the type and structure of cob_snapshot
|
||||
logger.debug(f"COB snapshot type for {symbol}: {type(cob_snapshot)}")
|
||||
|
||||
# Handle case where cob_snapshot is a list (error case)
|
||||
if isinstance(cob_snapshot, list):
|
||||
logger.error(f"COB snapshot is a list for {symbol}, expected object or dict")
|
||||
return html.Div([
|
||||
html.H6(f"{symbol} COB", className="mb-2"),
|
||||
html.P("Invalid COB data format (list)", className="text-danger small"),
|
||||
html.P(f"Mode: {cob_mode}", className="text-muted small")
|
||||
])
|
||||
|
||||
# Handle both old format (with stats attribute) and new format (direct attributes)
|
||||
if hasattr(cob_snapshot, 'stats'):
|
||||
# Old format with stats attribute
|
||||
@ -385,6 +406,18 @@ class DashboardComponentManager:
|
||||
html.Span(imbalance_text, className=f"fw-bold small {imbalance_color}")
|
||||
]),
|
||||
|
||||
# Multi-timeframe imbalance metrics
|
||||
html.Div([
|
||||
html.Strong("Timeframe Imbalances:", className="small d-block mt-2 mb-1")
|
||||
]),
|
||||
|
||||
html.Div([
|
||||
self._create_timeframe_imbalance("1s", stats.get('imbalance_1s', imbalance)),
|
||||
self._create_timeframe_imbalance("5s", stats.get('imbalance_5s', imbalance)),
|
||||
self._create_timeframe_imbalance("15s", stats.get('imbalance_15s', imbalance)),
|
||||
self._create_timeframe_imbalance("60s", stats.get('imbalance_60s', imbalance)),
|
||||
], className="d-flex justify-content-between mb-2"),
|
||||
|
||||
html.Div(imbalance_stats_display),
|
||||
|
||||
html.Hr(className="my-2"),
|
||||
@ -417,6 +450,22 @@ class DashboardComponentManager:
|
||||
html.Div(title, className="small text-muted"),
|
||||
html.Div(value, className="fw-bold")
|
||||
], className="text-center")
|
||||
|
||||
def _create_timeframe_imbalance(self, timeframe, value):
|
||||
"""Helper for creating timeframe imbalance indicators."""
|
||||
color = "text-success" if value > 0 else "text-danger" if value < 0 else "text-muted"
|
||||
icon = "fas fa-chevron-up" if value > 0 else "fas fa-chevron-down" if value < 0 else "fas fa-minus"
|
||||
|
||||
# Format the value with sign and 2 decimal places
|
||||
formatted_value = f"{value:+.2f}"
|
||||
|
||||
return html.Div([
|
||||
html.Div(timeframe, className="small text-muted"),
|
||||
html.Div([
|
||||
html.I(className=f"{icon} me-1"),
|
||||
html.Span(formatted_value, className="small")
|
||||
], className=color)
|
||||
], className="text-center")
|
||||
|
||||
def _create_cob_ladder_panel(self, bids, asks, mid_price, symbol=""):
|
||||
"""Creates the right panel with the compact COB ladder."""
|
||||
|
Reference in New Issue
Block a user