Files
gogo2/debug/debug_trading_activity.py
2025-06-25 11:42:12 +03:00

186 lines
7.6 KiB
Python

#!/usr/bin/env python3
"""
Trading Activity Diagnostic Script
Debug why no trades are happening after 6 hours
"""
import logging
import asyncio
from datetime import datetime, timedelta
import pandas as pd
import numpy as np
# Setup logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
async def diagnose_trading_system():
"""Comprehensive diagnosis of trading system"""
logger.info("=== TRADING SYSTEM DIAGNOSTIC ===")
try:
# Import core components
from core.config import get_config
from core.data_provider import DataProvider
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
# Initialize components
config = get_config()
data_provider = DataProvider()
orchestrator = EnhancedTradingOrchestrator(
data_provider=data_provider,
symbols=['ETH/USDT', 'BTC/USDT'],
enhanced_rl_training=True
)
logger.info("✅ Components initialized successfully")
# 1. Check data availability
logger.info("\n=== DATA AVAILABILITY CHECK ===")
for symbol in ['ETH/USDT', 'BTC/USDT']:
for timeframe in ['1m', '5m', '1h']:
try:
data = data_provider.get_historical_data(symbol, timeframe, limit=10)
if data is not None and not data.empty:
logger.info(f"{symbol} {timeframe}: {len(data)} bars available")
logger.info(f" Last price: ${data['close'].iloc[-1]:.2f}")
else:
logger.error(f"{symbol} {timeframe}: NO DATA")
except Exception as e:
logger.error(f"{symbol} {timeframe}: ERROR - {e}")
# 2. Check model status
logger.info("\n=== MODEL STATUS CHECK ===")
model_status = orchestrator.get_loaded_models_status() if hasattr(orchestrator, 'get_loaded_models_status') else {}
logger.info(f"Loaded models: {model_status}")
# 3. Check confidence thresholds
logger.info("\n=== CONFIDENCE THRESHOLD CHECK ===")
logger.info(f"Entry threshold: {getattr(orchestrator, 'confidence_threshold_open', 'UNKNOWN')}")
logger.info(f"Exit threshold: {getattr(orchestrator, 'confidence_threshold_close', 'UNKNOWN')}")
logger.info(f"Config threshold: {config.orchestrator.get('confidence_threshold', 'UNKNOWN')}")
# 4. Test decision making
logger.info("\n=== DECISION MAKING TEST ===")
try:
decisions = await orchestrator.make_coordinated_decisions()
logger.info(f"Generated {len(decisions)} decisions")
for symbol, decision in decisions.items():
if decision:
logger.info(f"{symbol}: {decision.action} "
f"(confidence: {decision.confidence:.3f}, "
f"price: ${decision.price:.2f})")
else:
logger.warning(f"{symbol}: No decision generated")
except Exception as e:
logger.error(f"❌ Decision making failed: {e}")
# 5. Test cold start predictions
logger.info("\n=== COLD START PREDICTIONS TEST ===")
try:
await orchestrator.ensure_predictions_available()
logger.info("✅ Cold start predictions system working")
except Exception as e:
logger.error(f"❌ Cold start predictions failed: {e}")
# 6. Check cross-asset signals
logger.info("\n=== CROSS-ASSET SIGNALS TEST ===")
try:
from core.unified_data_stream import UniversalDataStream
# Create mock universal stream for testing
mock_stream = type('MockStream', (), {})()
mock_stream.get_latest_data = lambda symbol: {'price': 2500.0 if 'ETH' in symbol else 35000.0}
mock_stream.get_market_structure = lambda symbol: {'trend': 'NEUTRAL', 'strength': 0.5}
mock_stream.get_cob_data = lambda symbol: {'imbalance': 0.0, 'depth': 'BALANCED'}
btc_analysis = await orchestrator._analyze_btc_price_action(mock_stream)
logger.info(f"BTC analysis result: {btc_analysis}")
eth_decision = await orchestrator._make_eth_decision_from_btc_signals(
{'signal': 'NEUTRAL', 'strength': 0.5},
{'signal': 'NEUTRAL', 'imbalance': 0.0}
)
logger.info(f"ETH decision result: {eth_decision}")
except Exception as e:
logger.error(f"❌ Cross-asset signals failed: {e}")
# 7. Simulate trade with lower thresholds
logger.info("\n=== SIMULATED TRADE TEST ===")
try:
# Create mock prediction with low confidence
from core.enhanced_orchestrator import EnhancedPrediction
mock_prediction = EnhancedPrediction(
model_name="TEST",
timeframe="1m",
action="BUY",
confidence=0.30, # Lower confidence
overall_action="BUY",
overall_confidence=0.30,
timeframe_predictions=[],
reasoning="Test prediction"
)
# Test if this would generate a trade
current_price = 2500.0
quantity = 0.01
logger.info(f"Mock prediction: {mock_prediction.action} "
f"(confidence: {mock_prediction.confidence:.3f})")
if mock_prediction.confidence > 0.25: # Our new lower threshold
logger.info("✅ Would generate trade with new threshold")
else:
logger.warning("❌ Still below threshold")
except Exception as e:
logger.error(f"❌ Simulated trade test failed: {e}")
# 8. Check RL reward functions
logger.info("\n=== RL REWARD FUNCTION TEST ===")
try:
# Test reward calculation
mock_trade = {
'action': 'BUY',
'confidence': 0.75,
'price': 2500.0,
'timestamp': datetime.now()
}
mock_outcome = {
'net_pnl': 25.0, # $25 profit
'exit_price': 2525.0,
'duration': timedelta(minutes=15)
}
mock_market_data = {
'volatility': 0.03,
'order_flow_direction': 'bullish',
'order_flow_strength': 0.8
}
if hasattr(orchestrator, 'calculate_enhanced_pivot_reward'):
reward = orchestrator.calculate_enhanced_pivot_reward(
mock_trade, mock_market_data, mock_outcome
)
logger.info(f"✅ RL reward for profitable trade: {reward:.3f}")
else:
logger.warning("❌ Enhanced pivot reward function not available")
except Exception as e:
logger.error(f"❌ RL reward test failed: {e}")
logger.info("\n=== DIAGNOSTIC COMPLETE ===")
logger.info("Check results above to identify trading bottlenecks")
except Exception as e:
logger.error(f"Diagnostic failed: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
asyncio.run(diagnose_trading_system())