main dash cob integration

This commit is contained in:
Dobromir Popov
2025-06-24 19:07:24 +03:00
parent 26266617a9
commit 6702a490dd
3 changed files with 200 additions and 13 deletions

View File

@ -92,6 +92,26 @@ except ImportError as e:
class UIDataPacket:
def __init__(self, *args, **kwargs): pass
# Import COB integration components if available
try:
from core.cob_integration import COBIntegration
from core.multi_exchange_cob_provider import MultiExchangeCOBProvider, COBSnapshot
COB_INTEGRATION_AVAILABLE = True
logger.info("COB integration components available")
except ImportError as e:
logger.warning(f"COB integration components not available: {e}")
COB_INTEGRATION_AVAILABLE = False
# Create fallback classes
class COBSnapshot:
def __init__(self, *args, **kwargs):
self.symbol = "N/A"
self.consolidated_bids = []
self.consolidated_asks = []
self.volume_weighted_mid = 0.0
self.spread_bps = 0.0
self.total_bid_liquidity = 0.0
self.total_ask_liquidity = 0.0
class AdaptiveThresholdLearner:
"""Learn optimal confidence thresholds based on real trade outcomes"""
@ -871,6 +891,19 @@ class TradingDashboard:
], className="card")
], className="mb-3"),
# COB (Consolidated Order Book) Visualization Section
html.Div([
html.Div([
html.Div([
html.H6([
html.I(className="fas fa-layer-group me-2"),
"Consolidated Order Book (COB) - Real-time Market Microstructure"
], className="card-title mb-2"),
html.Div(id="cob-visualization-content", style={"height": "400px", "overflowY": "auto"})
], className="card-body p-2")
], className="card")
], className="mb-3"),
# Bottom row - Session performance and system status
html.Div([
@ -992,7 +1025,8 @@ class TradingDashboard:
Output('system-status-details', 'children'),
Output('current-leverage', 'children'),
Output('leverage-risk', 'children'),
Output('cnn-monitoring-content', 'children')
Output('cnn-monitoring-content', 'children'),
Output('cob-visualization-content', 'children')
],
[Input('interval-component', 'n_intervals')]
)
@ -1200,13 +1234,20 @@ class TradingDashboard:
else:
risk_level = "Extreme Risk"
# Generate COB visualization content
try:
cob_content = self._create_cob_visualization_content()
except Exception as e:
logger.warning(f"COB visualization error: {e}")
cob_content = [html.P("COB data loading...", className="text-muted")]
# BUILD FINAL RESULT
result = (
price_text, pnl_text, pnl_class, fees_text, position_text, position_class,
trade_count_text, portfolio_text, mexc_status, price_chart, training_metrics,
decisions_list, session_perf, closed_trades_table, system_status['icon_class'],
system_status['title'], system_status['details'], leverage_text, risk_level,
cnn_monitoring_content
cnn_monitoring_content, cob_content
)
# Cache the result for emergencies
@ -5923,7 +5964,8 @@ class TradingDashboard:
"fas fa-circle text-warning fa-2x", "Loading",
[html.P("Loading...", className="text-muted")],
f"{self.leverage_multiplier:.0f}x", "Loading",
[html.P("Loading...", className="text-muted")]
[html.P("Loading...", className="text-muted")],
[html.P("COB loading...", className="text-muted")]
)
def _process_signal_optimized(self, signal):
@ -6097,6 +6139,138 @@ class TradingDashboard:
]
except:
return [html.P("CNN monitoring unavailable", className="text-muted")]
def _create_cob_visualization_content(self) -> List:
"""Create COB (Consolidated Order Book) visualization content"""
try:
content = []
# Check if we have enhanced orchestrator with COB integration
if not hasattr(self.orchestrator, 'latest_cob_features') or not hasattr(self.orchestrator, 'cob_integration'):
content.append(html.P("COB integration not available - using basic orchestrator", className="text-warning"))
return content
# Get COB data for primary symbols
symbols = ['ETH/USDT', 'BTC/USDT']
for symbol in symbols:
# Get COB features and state
cob_features = getattr(self.orchestrator, 'latest_cob_features', {}).get(symbol)
cob_state = getattr(self.orchestrator, 'latest_cob_state', {}).get(symbol)
# Get COB snapshot if integration is active
cob_snapshot = None
if hasattr(self.orchestrator, 'cob_integration') and self.orchestrator.cob_integration:
try:
cob_snapshot = self.orchestrator.cob_integration.get_cob_snapshot(symbol)
except:
pass
# Create symbol section
content.append(html.H6(f"{symbol} - Consolidated Order Book", className="text-primary"))
# COB Features Status
if cob_features is not None:
content.append(html.P([
html.Strong("CNN Features: "),
f"Shape {cob_features.shape} - Ready for ML training"
], className="text-success small"))
else:
content.append(html.P([
html.Strong("CNN Features: "),
"Not available"
], className="text-warning small"))
# COB State Status
if cob_state is not None:
content.append(html.P([
html.Strong("RL State: "),
f"Shape {cob_state.shape} - Ready for DQN training"
], className="text-success small"))
else:
content.append(html.P([
html.Strong("RL State: "),
"Not available"
], className="text-warning small"))
# COB Snapshot Details
if cob_snapshot:
content.append(html.Div([
html.P([
html.Strong("Mid Price: "),
f"${cob_snapshot.volume_weighted_mid:.2f}"
], className="text-info small mb-1"),
html.P([
html.Strong("Spread: "),
f"{cob_snapshot.spread_bps:.1f} bps"
], className="text-info small mb-1"),
html.P([
html.Strong("Bid Liquidity: "),
f"${cob_snapshot.total_bid_liquidity:,.0f}"
], className="text-success small mb-1"),
html.P([
html.Strong("Ask Liquidity: "),
f"${cob_snapshot.total_ask_liquidity:,.0f}"
], className="text-success small mb-1"),
html.P([
html.Strong("Active Exchanges: "),
", ".join(cob_snapshot.exchanges_active)
], className="text-secondary small mb-1"),
html.P([
html.Strong("Order Book Levels: "),
f"{len(cob_snapshot.consolidated_bids)} bids, {len(cob_snapshot.consolidated_asks)} asks"
], className="text-secondary small mb-1")
], className="border-start border-primary ps-2 mb-2"))
else:
content.append(html.P("COB snapshot not available", className="text-muted small"))
content.append(html.Hr())
# Training integration status
content.append(html.H6("COB → Training Pipeline Status", className="text-info"))
# Check if COB data is being used in training
training_active = False
if hasattr(self.orchestrator, 'enhanced_rl_training') and self.orchestrator.enhanced_rl_training:
training_active = True
content.append(html.P([
html.I(className="fas fa-check-circle text-success me-2"),
"COB data integrated into RL training pipeline"
], className="small"))
content.append(html.P([
html.I(className="fas fa-brain text-info me-2"),
"Real-time market microstructure → CNN features → RL states"
], className="small"))
else:
content.append(html.P([
html.I(className="fas fa-exclamation-triangle text-warning me-2"),
"COB training integration not active"
], className="small"))
# Performance metrics
if training_active:
try:
# Get COB integration performance
cob_update_count = 0
last_update = "Never"
for symbol in symbols:
if symbol in getattr(self.orchestrator, 'latest_cob_features', {}):
cob_update_count += 1
content.append(html.P([
html.Strong("COB Updates: "),
f"{cob_update_count} symbols receiving data"
], className="text-info small"))
except Exception as e:
content.append(html.P(f"Error getting COB metrics: {e}", className="text-danger small"))
return content
except Exception as e:
logger.error(f"Error creating COB visualization: {e}")
return [html.P(f"COB visualization error: {str(e)}", className="text-danger")]
def create_dashboard(data_provider: DataProvider = None, orchestrator: TradingOrchestrator = None, trading_executor: TradingExecutor = None) -> TradingDashboard: