enhanced
This commit is contained in:
@ -8,8 +8,10 @@ This script starts the custom scalping dashboard with:
|
||||
- 1 small BTC 1s chart
|
||||
- Ultra-fast 100ms updates for scalping
|
||||
- Real-time PnL tracking and logging
|
||||
- Enhanced orchestrator with real AI model decisions
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
@ -24,7 +26,7 @@ sys.path.insert(0, str(project_root))
|
||||
from core.config import get_config, setup_logging
|
||||
from core.data_provider import DataProvider
|
||||
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
|
||||
from web.scalping_dashboard import run_scalping_dashboard
|
||||
from web.scalping_dashboard import create_scalping_dashboard
|
||||
|
||||
# Setup logging
|
||||
setup_logging()
|
||||
@ -36,37 +38,42 @@ def validate_real_market_connection(data_provider: DataProvider) -> bool:
|
||||
Returns False if connection fails or data seems synthetic
|
||||
"""
|
||||
try:
|
||||
logger.info("🔍 VALIDATING REAL MARKET DATA CONNECTION...")
|
||||
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:
|
||||
# Force fresh data fetch (no cache)
|
||||
data = data_provider.get_historical_data(symbol, '1s', limit=100, refresh=True)
|
||||
|
||||
if data is None or data.empty:
|
||||
logger.error(f"❌ CRITICAL: No real 1s data for {symbol}")
|
||||
return False
|
||||
|
||||
# Validate data quality for scalping
|
||||
if len(data) < 50:
|
||||
logger.error(f"❌ CRITICAL: Insufficient real data for scalping {symbol}")
|
||||
return False
|
||||
|
||||
# Check for realistic price variations
|
||||
price_std = data['close'].std()
|
||||
if price_std == 0:
|
||||
logger.error(f"❌ CRITICAL: Static prices detected - possible synthetic data {symbol}")
|
||||
return False
|
||||
|
||||
logger.info(f"✅ Real 1s data validated: {symbol} - {len(data)} candles, price_std: {price_std:.4f}")
|
||||
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("✅ REAL MARKET DATA CONNECTION VALIDATED FOR SCALPING")
|
||||
logger.info("ALL REAL MARKET DATA CONNECTIONS VALIDATED")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"❌ CRITICAL: Market data validation failed: {e}")
|
||||
logger.error(f"CRITICAL: Market data validation failed: {e}")
|
||||
return False
|
||||
|
||||
class RealTradingEngine:
|
||||
@ -84,68 +91,85 @@ class RealTradingEngine:
|
||||
def start(self):
|
||||
"""Start real trading analysis"""
|
||||
self.running = True
|
||||
trading_thread = Thread(target=self._real_trading_loop, daemon=True)
|
||||
trading_thread = Thread(target=self._run_async_trading_loop, daemon=True)
|
||||
trading_thread.start()
|
||||
logger.info("🚀 REAL TRADING ENGINE STARTED - NO SYNTHETIC DATA")
|
||||
logger.info("REAL TRADING ENGINE STARTED - NO SYNTHETIC DATA")
|
||||
|
||||
def stop(self):
|
||||
"""Stop trading analysis"""
|
||||
self.running = False
|
||||
logger.info("⏹️ Real trading engine stopped")
|
||||
logger.info("Real trading engine stopped")
|
||||
|
||||
def _real_trading_loop(self):
|
||||
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...")
|
||||
logger.info("Starting REAL trading analysis loop...")
|
||||
|
||||
while self.running:
|
||||
try:
|
||||
# Analyze real market conditions for ETH/USDT and BTC/USDT
|
||||
symbols = ['ETH/USDT', 'BTC/USDT']
|
||||
# Make coordinated decisions using the orchestrator
|
||||
decisions = await self.orchestrator.make_coordinated_decisions()
|
||||
|
||||
for symbol in symbols:
|
||||
# Get real-time market analysis from orchestrator
|
||||
analysis = self.orchestrator.analyze_market_conditions(symbol)
|
||||
|
||||
if analysis is None:
|
||||
logger.warning(f"⚠️ No real market analysis available for {symbol}")
|
||||
continue
|
||||
|
||||
# Get real market data for decision making
|
||||
current_data = self.data_provider.get_historical_data(
|
||||
symbol, '1s', limit=20, refresh=True
|
||||
)
|
||||
|
||||
if current_data is None or current_data.empty:
|
||||
logger.warning(f"⚠️ No real current data for {symbol}")
|
||||
continue
|
||||
|
||||
# Make trading decision based on REAL market analysis
|
||||
decision = self.orchestrator.make_trading_decision(symbol)
|
||||
|
||||
for symbol, decision in decisions.items():
|
||||
if decision and decision.action in ['BUY', 'SELL']:
|
||||
self.trade_count += 1
|
||||
current_price = current_data['close'].iloc[-1]
|
||||
|
||||
logger.info(f"🔥 REAL TRADING DECISION #{self.trade_count}:")
|
||||
logger.info(f" 📊 {decision.action} {symbol} @ ${current_price:.2f}")
|
||||
logger.info(f" 📈 Confidence: {decision.confidence:.1%}")
|
||||
logger.info(f" 💰 Based on REAL market analysis")
|
||||
logger.info(f" 🕐 {datetime.now().strftime('%H:%M:%S')}")
|
||||
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})")
|
||||
|
||||
# Wait between real analysis cycles (scalping frequency)
|
||||
time.sleep(5) # 5-second analysis cycles for scalping
|
||||
# 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}")
|
||||
time.sleep(10) # Longer wait on error
|
||||
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")
|
||||
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")
|
||||
|
||||
try:
|
||||
# Initialize data provider
|
||||
@ -153,39 +177,39 @@ def main():
|
||||
|
||||
# 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")
|
||||
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
|
||||
orchestrator = EnhancedTradingOrchestrator(data_provider)
|
||||
|
||||
# Test orchestrator with real data
|
||||
logger.info("🔍 Testing orchestrator with real market data...")
|
||||
test_analysis = orchestrator.analyze_market_conditions('ETH/USDT')
|
||||
if test_analysis is None:
|
||||
logger.error("❌ CRITICAL: Orchestrator failed to analyze real market data")
|
||||
# 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("✅ Orchestrator validated with real market data")
|
||||
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")
|
||||
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
|
||||
run_scalping_dashboard(data_provider, orchestrator)
|
||||
dashboard = create_scalping_dashboard(data_provider, orchestrator)
|
||||
dashboard.run(host='127.0.0.1', port=8051, debug=False)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.info("🛑 Scalping dashboard stopped by user")
|
||||
logger.info("Scalping 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"CRITICAL ERROR: {e}")
|
||||
logger.error("Scalping dashboard stopped - NO SYNTHETIC DATA FALLBACK")
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user