feat: 添加 Windows 启动脚本
- start_system.bat: CMD 批处理脚本,双击即可运行 - start_system.ps1: PowerShell 脚本,支持进程监控和优雅退出 两个脚本都会: 1. 激活 crypto_pred_312 conda 环境 2. 启动 API 服务 (端口 8000) 3. 启动自动交易程序
This commit is contained in:
1 parent
233f0c5d10
commit
d0696a42ba
2 files changed
+137
No files matched your search
@@ -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
|
||||
@@ -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"
|
||||
}
|
||||
Reference in new issue
Block a user