added leverage slider

This commit is contained in:
Dobromir Popov
2025-05-30 22:33:41 +03:00
parent d870f74d0c
commit 7d8eca995e
21 changed files with 3205 additions and 2923 deletions

View File

@ -1,15 +1,14 @@
#!/usr/bin/env python3
"""
Clean Trading System - Streamlined Entry Point
Streamlined Trading System - Web Dashboard Only
Simplified entry point with only essential modes:
- test: Test data provider and core components
- web: Live trading dashboard with integrated training pipeline
Streamlined Flow: Data -> Indicators/Pivots -> CNN -> RL -> Orchestrator -> Execution
Simplified entry point with only the web dashboard mode:
- Streamlined Flow: Data -> Indicators/Pivots -> CNN -> RL -> Orchestrator -> Execution
- 2-Action System: BUY/SELL with intelligent position management
- Always invested approach with smart risk/reward setup detection
Usage:
python main_clean.py --mode [test|web] --symbol ETH/USDT
python main_clean.py [--symbol ETH/USDT] [--port 8050]
"""
import asyncio
@ -29,87 +28,12 @@ from core.data_provider import DataProvider
logger = logging.getLogger(__name__)
def run_data_test():
"""Test the enhanced data provider and core components"""
try:
config = get_config()
logger.info("Testing Enhanced Data Provider and Core Components...")
# Test data provider with multiple timeframes
data_provider = DataProvider(
symbols=['ETH/USDT'],
timeframes=['1s', '1m', '1h', '4h']
)
# Test historical data
logger.info("Testing historical data fetching...")
df = data_provider.get_historical_data('ETH/USDT', '1h', limit=100)
if df is not None:
logger.info(f"[SUCCESS] Historical data: {len(df)} candles loaded")
logger.info(f" Columns: {len(df.columns)} total")
logger.info(f" Date range: {df['timestamp'].min()} to {df['timestamp'].max()}")
# Show indicator breakdown
basic_cols = ['timestamp', 'open', 'high', 'low', 'close', 'volume']
indicators = [col for col in df.columns if col not in basic_cols]
logger.info(f" Technical indicators: {len(indicators)}")
else:
logger.error("[FAILED] Failed to load historical data")
# Test multi-timeframe feature matrix
logger.info("Testing multi-timeframe feature matrix...")
feature_matrix = data_provider.get_feature_matrix('ETH/USDT', ['1h', '4h'], window_size=20)
if feature_matrix is not None:
logger.info(f"[SUCCESS] Feature matrix shape: {feature_matrix.shape}")
logger.info(f" Timeframes: {feature_matrix.shape[0]}")
logger.info(f" Window size: {feature_matrix.shape[1]}")
logger.info(f" Features: {feature_matrix.shape[2]}")
else:
logger.error("[FAILED] Failed to create feature matrix")
# Test CNN model availability
try:
from NN.models.cnn_model import CNNModel
cnn = CNNModel(n_actions=2) # 2-action system
logger.info("[SUCCESS] CNN model initialized with 2 actions (BUY/SELL)")
except Exception as e:
logger.warning(f"[WARNING] CNN model not available: {e}")
# Test RL agent availability
try:
from NN.models.dqn_agent import DQNAgent
agent = DQNAgent(state_shape=(50,), n_actions=2) # 2-action system
logger.info("[SUCCESS] RL Agent initialized with 2 actions (BUY/SELL)")
except Exception as e:
logger.warning(f"[WARNING] RL Agent not available: {e}")
# Test orchestrator
try:
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
orchestrator = EnhancedTradingOrchestrator(data_provider)
logger.info("[SUCCESS] Enhanced Trading Orchestrator initialized")
except Exception as e:
logger.warning(f"[WARNING] Enhanced Orchestrator not available: {e}")
# Test health check
health = data_provider.health_check()
logger.info(f"[SUCCESS] Data provider health check completed")
logger.info("[SUCCESS] Core system test completed successfully!")
logger.info("2-Action System: BUY/SELL only (no HOLD)")
logger.info("Streamlined Flow: Data -> Indicators -> CNN -> RL -> Orchestrator -> Execution")
except Exception as e:
logger.error(f"Error in system test: {e}")
import traceback
logger.error(traceback.format_exc())
raise
def run_web_dashboard():
"""Run the streamlined web dashboard with integrated training pipeline"""
"""Run the streamlined web dashboard with 2-action system and always-invested approach"""
try:
logger.info("Starting Streamlined Trading Dashboard...")
logger.info("2-Action System: BUY/SELL with intelligent position management")
logger.info("Always Invested Approach: Smart risk/reward setup detection")
logger.info("Integrated Training Pipeline: Live data -> Models -> Trading")
# Get configuration
@ -143,7 +67,7 @@ def run_web_dashboard():
model_registry = {}
logger.warning("Model registry not available, using empty registry")
# Create streamlined orchestrator with 2-action system
# Create streamlined orchestrator with 2-action system and always-invested approach
orchestrator = EnhancedTradingOrchestrator(
data_provider=data_provider,
symbols=config.get('symbols', ['ETH/USDT']),
@ -151,6 +75,7 @@ def run_web_dashboard():
model_registry=model_registry
)
logger.info("Enhanced Trading Orchestrator with 2-Action System initialized")
logger.info("Always Invested: Learning to spot high risk/reward setups")
# Create trading executor for live execution
trading_executor = TradingExecutor()
@ -174,6 +99,7 @@ def run_web_dashboard():
logger.info("Real-time Indicators & Pivots: ENABLED")
logger.info("Live Trading Execution: ENABLED")
logger.info("2-Action System: BUY/SELL with position intelligence")
logger.info("Always Invested: Different thresholds for entry/exit")
logger.info("Pipeline: Data -> Indicators -> CNN -> RL -> Orchestrator -> Execution")
dashboard.run(host=host, port=port, debug=False)
@ -198,12 +124,8 @@ def run_web_dashboard():
logger.error(traceback.format_exc())
async def main():
"""Main entry point with streamlined mode selection"""
parser = argparse.ArgumentParser(description='Streamlined Trading System - Integrated Pipeline')
parser.add_argument('--mode',
choices=['test', 'web'],
default='web',
help='Operation mode: test (system check) or web (live trading)')
"""Main entry point with streamlined web-only operation"""
parser = argparse.ArgumentParser(description='Streamlined Trading System - 2-Action Web Dashboard')
parser.add_argument('--symbol', type=str, default='ETH/USDT',
help='Primary trading symbol (default: ETH/USDT)')
parser.add_argument('--port', type=int, default=8050,
@ -218,19 +140,16 @@ async def main():
try:
logger.info("=" * 70)
logger.info("STREAMLINED TRADING SYSTEM - INTEGRATED PIPELINE")
logger.info(f"Mode: {args.mode.upper()}")
logger.info("STREAMLINED TRADING SYSTEM - 2-ACTION WEB DASHBOARD")
logger.info(f"Primary Symbol: {args.symbol}")
if args.mode == 'web':
logger.info("Integrated Flow: Data -> Indicators -> CNN -> RL -> Execution")
logger.info("2-Action System: BUY/SELL with intelligent position management")
logger.info(f"Web Port: {args.port}")
logger.info("2-Action System: BUY/SELL with intelligent position management")
logger.info("Always Invested: Learning to spot high risk/reward setups")
logger.info("Flow: Data -> Indicators -> CNN -> RL -> Orchestrator -> Execution")
logger.info("=" * 70)
# Route to appropriate mode
if args.mode == 'test':
run_data_test()
elif args.mode == 'web':
run_web_dashboard()
# Run the web dashboard
run_web_dashboard()
logger.info("[SUCCESS] Operation completed successfully!")