240 lines
7.0 KiB
Python
240 lines
7.0 KiB
Python
|
|
"""
|
||
|
|
Nautilus-Dolphin System Launcher
|
||
|
|
================================
|
||
|
|
|
||
|
|
Launch script to bring up the Nautilus-Dolphin trading system.
|
||
|
|
|
||
|
|
Usage:
|
||
|
|
python launch_system.py [--mode MODE] [--config CONFIG]
|
||
|
|
|
||
|
|
Modes:
|
||
|
|
backtest - Run backtest validation (default)
|
||
|
|
paper - Run paper trading
|
||
|
|
live - Run live trading (requires API keys)
|
||
|
|
|
||
|
|
Examples:
|
||
|
|
python launch_system.py --mode backtest
|
||
|
|
python launch_system.py --mode paper --config config/config.paper.yaml
|
||
|
|
"""
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
import asyncio
|
||
|
|
import sys
|
||
|
|
import yaml
|
||
|
|
from pathlib import Path
|
||
|
|
from typing import Dict
|
||
|
|
|
||
|
|
# Try to import Nautilus components
|
||
|
|
try:
|
||
|
|
from nautilus_trader.common.component import init_logging, Logger
|
||
|
|
NAUTILUS_AVAILABLE = True
|
||
|
|
print("[OK] Nautilus Trader imported successfully")
|
||
|
|
except ImportError as e:
|
||
|
|
NAUTILUS_AVAILABLE = False
|
||
|
|
print(f"[FAIL] Nautilus Trader not available: {e}")
|
||
|
|
print(" Install with: pip install nautilus_trader")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
# Import N-Dolphin launcher
|
||
|
|
try:
|
||
|
|
from nautilus_dolphin.nautilus.launcher import NautilusDolphinLauncher
|
||
|
|
print("[OK] N-Dolphin launcher imported")
|
||
|
|
except ImportError as e:
|
||
|
|
print(f"[FAIL] Failed to import N-Dolphin launcher: {e}")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
|
||
|
|
def load_config(config_path: str) -> Dict:
|
||
|
|
"""Load configuration from YAML file."""
|
||
|
|
try:
|
||
|
|
with open(config_path, 'r') as f:
|
||
|
|
return yaml.safe_load(f)
|
||
|
|
except Exception as e:
|
||
|
|
print(f"[FAIL] Failed to load config from {config_path}: {e}")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
|
||
|
|
def validate_system():
|
||
|
|
"""Validate system components before launch."""
|
||
|
|
print("\n" + "=" * 70)
|
||
|
|
print("VALIDATING SYSTEM COMPONENTS")
|
||
|
|
print("=" * 70)
|
||
|
|
|
||
|
|
all_ok = True
|
||
|
|
|
||
|
|
# Check 1: Nautilus Trader
|
||
|
|
if NAUTILUS_AVAILABLE:
|
||
|
|
print("[OK] Nautilus Trader: Available")
|
||
|
|
else:
|
||
|
|
print("[FAIL] Nautilus Trader: Not available")
|
||
|
|
all_ok = False
|
||
|
|
|
||
|
|
# Check 2: Redis (for signal bridge)
|
||
|
|
try:
|
||
|
|
import redis
|
||
|
|
print("[OK] Redis client: Available")
|
||
|
|
except ImportError:
|
||
|
|
print("[WARN] Redis client: Not installed (signal bridge will not work)")
|
||
|
|
|
||
|
|
# Check 3: ACB v5
|
||
|
|
try:
|
||
|
|
from nautilus_dolphin.nautilus.adaptive_circuit_breaker import (
|
||
|
|
AdaptiveCircuitBreaker, ACBPositionSizer
|
||
|
|
)
|
||
|
|
acb = AdaptiveCircuitBreaker()
|
||
|
|
sizer = ACBPositionSizer()
|
||
|
|
print("[OK] ACB v5: Initialized")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"[FAIL] ACB v5: {e}")
|
||
|
|
all_ok = False
|
||
|
|
|
||
|
|
# Check 4: Configuration
|
||
|
|
config_path = Path("config/config.yaml")
|
||
|
|
if config_path.exists():
|
||
|
|
print(f"[OK] Config file: {config_path}")
|
||
|
|
else:
|
||
|
|
print(f"[WARN] Config file: {config_path} not found")
|
||
|
|
|
||
|
|
print("\n" + "=" * 70)
|
||
|
|
if all_ok:
|
||
|
|
print("VALIDATION PASSED - System ready to launch")
|
||
|
|
else:
|
||
|
|
print("VALIDATION FAILED - Fix issues before launching")
|
||
|
|
print("=" * 70)
|
||
|
|
|
||
|
|
return all_ok
|
||
|
|
|
||
|
|
|
||
|
|
async def launch_backtest(config: Dict):
|
||
|
|
"""Launch backtest mode."""
|
||
|
|
print("\n" + "=" * 70)
|
||
|
|
print("LAUNCHING: Backtest Mode")
|
||
|
|
print("=" * 70)
|
||
|
|
|
||
|
|
# Merge config with data catalogue, execution, and strategy
|
||
|
|
launcher_config = {
|
||
|
|
'venue': config.get('strategy', {}).get('venue', 'BINANCE_FUTURES'),
|
||
|
|
'environment': 'BACKTEST',
|
||
|
|
'trader_id': 'DOLPHIN-BACKTEST-001',
|
||
|
|
'strategy': config.get('strategy', {
|
||
|
|
'venue': 'BINANCE_FUTURES',
|
||
|
|
'acb_enabled': True,
|
||
|
|
'max_leverage': 5.0,
|
||
|
|
'capital_fraction': 0.20,
|
||
|
|
}),
|
||
|
|
'signal_bridge': config.get('signal_bridge', {}),
|
||
|
|
'data_catalog': config.get('data_catalog', {
|
||
|
|
'eigenvalues_dir': 'eigenvalues',
|
||
|
|
'catalog_path': 'nautilus_dolphin/catalog',
|
||
|
|
'start_date': '2026-01-01',
|
||
|
|
'end_date': '2026-01-03',
|
||
|
|
'assets': ['BTCUSDT', 'ETHUSDT', 'ADAUSDT', 'SOLUSDT', 'DOTUSDT'],
|
||
|
|
}),
|
||
|
|
'execution': config.get('execution', {
|
||
|
|
'paper_trading': True,
|
||
|
|
'testnet': True,
|
||
|
|
}),
|
||
|
|
**config.get('smart_exec', {}),
|
||
|
|
}
|
||
|
|
|
||
|
|
try:
|
||
|
|
launcher = NautilusDolphinLauncher(launcher_config)
|
||
|
|
await launcher.start()
|
||
|
|
except Exception as e:
|
||
|
|
print(f"\n[FAIL] Failed to start backtest: {e}")
|
||
|
|
import traceback
|
||
|
|
traceback.print_exc()
|
||
|
|
return 1
|
||
|
|
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
async def launch_paper(config: Dict):
|
||
|
|
"""Launch paper trading mode."""
|
||
|
|
print("\n" + "=" * 70)
|
||
|
|
print("LAUNCHING: Paper Trading Mode")
|
||
|
|
print("=" * 70)
|
||
|
|
print("\n[WARNING] Paper trading not yet fully implemented")
|
||
|
|
print(" Falling back to backtest mode\n")
|
||
|
|
|
||
|
|
return await launch_backtest(config)
|
||
|
|
|
||
|
|
|
||
|
|
async def launch_live(config: Dict):
|
||
|
|
"""Launch live trading mode."""
|
||
|
|
print("\n" + "=" * 70)
|
||
|
|
print("LAUNCHING: LIVE Trading Mode")
|
||
|
|
print("=" * 70)
|
||
|
|
print("\n[WARNING] Live trading requires:")
|
||
|
|
print(" - Valid API keys in environment")
|
||
|
|
print(" - Risk acknowledgment")
|
||
|
|
print(" - Circuit breakers armed")
|
||
|
|
print("\n[ERROR] Live trading not implemented in this version")
|
||
|
|
|
||
|
|
return 1
|
||
|
|
|
||
|
|
|
||
|
|
async def main():
|
||
|
|
"""Main entry point."""
|
||
|
|
parser = argparse.ArgumentParser(
|
||
|
|
description="Launch Nautilus-Dolphin Trading System"
|
||
|
|
)
|
||
|
|
parser.add_argument(
|
||
|
|
'--mode',
|
||
|
|
choices=['backtest', 'paper', 'live', 'validate'],
|
||
|
|
default='validate',
|
||
|
|
help='Launch mode (default: validate)'
|
||
|
|
)
|
||
|
|
parser.add_argument(
|
||
|
|
'--config',
|
||
|
|
default='config/config.yaml',
|
||
|
|
help='Configuration file path'
|
||
|
|
)
|
||
|
|
parser.add_argument(
|
||
|
|
'--skip-validation',
|
||
|
|
action='store_true',
|
||
|
|
help='Skip system validation'
|
||
|
|
)
|
||
|
|
|
||
|
|
args = parser.parse_args()
|
||
|
|
|
||
|
|
print("=" * 70)
|
||
|
|
print("NAUTILUS-DOLPHIN SYSTEM LAUNCHER")
|
||
|
|
print("=" * 70)
|
||
|
|
print(f"Mode: {args.mode}")
|
||
|
|
print(f"Config: {args.config}")
|
||
|
|
|
||
|
|
# Validate system
|
||
|
|
if not args.skip_validation:
|
||
|
|
if not validate_system():
|
||
|
|
return 1
|
||
|
|
|
||
|
|
# Load configuration
|
||
|
|
if args.mode != 'validate':
|
||
|
|
config = load_config(args.config)
|
||
|
|
else:
|
||
|
|
config = {}
|
||
|
|
|
||
|
|
# Launch based on mode
|
||
|
|
if args.mode == 'validate':
|
||
|
|
print("\n[INFO] Validation complete - use --mode backtest to run")
|
||
|
|
return 0
|
||
|
|
elif args.mode == 'backtest':
|
||
|
|
return await launch_backtest(config)
|
||
|
|
elif args.mode == 'paper':
|
||
|
|
return await launch_paper(config)
|
||
|
|
elif args.mode == 'live':
|
||
|
|
return await launch_live(config)
|
||
|
|
else:
|
||
|
|
print(f"[ERROR] Unknown mode: {args.mode}")
|
||
|
|
return 1
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
try:
|
||
|
|
exit_code = asyncio.run(main())
|
||
|
|
sys.exit(exit_code)
|
||
|
|
except KeyboardInterrupt:
|
||
|
|
print("\n\n[INFO] Shutdown requested by user")
|
||
|
|
sys.exit(0)
|