168 lines
6.6 KiB
Python
168 lines
6.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Run Enhanced Trading Dashboard
|
|
|
|
This script starts the web dashboard with the enhanced trading system
|
|
for real-time monitoring and visualization.
|
|
"""
|
|
|
|
import logging
|
|
import asyncio
|
|
from threading import Thread
|
|
import time
|
|
|
|
from core.config import get_config, setup_logging
|
|
from core.data_provider import DataProvider
|
|
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
|
|
from web.dashboard import TradingDashboard
|
|
|
|
# Setup logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class EnhancedDashboardRunner:
|
|
"""Enhanced dashboard runner with mock trading simulation"""
|
|
|
|
def __init__(self):
|
|
"""Initialize the enhanced dashboard"""
|
|
self.config = get_config()
|
|
self.data_provider = DataProvider(self.config)
|
|
self.orchestrator = EnhancedTradingOrchestrator(self.data_provider)
|
|
|
|
# Create dashboard with enhanced orchestrator
|
|
self.dashboard = TradingDashboard(
|
|
data_provider=self.data_provider,
|
|
orchestrator=self.orchestrator
|
|
)
|
|
|
|
# Simulation state
|
|
self.running = False
|
|
self.simulation_thread = None
|
|
|
|
logger.info("Enhanced dashboard runner initialized")
|
|
|
|
def start_simulation(self):
|
|
"""Start background simulation for demonstration"""
|
|
self.running = True
|
|
self.simulation_thread = Thread(target=self._simulation_loop, daemon=True)
|
|
self.simulation_thread.start()
|
|
logger.info("Started enhanced trading simulation")
|
|
|
|
def _simulation_loop(self):
|
|
"""Background simulation loop"""
|
|
import random
|
|
from datetime import datetime
|
|
from core.enhanced_orchestrator import TradingAction, TimeframePrediction
|
|
|
|
action_count = 0
|
|
|
|
while self.running:
|
|
try:
|
|
# Simulate trading decisions for demonstration
|
|
for symbol in self.config.symbols:
|
|
# Create mock timeframe predictions
|
|
timeframe_predictions = []
|
|
for timeframe in ['1h', '4h', '1d']:
|
|
# Random but realistic predictions
|
|
action_probs = [
|
|
random.uniform(0.1, 0.4), # SELL
|
|
random.uniform(0.3, 0.6), # HOLD
|
|
random.uniform(0.1, 0.4) # BUY
|
|
]
|
|
# Normalize probabilities
|
|
total = sum(action_probs)
|
|
action_probs = [p/total for p in action_probs]
|
|
|
|
best_action_idx = action_probs.index(max(action_probs))
|
|
actions = ['SELL', 'HOLD', 'BUY']
|
|
best_action = actions[best_action_idx]
|
|
|
|
tf_pred = TimeframePrediction(
|
|
timeframe=timeframe,
|
|
action=best_action,
|
|
confidence=random.uniform(0.5, 0.9),
|
|
probabilities={
|
|
'SELL': action_probs[0],
|
|
'HOLD': action_probs[1],
|
|
'BUY': action_probs[2]
|
|
},
|
|
timestamp=datetime.now(),
|
|
market_features={
|
|
'volatility': random.uniform(0.01, 0.05),
|
|
'volume': random.uniform(1000, 10000),
|
|
'trend_strength': random.uniform(0.3, 0.8)
|
|
}
|
|
)
|
|
timeframe_predictions.append(tf_pred)
|
|
|
|
# Create mock trading action
|
|
if random.random() > 0.7: # 30% chance of action
|
|
action_count += 1
|
|
mock_action = TradingAction(
|
|
symbol=symbol,
|
|
action=random.choice(['BUY', 'SELL']),
|
|
quantity=random.uniform(0.01, 0.1),
|
|
confidence=random.uniform(0.6, 0.9),
|
|
price=random.uniform(2000, 4000) if 'ETH' in symbol else random.uniform(40000, 70000),
|
|
timestamp=datetime.now(),
|
|
reasoning={
|
|
'model': 'Enhanced Multi-Modal',
|
|
'timeframe_consensus': 'Strong',
|
|
'market_regime': random.choice(['trending', 'ranging', 'volatile']),
|
|
'action_count': action_count
|
|
},
|
|
timeframe_analysis=timeframe_predictions
|
|
)
|
|
|
|
# Add to dashboard
|
|
self.dashboard.add_trading_decision(mock_action)
|
|
|
|
logger.info(f"Simulated {mock_action.action} for {symbol} "
|
|
f"(confidence: {mock_action.confidence:.2f})")
|
|
|
|
# Sleep for next iteration
|
|
time.sleep(10) # Update every 10 seconds
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error in simulation loop: {e}")
|
|
time.sleep(5)
|
|
|
|
def run_dashboard(self, host='127.0.0.1', port=8050):
|
|
"""Run the enhanced dashboard"""
|
|
logger.info(f"Starting enhanced trading dashboard at http://{host}:{port}")
|
|
logger.info("Features:")
|
|
logger.info("- Multi-modal CNN + RL predictions")
|
|
logger.info("- Multi-timeframe analysis")
|
|
logger.info("- Real-time market regime detection")
|
|
logger.info("- Perfect move tracking for CNN training")
|
|
logger.info("- RL feedback loop evaluation")
|
|
|
|
# Start simulation
|
|
self.start_simulation()
|
|
|
|
# Run dashboard
|
|
try:
|
|
self.dashboard.run(host=host, port=port, debug=False)
|
|
except KeyboardInterrupt:
|
|
logger.info("Dashboard stopped by user")
|
|
finally:
|
|
self.running = False
|
|
if self.simulation_thread:
|
|
self.simulation_thread.join(timeout=2)
|
|
|
|
def main():
|
|
"""Main function"""
|
|
try:
|
|
logger.info("=== ENHANCED TRADING DASHBOARD ===")
|
|
|
|
# Create and run dashboard
|
|
runner = EnhancedDashboardRunner()
|
|
runner.run_dashboard()
|
|
|
|
except Exception as e:
|
|
logger.error(f"Fatal error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
main() |