cleanup and reorgnization
This commit is contained in:
40
scripts/restart_dashboard_with_learning.py
Normal file
40
scripts/restart_dashboard_with_learning.py
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Restart Dashboard with Forced Learning Enabled
|
||||
Simple script to start dashboard with all learning features enabled
|
||||
"""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def main():
|
||||
"""Start dashboard with forced learning"""
|
||||
logger.info("🚀 Starting Dashboard with FORCED LEARNING ENABLED")
|
||||
logger.info("=" * 60)
|
||||
logger.info(f"Timestamp: {datetime.now()}")
|
||||
logger.info("Fixes Applied:")
|
||||
logger.info("✅ Enhanced RL: FORCED ENABLED")
|
||||
logger.info("✅ CNN Training: FORCED ENABLED")
|
||||
logger.info("✅ Williams Pivots: CNN INTEGRATED")
|
||||
logger.info("✅ Learning Pipeline: ACTIVE")
|
||||
logger.info("=" * 60)
|
||||
|
||||
try:
|
||||
# Import and run main
|
||||
from main_clean import run_web_dashboard
|
||||
logger.info("Starting web dashboard...")
|
||||
run_web_dashboard()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Dashboard stopped by user")
|
||||
except Exception as e:
|
||||
logger.error(f"Dashboard failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
90
scripts/restart_main_overnight.ps1
Normal file
90
scripts/restart_main_overnight.ps1
Normal file
@ -0,0 +1,90 @@
|
||||
# Overnight Training Restart Script (PowerShell)
|
||||
# Keeps main.py running continuously, restarting it if it crashes.
|
||||
# Usage: .\restart_main_overnight.ps1
|
||||
|
||||
Write-Host "=" * 60
|
||||
Write-Host "OVERNIGHT TRAINING RESTART SCRIPT (PowerShell)"
|
||||
Write-Host "=" * 60
|
||||
Write-Host "Press Ctrl+C to stop the restart loop"
|
||||
Write-Host "Main script: main.py"
|
||||
Write-Host "Restart delay on crash: 10 seconds"
|
||||
Write-Host "=" * 60
|
||||
|
||||
$restartCount = 0
|
||||
$startTime = Get-Date
|
||||
|
||||
# Create logs directory if it doesn't exist
|
||||
if (!(Test-Path "logs")) {
|
||||
New-Item -ItemType Directory -Path "logs"
|
||||
}
|
||||
|
||||
# Setup log file
|
||||
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
|
||||
$logFile = "logs\restart_main_ps_$timestamp.log"
|
||||
|
||||
function Write-Log {
|
||||
param($Message)
|
||||
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||
$logMessage = "$timestamp - $Message"
|
||||
Write-Host $logMessage
|
||||
Add-Content -Path $logFile -Value $logMessage
|
||||
}
|
||||
|
||||
Write-Log "Restart script started, logging to: $logFile"
|
||||
|
||||
# Kill any existing Python processes
|
||||
try {
|
||||
Get-Process python* -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Seconds 2
|
||||
Write-Log "Killed existing Python processes"
|
||||
} catch {
|
||||
Write-Log "Could not kill existing processes: $_"
|
||||
}
|
||||
|
||||
try {
|
||||
while ($true) {
|
||||
$restartCount++
|
||||
$runStartTime = Get-Date
|
||||
|
||||
Write-Log "[RESTART #$restartCount] Starting main.py at $(Get-Date -Format 'HH:mm:ss')"
|
||||
|
||||
# Start main.py
|
||||
try {
|
||||
$process = Start-Process -FilePath "python" -ArgumentList "main.py" -PassThru -Wait
|
||||
$exitCode = $process.ExitCode
|
||||
$runEndTime = Get-Date
|
||||
$runDuration = ($runEndTime - $runStartTime).TotalSeconds
|
||||
|
||||
Write-Log "[EXIT] main.py exited with code $exitCode"
|
||||
Write-Log "[DURATION] Process ran for $([math]::Round($runDuration, 1)) seconds"
|
||||
|
||||
# Check for fast exits
|
||||
if ($runDuration -lt 30) {
|
||||
Write-Log "[FAST EXIT] Process exited quickly, waiting 30 seconds..."
|
||||
Start-Sleep -Seconds 30
|
||||
} else {
|
||||
Write-Log "[DELAY] Waiting 10 seconds before restart..."
|
||||
Start-Sleep -Seconds 10
|
||||
}
|
||||
|
||||
# Log stats every 10 restarts
|
||||
if ($restartCount % 10 -eq 0) {
|
||||
$totalDuration = (Get-Date) - $startTime
|
||||
Write-Log "[STATS] Session: $restartCount restarts in $([math]::Round($totalDuration.TotalHours, 1)) hours"
|
||||
}
|
||||
|
||||
} catch {
|
||||
Write-Log "[ERROR] Error starting main.py: $_"
|
||||
Start-Sleep -Seconds 10
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Log "[INTERRUPT] Restart loop interrupted: $_"
|
||||
} finally {
|
||||
$totalDuration = (Get-Date) - $startTime
|
||||
Write-Log "=" * 60
|
||||
Write-Log "OVERNIGHT TRAINING SESSION COMPLETE"
|
||||
Write-Log "Total restarts: $restartCount"
|
||||
Write-Log "Total session time: $([math]::Round($totalDuration.TotalHours, 1)) hours"
|
||||
Write-Log "=" * 60
|
||||
}
|
188
scripts/restart_main_overnight.py
Normal file
188
scripts/restart_main_overnight.py
Normal file
@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Overnight Training Restart Script
|
||||
Keeps main.py running continuously, restarting it if it crashes.
|
||||
Designed for overnight training sessions with unstable code.
|
||||
|
||||
Usage:
|
||||
python restart_main_overnight.py
|
||||
|
||||
Press Ctrl+C to stop the restart loop.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
import signal
|
||||
import os
|
||||
|
||||
# Setup logging for the restart script
|
||||
def setup_restart_logging():
|
||||
"""Setup logging for restart events"""
|
||||
log_dir = Path("logs")
|
||||
log_dir.mkdir(exist_ok=True)
|
||||
|
||||
# Create restart log file with timestamp
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
log_file = log_dir / f"restart_main_{timestamp}.log"
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.FileHandler(log_file, encoding='utf-8'),
|
||||
logging.StreamHandler(sys.stdout)
|
||||
]
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.info(f"Restart script logging to: {log_file}")
|
||||
return logger
|
||||
|
||||
def kill_existing_processes(logger):
|
||||
"""Kill any existing main.py processes to avoid conflicts"""
|
||||
try:
|
||||
if os.name == 'nt': # Windows
|
||||
# Kill any existing Python processes running main.py
|
||||
subprocess.run(['taskkill', '/f', '/im', 'python.exe'],
|
||||
capture_output=True, check=False)
|
||||
subprocess.run(['taskkill', '/f', '/im', 'pythonw.exe'],
|
||||
capture_output=True, check=False)
|
||||
time.sleep(2)
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not kill existing processes: {e}")
|
||||
|
||||
def run_main_with_restart(logger):
|
||||
"""Main restart loop"""
|
||||
restart_count = 0
|
||||
consecutive_fast_exits = 0
|
||||
start_time = datetime.now()
|
||||
|
||||
logger.info("=" * 60)
|
||||
logger.info("OVERNIGHT TRAINING RESTART SCRIPT STARTED")
|
||||
logger.info("=" * 60)
|
||||
logger.info("Press Ctrl+C to stop the restart loop")
|
||||
logger.info("Main script: main.py")
|
||||
logger.info("Restart delay on crash: 10 seconds")
|
||||
logger.info("Fast exit protection: Enabled")
|
||||
logger.info("=" * 60)
|
||||
|
||||
# Kill any existing processes
|
||||
kill_existing_processes(logger)
|
||||
|
||||
while True:
|
||||
try:
|
||||
restart_count += 1
|
||||
run_start_time = datetime.now()
|
||||
|
||||
logger.info(f"[RESTART #{restart_count}] Starting main.py at {run_start_time.strftime('%H:%M:%S')}")
|
||||
|
||||
# Start main.py as subprocess
|
||||
process = subprocess.Popen([
|
||||
sys.executable, "main.py"
|
||||
], stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
universal_newlines=True, bufsize=1)
|
||||
|
||||
logger.info(f"[PROCESS] main.py started with PID: {process.pid}")
|
||||
|
||||
# Stream output from main.py
|
||||
try:
|
||||
if process.stdout:
|
||||
while True:
|
||||
output = process.stdout.readline()
|
||||
if output == '' and process.poll() is not None:
|
||||
break
|
||||
if output:
|
||||
# Forward output from main.py (remove extra newlines)
|
||||
print(f"[MAIN] {output.rstrip()}")
|
||||
else:
|
||||
# If no stdout, just wait for process to complete
|
||||
process.wait()
|
||||
except KeyboardInterrupt:
|
||||
logger.info("[INTERRUPT] Ctrl+C received, stopping main.py...")
|
||||
process.terminate()
|
||||
try:
|
||||
process.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:
|
||||
logger.warning("[FORCE KILL] Process didn't terminate, force killing...")
|
||||
process.kill()
|
||||
raise
|
||||
|
||||
# Process has exited
|
||||
exit_code = process.poll()
|
||||
run_end_time = datetime.now()
|
||||
run_duration = (run_end_time - run_start_time).total_seconds()
|
||||
|
||||
logger.info(f"[EXIT] main.py exited with code {exit_code}")
|
||||
logger.info(f"[DURATION] Process ran for {run_duration:.1f} seconds")
|
||||
|
||||
# Check for fast exits (potential configuration issues)
|
||||
if run_duration < 30: # Less than 30 seconds
|
||||
consecutive_fast_exits += 1
|
||||
logger.warning(f"[FAST EXIT] Process exited quickly ({consecutive_fast_exits} consecutive)")
|
||||
|
||||
if consecutive_fast_exits >= 5:
|
||||
logger.error("[ABORT] Too many consecutive fast exits (5+)")
|
||||
logger.error("This indicates a configuration or startup problem")
|
||||
logger.error("Please check the main.py script manually")
|
||||
break
|
||||
|
||||
# Longer delay for fast exits
|
||||
delay = min(60, 10 * consecutive_fast_exits)
|
||||
logger.info(f"[DELAY] Waiting {delay} seconds before restart due to fast exit...")
|
||||
time.sleep(delay)
|
||||
else:
|
||||
consecutive_fast_exits = 0 # Reset counter
|
||||
logger.info("[DELAY] Waiting 10 seconds before restart...")
|
||||
time.sleep(10)
|
||||
|
||||
# Log session statistics every 10 restarts
|
||||
if restart_count % 10 == 0:
|
||||
total_duration = (datetime.now() - start_time).total_seconds()
|
||||
logger.info(f"[STATS] Session: {restart_count} restarts in {total_duration/3600:.1f} hours")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logger.info("[SHUTDOWN] Restart loop interrupted by user")
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f"[ERROR] Unexpected error in restart loop: {e}")
|
||||
logger.error("Continuing restart loop after 30 second delay...")
|
||||
time.sleep(30)
|
||||
|
||||
total_duration = (datetime.now() - start_time).total_seconds()
|
||||
logger.info("=" * 60)
|
||||
logger.info("OVERNIGHT TRAINING SESSION COMPLETE")
|
||||
logger.info(f"Total restarts: {restart_count}")
|
||||
logger.info(f"Total session time: {total_duration/3600:.1f} hours")
|
||||
logger.info("=" * 60)
|
||||
|
||||
def main():
|
||||
"""Main entry point"""
|
||||
# Setup signal handlers for clean shutdown
|
||||
def signal_handler(signum, frame):
|
||||
logger.info(f"[SIGNAL] Received signal {signum}, shutting down...")
|
||||
sys.exit(0)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
if hasattr(signal, 'SIGTERM'):
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
|
||||
# Setup logging
|
||||
global logger
|
||||
logger = setup_restart_logging()
|
||||
|
||||
try:
|
||||
run_main_with_restart(logger)
|
||||
except Exception as e:
|
||||
logger.error(f"[FATAL] Fatal error in restart script: {e}")
|
||||
import traceback
|
||||
logger.error(traceback.format_exc())
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
14
scripts/start_live_trading.ps1
Normal file
14
scripts/start_live_trading.ps1
Normal file
@ -0,0 +1,14 @@
|
||||
# PowerShell script to start live trading demo and TensorBoard
|
||||
|
||||
Write-Host "Starting Trading Bot Live Demo..." -ForegroundColor Green
|
||||
|
||||
# Create a new PowerShell window for TensorBoard
|
||||
Start-Process powershell -ArgumentList "-Command python run_tensorboard.py" -WindowStyle Normal
|
||||
|
||||
# Wait a moment for TensorBoard to start
|
||||
Write-Host "Starting TensorBoard... Please wait" -ForegroundColor Yellow
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
# Start the live trading demo in the current window
|
||||
Write-Host "Starting Live Trading Demo with mock data..." -ForegroundColor Green
|
||||
python run_live_demo.py --symbol ETH/USDT --timeframe 1m --model models/trading_agent_best_pnl.pt --mock
|
Reference in New Issue
Block a user