cleanup, cob ladder still broken
This commit is contained in:
@ -5426,9 +5426,24 @@ class CleanTradingDashboard:
|
||||
confidence_target_tensor = torch.FloatTensor([confidence_target]).to(device)
|
||||
|
||||
network.train()
|
||||
action_logits, predicted_confidence = network(features_tensor)
|
||||
network_output = network(features_tensor)
|
||||
|
||||
# Handle different return formats from network
|
||||
if isinstance(network_output, tuple) and len(network_output) == 2:
|
||||
action_logits, predicted_confidence = network_output
|
||||
elif hasattr(network_output, 'dim'):
|
||||
# Single tensor output - assume it's action logits
|
||||
action_logits = network_output
|
||||
predicted_confidence = torch.tensor(0.5, device=device) # Default confidence
|
||||
else:
|
||||
logger.debug(f"Unexpected network output format: {type(network_output)}")
|
||||
continue
|
||||
|
||||
# Ensure predicted_confidence is a tensor with proper dimensions
|
||||
if not hasattr(predicted_confidence, 'dim'):
|
||||
# If it's not a tensor, convert it
|
||||
predicted_confidence = torch.tensor(float(predicted_confidence), device=device)
|
||||
|
||||
# Ensure predicted_confidence has a batch dimension if it doesn't already
|
||||
if predicted_confidence.dim() == 0:
|
||||
predicted_confidence = predicted_confidence.unsqueeze(0)
|
||||
|
||||
@ -6048,4 +6063,7 @@ def create_clean_dashboard(data_provider: Optional[DataProvider] = None, orchest
|
||||
data_provider=data_provider,
|
||||
orchestrator=orchestrator,
|
||||
trading_executor=trading_executor
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# test edit
|
@ -275,18 +275,28 @@ class DashboardComponentManager:
|
||||
def format_cob_data(self, cob_snapshot, symbol, cumulative_imbalance_stats=None):
|
||||
"""Format COB data into a split view with summary, imbalance stats, and a compact ladder."""
|
||||
try:
|
||||
if not cob_snapshot or not hasattr(cob_snapshot, 'stats'):
|
||||
if not cob_snapshot:
|
||||
return html.Div([
|
||||
html.H6(f"{symbol} COB", className="mb-2"),
|
||||
html.P("No COB data available", className="text-muted small")
|
||||
])
|
||||
|
||||
stats = cob_snapshot.stats if hasattr(cob_snapshot, 'stats') else {}
|
||||
mid_price = stats.get('mid_price', 0)
|
||||
spread_bps = stats.get('spread_bps', 0)
|
||||
imbalance = stats.get('imbalance', 0)
|
||||
bids = getattr(cob_snapshot, 'consolidated_bids', [])
|
||||
asks = getattr(cob_snapshot, 'consolidated_asks', [])
|
||||
# Handle both old format (with stats attribute) and new format (direct attributes)
|
||||
if hasattr(cob_snapshot, 'stats'):
|
||||
# Old format with stats attribute
|
||||
stats = cob_snapshot.stats
|
||||
mid_price = stats.get('mid_price', 0)
|
||||
spread_bps = stats.get('spread_bps', 0)
|
||||
imbalance = stats.get('imbalance', 0)
|
||||
bids = getattr(cob_snapshot, 'consolidated_bids', [])
|
||||
asks = getattr(cob_snapshot, 'consolidated_asks', [])
|
||||
else:
|
||||
# New COBSnapshot format with direct attributes
|
||||
mid_price = getattr(cob_snapshot, 'volume_weighted_mid', 0)
|
||||
spread_bps = getattr(cob_snapshot, 'spread_bps', 0)
|
||||
imbalance = getattr(cob_snapshot, 'liquidity_imbalance', 0)
|
||||
bids = getattr(cob_snapshot, 'consolidated_bids', [])
|
||||
asks = getattr(cob_snapshot, 'consolidated_asks', [])
|
||||
|
||||
if mid_price == 0 or not bids or not asks:
|
||||
return html.Div([
|
||||
@ -294,6 +304,17 @@ class DashboardComponentManager:
|
||||
html.P("Awaiting valid order book data...", className="text-muted small")
|
||||
])
|
||||
|
||||
# Create stats dict for compatibility with existing code
|
||||
stats = {
|
||||
'mid_price': mid_price,
|
||||
'spread_bps': spread_bps,
|
||||
'imbalance': imbalance,
|
||||
'total_bid_liquidity': getattr(cob_snapshot, 'total_bid_liquidity', 0),
|
||||
'total_ask_liquidity': getattr(cob_snapshot, 'total_ask_liquidity', 0),
|
||||
'bid_levels': len(bids),
|
||||
'ask_levels': len(asks)
|
||||
}
|
||||
|
||||
# --- Left Panel: Overview and Stats ---
|
||||
overview_panel = self._create_cob_overview_panel(symbol, stats, cumulative_imbalance_stats)
|
||||
|
||||
@ -381,10 +402,19 @@ class DashboardComponentManager:
|
||||
def aggregate_buckets(orders):
|
||||
buckets = {}
|
||||
for order in orders:
|
||||
price = order.get('price', 0)
|
||||
# Handle both old format (size) and new format (total_size)
|
||||
size = order.get('total_size', order.get('size', 0))
|
||||
volume_usd = order.get('total_volume_usd', size * price)
|
||||
# Handle both dictionary format and ConsolidatedOrderBookLevel objects
|
||||
if hasattr(order, 'price'):
|
||||
# ConsolidatedOrderBookLevel object
|
||||
price = order.price
|
||||
size = order.total_size
|
||||
volume_usd = order.total_volume_usd
|
||||
else:
|
||||
# Dictionary format (legacy)
|
||||
price = order.get('price', 0)
|
||||
# Handle both old format (size) and new format (total_size)
|
||||
size = order.get('total_size', order.get('size', 0))
|
||||
volume_usd = order.get('total_volume_usd', size * price)
|
||||
|
||||
if price > 0:
|
||||
bucket_key = round(price / bucket_size) * bucket_size
|
||||
if bucket_key not in buckets:
|
||||
|
Reference in New Issue
Block a user