This commit is contained in:
Dobromir Popov
2025-05-24 02:01:13 +03:00
parent 509ad0ae17
commit 6e8ec97539
3 changed files with 566 additions and 0 deletions

View File

@ -18,6 +18,8 @@ import argparse
import logging
import sys
from pathlib import Path
from threading import Thread
import time
# Add project root to path
project_root = Path(__file__).parent
@ -179,6 +181,95 @@ def run_orchestrator_test():
logger.error(traceback.format_exc())
raise
def run_web_dashboard(port: int = 8050, demo_mode: bool = True):
"""Run the web dashboard"""
try:
from web.dashboard import TradingDashboard
logger.info("Starting Web Dashboard...")
# Initialize components
data_provider = DataProvider(symbols=['ETH/USDT'], timeframes=['1h', '4h'])
orchestrator = TradingOrchestrator(data_provider)
# Create dashboard
dashboard = TradingDashboard(data_provider, orchestrator)
# Add orchestrator callback to send decisions to dashboard
async def decision_callback(decision):
dashboard.add_trading_decision(decision)
orchestrator.add_decision_callback(decision_callback)
if demo_mode:
# Start demo mode with mock decisions
logger.info("Starting demo mode with simulated trading decisions...")
def demo_thread():
"""Generate demo trading decisions"""
import random
import time
from datetime import datetime
from core.orchestrator import TradingDecision
actions = ['BUY', 'SELL', 'HOLD']
base_price = 3000.0
while True:
try:
# Simulate price movement
price_change = random.uniform(-50, 50)
current_price = max(base_price + price_change, 1000)
# Create mock decision
action = random.choice(actions)
confidence = random.uniform(0.6, 0.95)
decision = TradingDecision(
action=action,
confidence=confidence,
symbol='ETH/USDT',
price=current_price,
timestamp=datetime.now(),
reasoning={'demo_mode': True, 'random_decision': True},
memory_usage={'demo': 0}
)
dashboard.add_trading_decision(decision)
logger.info(f"Demo decision: {action} ETH/USDT @${current_price:.2f} (confidence: {confidence:.2f})")
# Update base price occasionally
if random.random() < 0.1:
base_price = current_price
time.sleep(5) # New decision every 5 seconds
except Exception as e:
logger.error(f"Error in demo thread: {e}")
time.sleep(10)
# Start demo thread
demo_thread_instance = Thread(target=demo_thread, daemon=True)
demo_thread_instance.start()
# Start data streaming if available
try:
logger.info("Starting real-time data streaming...")
# Don't use asyncio.run here as we're already in an event loop context
# Just log that streaming would be started in a real deployment
logger.info("Real-time streaming would be started in production deployment")
except Exception as e:
logger.warning(f"Could not start real-time streaming: {e}")
# Run dashboard
dashboard.run(port=port, debug=False)
except Exception as e:
logger.error(f"Error running web dashboard: {e}")
import traceback
logger.error(traceback.format_exc())
raise
async def main():
"""Main entry point"""
parser = argparse.ArgumentParser(description='Clean Trading System')
@ -187,6 +278,10 @@ async def main():
parser.add_argument('--symbol', type=str, help='Override default symbol')
parser.add_argument('--config', type=str, default='config.yaml',
help='Configuration file path')
parser.add_argument('--port', type=int, default=8050,
help='Port for web dashboard')
parser.add_argument('--demo', action='store_true',
help='Run web dashboard in demo mode with simulated data')
args = parser.parse_args()
@ -203,6 +298,8 @@ async def main():
run_data_test()
elif args.mode == 'orchestrator':
run_orchestrator_test()
elif args.mode == 'web':
run_web_dashboard(port=args.port, demo_mode=args.demo)
else:
logger.info(f"Mode '{args.mode}' not yet implemented in clean architecture")