scalping dash also works initially
This commit is contained in:
@ -11,19 +11,16 @@ This script starts the custom scalping dashboard with:
|
||||
- Enhanced orchestrator with real AI model decisions
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from threading import Thread
|
||||
|
||||
# Add project root to path
|
||||
project_root = Path(__file__).parent
|
||||
sys.path.insert(0, str(project_root))
|
||||
|
||||
from core.config import get_config, setup_logging
|
||||
from core.config import setup_logging
|
||||
from core.data_provider import DataProvider
|
||||
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
|
||||
from web.scalping_dashboard import create_scalping_dashboard
|
||||
@ -32,184 +29,45 @@ from web.scalping_dashboard import create_scalping_dashboard
|
||||
setup_logging()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def validate_real_market_connection(data_provider: DataProvider) -> bool:
|
||||
"""
|
||||
CRITICAL: Validate real market data connection
|
||||
Returns False if connection fails or data seems synthetic
|
||||
"""
|
||||
try:
|
||||
logger.info("VALIDATING REAL MARKET DATA CONNECTION...")
|
||||
|
||||
# Test primary trading symbols
|
||||
test_symbols = ['ETH/USDT', 'BTC/USDT']
|
||||
test_timeframes = ['1m', '5m']
|
||||
|
||||
for symbol in test_symbols:
|
||||
for timeframe in test_timeframes:
|
||||
# Force fresh data fetch (no cache)
|
||||
data = data_provider.get_historical_data(symbol, timeframe, limit=50, refresh=True)
|
||||
|
||||
if data is None or data.empty:
|
||||
logger.error(f"CRITICAL: No real data for {symbol} {timeframe}")
|
||||
return False
|
||||
|
||||
# Validate data quality for trading
|
||||
if len(data) < 10:
|
||||
logger.error(f"CRITICAL: Insufficient real data for {symbol} {timeframe}")
|
||||
return False
|
||||
|
||||
# Check for realistic price ranges (basic sanity check)
|
||||
prices = data['close'].values
|
||||
if 'ETH' in symbol and (prices.min() < 100 or prices.max() > 10000):
|
||||
logger.error(f"CRITICAL: Unrealistic ETH prices detected - possible synthetic data")
|
||||
return False
|
||||
elif 'BTC' in symbol and (prices.min() < 10000 or prices.max() > 200000):
|
||||
logger.error(f"CRITICAL: Unrealistic BTC prices detected - possible synthetic data")
|
||||
return False
|
||||
|
||||
logger.info(f"Real data validated: {symbol} {timeframe} - {len(data)} candles")
|
||||
|
||||
logger.info("ALL REAL MARKET DATA CONNECTIONS VALIDATED")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"CRITICAL: Market data validation failed: {e}")
|
||||
return False
|
||||
|
||||
class RealTradingEngine:
|
||||
"""
|
||||
Real trading engine that makes decisions based on live market analysis
|
||||
NO SYNTHETIC DATA - Uses orchestrator for real market analysis
|
||||
"""
|
||||
|
||||
def __init__(self, data_provider: DataProvider, orchestrator: EnhancedTradingOrchestrator):
|
||||
self.data_provider = data_provider
|
||||
self.orchestrator = orchestrator
|
||||
self.running = False
|
||||
self.trade_count = 0
|
||||
|
||||
def start(self):
|
||||
"""Start real trading analysis"""
|
||||
self.running = True
|
||||
trading_thread = Thread(target=self._run_async_trading_loop, daemon=True)
|
||||
trading_thread.start()
|
||||
logger.info("REAL TRADING ENGINE STARTED - NO SYNTHETIC DATA")
|
||||
|
||||
def stop(self):
|
||||
"""Stop trading analysis"""
|
||||
self.running = False
|
||||
logger.info("Real trading engine stopped")
|
||||
|
||||
def _run_async_trading_loop(self):
|
||||
"""Run the async trading loop in a separate thread"""
|
||||
asyncio.run(self._real_trading_loop())
|
||||
|
||||
async def _real_trading_loop(self):
|
||||
"""
|
||||
Real trading analysis loop using live market data ONLY
|
||||
"""
|
||||
logger.info("Starting REAL trading analysis loop...")
|
||||
|
||||
while self.running:
|
||||
try:
|
||||
# Make coordinated decisions using the orchestrator
|
||||
decisions = await self.orchestrator.make_coordinated_decisions()
|
||||
|
||||
for symbol, decision in decisions.items():
|
||||
if decision and decision.action in ['BUY', 'SELL']:
|
||||
self.trade_count += 1
|
||||
|
||||
logger.info(f"REAL TRADING DECISION #{self.trade_count}:")
|
||||
logger.info(f" {decision.action} {symbol} @ ${decision.price:.2f}")
|
||||
logger.info(f" Confidence: {decision.confidence:.1%}")
|
||||
logger.info(f" Quantity: {decision.quantity:.6f}")
|
||||
logger.info(f" Based on REAL market analysis")
|
||||
logger.info(f" Time: {datetime.now().strftime('%H:%M:%S')}")
|
||||
|
||||
# Log timeframe analysis
|
||||
for tf_pred in decision.timeframe_analysis:
|
||||
logger.info(f" {tf_pred.timeframe}: {tf_pred.action} "
|
||||
f"(conf: {tf_pred.confidence:.3f})")
|
||||
|
||||
# Evaluate past actions for RL learning
|
||||
await self.orchestrator.evaluate_actions_with_rl()
|
||||
|
||||
# Wait between real analysis cycles (60 seconds for enhanced decisions)
|
||||
await asyncio.sleep(60)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in real trading analysis: {e}")
|
||||
await asyncio.sleep(30) # Wait on error
|
||||
|
||||
def test_orchestrator_simple(orchestrator: EnhancedTradingOrchestrator) -> bool:
|
||||
"""Simple test to verify orchestrator can make basic decisions"""
|
||||
try:
|
||||
# Run a simple async test
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
# Test making coordinated decisions
|
||||
decisions = loop.run_until_complete(orchestrator.make_coordinated_decisions())
|
||||
|
||||
loop.close()
|
||||
|
||||
# Check if we got any results
|
||||
if isinstance(decisions, dict):
|
||||
logger.info(f"Orchestrator test successful - got decisions for {len(decisions)} symbols")
|
||||
return True
|
||||
else:
|
||||
logger.error("Orchestrator test failed - no decisions returned")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Orchestrator test failed: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""Main function for scalping dashboard with REAL DATA ONLY"""
|
||||
logger.info("STARTING SCALPING DASHBOARD - 100% REAL MARKET DATA")
|
||||
logger.info("Ultra-fast scalping with live market analysis")
|
||||
logger.info("ZERO SYNTHETIC DATA - REAL DECISIONS ONLY")
|
||||
"""Main function for scalping dashboard"""
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(description='Ultra-Fast Scalping Dashboard (500x Leverage)')
|
||||
parser.add_argument('--episodes', type=int, default=1000, help='Number of episodes (for compatibility)')
|
||||
parser.add_argument('--max-position', type=float, default=0.1, help='Maximum position size')
|
||||
parser.add_argument('--leverage', type=int, default=500, help='Leverage multiplier')
|
||||
parser.add_argument('--port', type=int, default=8051, help='Dashboard port')
|
||||
parser.add_argument('--host', type=str, default='127.0.0.1', help='Dashboard host')
|
||||
parser.add_argument('--debug', action='store_true', help='Enable debug mode')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
logger.info("STARTING SCALPING DASHBOARD")
|
||||
logger.info("Session-based trading with $100 starting balance")
|
||||
logger.info(f"Configuration: Leverage={args.leverage}x, Max Position={args.max_position}, Port={args.port}")
|
||||
|
||||
try:
|
||||
# Initialize data provider
|
||||
# Initialize components
|
||||
logger.info("Initializing data provider...")
|
||||
data_provider = DataProvider()
|
||||
|
||||
# CRITICAL: Validate real market data connection
|
||||
if not validate_real_market_connection(data_provider):
|
||||
logger.error("CRITICAL: Real market data validation FAILED")
|
||||
logger.error("Scalping dashboard will NOT start without verified real data")
|
||||
logger.error("NO SYNTHETIC DATA FALLBACK ALLOWED")
|
||||
return 1
|
||||
|
||||
# Initialize orchestrator with validated real data
|
||||
logger.info("Initializing trading orchestrator...")
|
||||
orchestrator = EnhancedTradingOrchestrator(data_provider)
|
||||
|
||||
# Test orchestrator with a simple test
|
||||
logger.info("Testing orchestrator with real market data...")
|
||||
if not test_orchestrator_simple(orchestrator):
|
||||
logger.error("CRITICAL: Orchestrator validation failed")
|
||||
return 1
|
||||
logger.info("LAUNCHING DASHBOARD")
|
||||
logger.info(f"Dashboard will be available at http://{args.host}:{args.port}")
|
||||
|
||||
logger.info("Orchestrator validated with real market data")
|
||||
|
||||
# Initialize real trading engine
|
||||
trading_engine = RealTradingEngine(data_provider, orchestrator)
|
||||
trading_engine.start()
|
||||
|
||||
logger.info("LAUNCHING SCALPING DASHBOARD WITH 100% REAL DATA")
|
||||
logger.info("Real-time scalping decisions from live market analysis")
|
||||
|
||||
# Start the scalping dashboard with real data
|
||||
# Start the dashboard
|
||||
dashboard = create_scalping_dashboard(data_provider, orchestrator)
|
||||
dashboard.run(host='127.0.0.1', port=8051, debug=False)
|
||||
dashboard.run(host=args.host, port=args.port, debug=args.debug)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Scalping dashboard stopped by user")
|
||||
logger.info("Dashboard stopped by user")
|
||||
return 0
|
||||
except Exception as e:
|
||||
logger.error(f"CRITICAL ERROR: {e}")
|
||||
logger.error("Scalping dashboard stopped - NO SYNTHETIC DATA FALLBACK")
|
||||
logger.error(f"ERROR: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user