diff --git a/start_system.bat b/start_system.bat new file mode 100644 index 0000000..9b97999 --- /dev/null +++ b/start_system.bat @@ -0,0 +1,47 @@ +@echo off +chcp 65001 >nul +REM ============================================ +REM 系统启动脚本 (Windows) +REM 启动 API 服务和自动交易程序 +REM ============================================ + +echo [%date% %time%] 正在启动系统... + +REM 检查 conda 环境 +where conda >nul 2>&1 +if %errorlevel% neq 0 ( + echo [错误] 未找到 conda,请先安装 Anaconda 或 Miniconda + pause + exit /b 1 +) + +REM 激活 conda 环境 +echo [%date% %time%] 激活 conda 环境: crypto_pred_312 +call conda activate crypto_pred_312 +if %errorlevel% neq 0 ( + echo [错误] 无法激活 conda 环境 crypto_pred_312 + echo 请先创建环境: conda create -n crypto_pred_312 python=3.12 + pause + exit /b 1 +) + +REM 启动 API 服务 (后台运行) +echo [%date% %time%] 启动 API 服务... +start "API服务" cmd /c "python -m uvicorn api.main:app --host 0.0.0.0 --port 8000" + +REM 等待 API 启动 +timeout /t 3 /nobreak >nul + +REM 启动自动交易程序 (后台运行) +echo [%date% %time%] 启动自动交易程序... +start "自动交易" cmd /c "python -u auto_trade_polymarket.py" + +echo. +echo ============================================ +echo 系统启动完成! +echo 前端访问: http://localhost:8000 +echo 关闭窗口可停止对应服务 +echo ============================================ +echo. + +pause diff --git a/start_system.ps1 b/start_system.ps1 new file mode 100644 index 0000000..307a797 --- /dev/null +++ b/start_system.ps1 @@ -0,0 +1,90 @@ +# ============================================ +# 系统启动脚本 (Windows PowerShell) +# 启动 API 服务和自动交易程序 +# ============================================ + +$ErrorActionPreference = "Stop" + +function Write-Log { + param([string]$Message, [string]$Color = "White") + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + Write-Host "[$timestamp] $Message" -ForegroundColor $Color +} + +Write-Log "正在启动系统..." "Yellow" + +# 检查 conda +$condaPath = Get-Command conda -ErrorAction SilentlyContinue +if (-not $condaPath) { + Write-Log "错误: 未找到 conda,请先安装 Anaconda 或 Miniconda" "Red" + Read-Host "按回车键退出" + exit 1 +} + +# 激活 conda 环境 +Write-Log "激活 conda 环境: crypto_pred_312" "Yellow" +try { + conda activate crypto_pred_312 +} catch { + Write-Log "错误: 无法激活 conda 环境 crypto_pred_312" "Red" + Write-Log "请先创建环境: conda create -n crypto_pred_312 python=3.12" "Yellow" + Read-Host "按回车键退出" + exit 1 +} + +# 启动 API 服务 +Write-Log "启动 API 服务..." "Yellow" +$apiProcess = Start-Process -FilePath "python" ` + -ArgumentList "-m uvicorn api.main:app --host 0.0.0.0 --port 8000" ` + -PassThru -NoNewWindow + +Write-Log "API 服务已启动 (PID: $($apiProcess.Id))" "Green" + +# 等待 API 启动 +Start-Sleep -Seconds 3 + +# 启动自动交易程序 +Write-Log "启动自动交易程序..." "Yellow" +$tradeProcess = Start-Process -FilePath "python" ` + -ArgumentList "-u auto_trade_polymarket.py" ` + -PassThru -NoNewWindow + +Write-Log "自动交易程序已启动 (PID: $($tradeProcess.Id))" "Green" + +Write-Host "" +Write-Host "============================================" -ForegroundColor Cyan +Write-Host " 系统启动完成!" -ForegroundColor Green +Write-Host " 前端访问: http://localhost:8000" -ForegroundColor Green +Write-Host " 按 Ctrl+C 停止所有服务" -ForegroundColor Yellow +Write-Host "============================================" -ForegroundColor Cyan +Write-Host "" + +# 等待用户中断 +try { + while ($true) { + # 检查进程状态 + if ($apiProcess.HasExited) { + Write-Log "API 服务意外退出" "Red" + break + } + if ($tradeProcess.HasExited) { + Write-Log "自动交易程序意外退出" "Red" + break + } + Start-Sleep -Seconds 1 + } +} finally { + Write-Log "正在停止服务..." "Yellow" + + if (-not $apiProcess.HasExited) { + Stop-Process -Id $apiProcess.Id -Force -ErrorAction SilentlyContinue + Write-Log "API 服务已停止" "Green" + } + + if (-not $tradeProcess.HasExited) { + Stop-Process -Id $tradeProcess.Id -Force -ErrorAction SilentlyContinue + Write-Log "自动交易程序已停止" "Green" + } + + Write-Log "所有服务已停止" "Green" +}