try to fix training
This commit is contained in:
48
.vscode/launch.json
vendored
48
.vscode/launch.json
vendored
@ -1,15 +1,32 @@
|
|||||||
{
|
{
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "📊 Enhanced Web Dashboard",
|
"name": "📊 Enhanced Web Dashboard (Safe)",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "main.py",
|
"program": "main_clean.py",
|
||||||
"args": [
|
"args": [
|
||||||
"--port",
|
"--port",
|
||||||
"8050"
|
"8051",
|
||||||
|
"--no-training"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"justMyCode": false,
|
||||||
|
"env": {
|
||||||
|
"PYTHONUNBUFFERED": "1",
|
||||||
|
"ENABLE_REALTIME_CHARTS": "1"
|
||||||
|
},
|
||||||
|
"preLaunchTask": "Kill Stale Processes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "📊 Enhanced Web Dashboard (Full)",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "main_clean.py",
|
||||||
|
"args": [
|
||||||
|
"--port",
|
||||||
|
"8051"
|
||||||
],
|
],
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
"justMyCode": false,
|
"justMyCode": false,
|
||||||
@ -20,6 +37,29 @@
|
|||||||
},
|
},
|
||||||
"preLaunchTask": "Kill Stale Processes"
|
"preLaunchTask": "Kill Stale Processes"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "📊 Clean Dashboard (Legacy)",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "run_clean_dashboard.py",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"justMyCode": false,
|
||||||
|
"env": {
|
||||||
|
"PYTHONUNBUFFERED": "1",
|
||||||
|
"ENABLE_REALTIME_CHARTS": "1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "🚀 Main System",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "main.py",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"justMyCode": false,
|
||||||
|
"env": {
|
||||||
|
"PYTHONUNBUFFERED": "1"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "🔬 System Test & Validation",
|
"name": "🔬 System Test & Validation",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
|
19
.vscode/tasks.json
vendored
19
.vscode/tasks.json
vendored
@ -4,20 +4,21 @@
|
|||||||
{
|
{
|
||||||
"label": "Kill Stale Processes",
|
"label": "Kill Stale Processes",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "python",
|
"command": "powershell",
|
||||||
"args": [
|
"args": [
|
||||||
"scripts/kill_stale_processes.py"
|
"-Command",
|
||||||
|
"Get-Process python | Where-Object {$_.ProcessName -eq 'python' -and $_.MainWindowTitle -like '*dashboard*'} | Stop-Process -Force; Start-Sleep -Seconds 1"
|
||||||
],
|
],
|
||||||
|
"group": "build",
|
||||||
"presentation": {
|
"presentation": {
|
||||||
"reveal": "always",
|
"echo": true,
|
||||||
|
"reveal": "silent",
|
||||||
|
"focus": false,
|
||||||
"panel": "shared",
|
"panel": "shared",
|
||||||
"clear": true
|
"showReuseMessage": false,
|
||||||
|
"clear": false
|
||||||
},
|
},
|
||||||
"problemMatcher": [],
|
"problemMatcher": []
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": false
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Start TensorBoard",
|
"label": "Start TensorBoard",
|
||||||
|
@ -33,7 +33,17 @@ import json
|
|||||||
from .config import get_config
|
from .config import get_config
|
||||||
from .data_provider import DataProvider, MarketTick
|
from .data_provider import DataProvider, MarketTick
|
||||||
from .universal_data_adapter import UniversalDataAdapter, UniversalDataStream
|
from .universal_data_adapter import UniversalDataAdapter, UniversalDataStream
|
||||||
from .enhanced_orchestrator import MarketState, TradingAction
|
from .trading_action import TradingAction
|
||||||
|
|
||||||
|
# Simple MarketState placeholder
|
||||||
|
@dataclass
|
||||||
|
class MarketState:
|
||||||
|
"""Market state for unified data stream"""
|
||||||
|
timestamp: datetime
|
||||||
|
symbol: str
|
||||||
|
price: float
|
||||||
|
volume: float
|
||||||
|
data: Dict[str, Any] = field(default_factory=dict)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
133
main_clean.py
Normal file
133
main_clean.py
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Clean Main Entry Point for Enhanced Trading Dashboard
|
||||||
|
|
||||||
|
This is the main entry point that safely launches the clean dashboard
|
||||||
|
with proper error handling and optimized settings.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import logging
|
||||||
|
import argparse
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
# Add project root to path
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
# Import core components
|
||||||
|
try:
|
||||||
|
from core.config import setup_logging
|
||||||
|
from core.data_provider import DataProvider
|
||||||
|
from core.orchestrator import TradingOrchestrator
|
||||||
|
from core.trading_executor import TradingExecutor
|
||||||
|
from web.clean_dashboard import create_clean_dashboard
|
||||||
|
except ImportError as e:
|
||||||
|
print(f"Error importing core modules: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def create_safe_orchestrator() -> Optional[TradingOrchestrator]:
|
||||||
|
"""Create orchestrator with safe CNN model handling"""
|
||||||
|
try:
|
||||||
|
# Create orchestrator with basic configuration (uses correct constructor parameters)
|
||||||
|
orchestrator = TradingOrchestrator(
|
||||||
|
enhanced_rl_training=False # Disable problematic training initially
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info("Trading orchestrator created successfully")
|
||||||
|
return orchestrator
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error creating orchestrator: {e}")
|
||||||
|
logger.info("Continuing without orchestrator - dashboard will run in view-only mode")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def create_safe_trading_executor() -> Optional[TradingExecutor]:
|
||||||
|
"""Create trading executor with safe configuration"""
|
||||||
|
try:
|
||||||
|
# TradingExecutor only accepts config_path parameter
|
||||||
|
trading_executor = TradingExecutor(config_path="config.yaml")
|
||||||
|
|
||||||
|
logger.info("Trading executor created successfully")
|
||||||
|
return trading_executor
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error creating trading executor: {e}")
|
||||||
|
logger.info("Continuing without trading executor - dashboard will be view-only")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main entry point for clean dashboard"""
|
||||||
|
parser = argparse.ArgumentParser(description='Enhanced Trading Dashboard')
|
||||||
|
parser.add_argument('--port', type=int, default=8050, help='Dashboard port (default: 8050)')
|
||||||
|
parser.add_argument('--host', type=str, default='127.0.0.1', help='Dashboard host (default: 127.0.0.1)')
|
||||||
|
parser.add_argument('--debug', action='store_true', help='Enable debug mode')
|
||||||
|
parser.add_argument('--no-training', action='store_true', help='Disable ML training for stability')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Setup logging
|
||||||
|
try:
|
||||||
|
setup_logging()
|
||||||
|
logger.info("================================================================================")
|
||||||
|
logger.info("CLEAN ENHANCED TRADING DASHBOARD")
|
||||||
|
logger.info("================================================================================")
|
||||||
|
logger.info(f"Starting on http://{args.host}:{args.port}")
|
||||||
|
logger.info("Features: Real-time Charts, Trading Interface, Model Monitoring")
|
||||||
|
logger.info("================================================================================")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error setting up logging: {e}")
|
||||||
|
# Continue without logging setup
|
||||||
|
|
||||||
|
# Set environment variables for optimization
|
||||||
|
os.environ['ENABLE_REALTIME_CHARTS'] = '1'
|
||||||
|
if not args.no_training:
|
||||||
|
os.environ['ENABLE_NN_MODELS'] = '1'
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Create data provider
|
||||||
|
logger.info("Initializing data provider...")
|
||||||
|
data_provider = DataProvider(symbols=['ETH/USDT', 'BTC/USDT'])
|
||||||
|
|
||||||
|
# Create orchestrator (with safe CNN handling)
|
||||||
|
logger.info("Initializing trading orchestrator...")
|
||||||
|
orchestrator = create_safe_orchestrator()
|
||||||
|
|
||||||
|
# Create trading executor
|
||||||
|
logger.info("Initializing trading executor...")
|
||||||
|
trading_executor = create_safe_trading_executor()
|
||||||
|
|
||||||
|
# Create and run dashboard
|
||||||
|
logger.info("Creating clean dashboard...")
|
||||||
|
dashboard = create_clean_dashboard(
|
||||||
|
data_provider=data_provider,
|
||||||
|
orchestrator=orchestrator,
|
||||||
|
trading_executor=trading_executor
|
||||||
|
)
|
||||||
|
|
||||||
|
# Start the dashboard server
|
||||||
|
logger.info(f"Starting dashboard server on http://{args.host}:{args.port}")
|
||||||
|
dashboard.run_server(
|
||||||
|
host=args.host,
|
||||||
|
port=args.port,
|
||||||
|
debug=args.debug
|
||||||
|
)
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.info("Dashboard stopped by user")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error running dashboard: {e}")
|
||||||
|
|
||||||
|
# Try to provide helpful error message
|
||||||
|
if "model.fit" in str(e) or "CNN" in str(e):
|
||||||
|
logger.error("CNN model training error detected. Try running with --no-training flag")
|
||||||
|
logger.error("Command: python main_clean.py --no-training")
|
||||||
|
|
||||||
|
sys.exit(1)
|
||||||
|
finally:
|
||||||
|
logger.info("Clean dashboard shutdown complete")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -965,8 +965,12 @@ class WilliamsMarketStructure:
|
|||||||
logger.info(f"CNN Training with X_shape: {X_train_batch.shape}, y_shape: {y_train_batch.shape}")
|
logger.info(f"CNN Training with X_shape: {X_train_batch.shape}, y_shape: {y_train_batch.shape}")
|
||||||
# Perform a single step of training (online learning)
|
# Perform a single step of training (online learning)
|
||||||
# Use the wrapper's fit method, not the model's directly
|
# Use the wrapper's fit method, not the model's directly
|
||||||
self.cnn_model.fit(X_train_batch, y_train_batch, batch_size=1, epochs=1, verbose=0, callbacks=[])
|
try:
|
||||||
logger.info(f"CNN online training step completed for pivot at index {self.previous_pivot_details_for_cnn['pivot'].index}.")
|
self.cnn_model.fit(X_train_batch, y_train_batch, batch_size=1, epochs=1, verbose=0, callbacks=[])
|
||||||
|
logger.info(f"CNN online training step completed for pivot at index {self.previous_pivot_details_for_cnn['pivot'].index}.")
|
||||||
|
except Exception as fit_error:
|
||||||
|
logger.error(f"CNN model fit error: {fit_error}")
|
||||||
|
logger.warning("CNN training step failed - continuing without training")
|
||||||
else:
|
else:
|
||||||
logger.warning("CNN Training: Skipping due to invalid X_train or y_train.")
|
logger.warning("CNN Training: Skipping due to invalid X_train or y_train.")
|
||||||
|
|
||||||
|
@ -69,14 +69,16 @@ except ImportError:
|
|||||||
COB_INTEGRATION_AVAILABLE = False
|
COB_INTEGRATION_AVAILABLE = False
|
||||||
logger.warning("COB integration not available")
|
logger.warning("COB integration not available")
|
||||||
|
|
||||||
# Add Universal Data Stream imports
|
# Universal Data Stream - temporarily disabled due to import issues
|
||||||
try:
|
UNIFIED_STREAM_AVAILABLE = False
|
||||||
from core.unified_data_stream import UnifiedDataStream
|
|
||||||
from core.universal_data_adapter import UniversalDataAdapter, UniversalDataStream as UDS
|
# Placeholder class for disabled Universal Data Stream
|
||||||
UNIFIED_STREAM_AVAILABLE = True
|
class UnifiedDataStream:
|
||||||
except ImportError:
|
"""Placeholder for disabled Universal Data Stream"""
|
||||||
UNIFIED_STREAM_AVAILABLE = False
|
def __init__(self, *args, **kwargs):
|
||||||
logger.warning("Unified Data Stream not available")
|
pass
|
||||||
|
def register_consumer(self, *args, **kwargs):
|
||||||
|
return "disabled"
|
||||||
|
|
||||||
# Import RL COB trader for 1B parameter model integration
|
# Import RL COB trader for 1B parameter model integration
|
||||||
from core.realtime_rl_cob_trader import RealtimeRLCOBTrader, PredictionResult
|
from core.realtime_rl_cob_trader import RealtimeRLCOBTrader, PredictionResult
|
||||||
@ -2133,7 +2135,7 @@ class CleanTradingDashboard:
|
|||||||
opening_trade_record = {
|
opening_trade_record = {
|
||||||
'symbol': symbol,
|
'symbol': symbol,
|
||||||
'side': action,
|
'side': action,
|
||||||
'quantity': size,
|
'quantity': decision['size'], # Use size from decision
|
||||||
'entry_price': current_price,
|
'entry_price': current_price,
|
||||||
'leverage': self.current_leverage, # Store leverage at entry
|
'leverage': self.current_leverage, # Store leverage at entry
|
||||||
'pnl': 0.0, # Will be updated when position closes
|
'pnl': 0.0, # Will be updated when position closes
|
||||||
|
Reference in New Issue
Block a user