feat: 每日自动优化完整流程 + 优化器参数范围适配保证金%

- daily_optimize.py: restart_ea() 直接杀旧启新,不再依赖信号文件
- optimize.py: 风控参数搜索范围改为保证金%(SL -100%~-10%, TP +50%~+300%)
- cron: 每日凌晨2点自动跑优化→重启EA
This commit is contained in:
silencesdg
2026-05-14 19:37:21 +08:00
parent 0fcd676a0a
commit 6c84f44073
3 changed files with 35 additions and 10 deletions
+28 -3
View File
@@ -218,9 +218,34 @@ def update_config(best_params: dict):
def restart_ea():
"""通过信号文件通知 restart_ea.sh 重启"""
RESTART_SIGNAL.write_text(datetime.now().isoformat())
logger.info("📡 已发送重启信号")
"""杀掉旧 EA → 清日志 → 启动新 EA(应用优化后的配置)"""
import subprocess
logger.info("🔄 重启 EA...")
# 杀旧进程
subprocess.run(["pkill", "-f", "python.*run/realtime.py"], capture_output=True)
import time; time.sleep(2)
subprocess.run(["pkill", "-9", "-f", "python.*run/realtime.py"], capture_output=True)
time.sleep(1)
# 清空旧交易记录
for f in PROJECT_DIR.glob("realtime_trades_*"):
f.unlink(missing_ok=True)
# 清日志
log_file = PROJECT_DIR / "logs" / "strategy.log"
log_file.write_text("")
# 启动新 EA(后台)
log = open(log_file, "a")
proc = subprocess.Popen(
[sys.executable, "run/realtime.py"],
cwd=str(PROJECT_DIR),
stdout=log, stderr=subprocess.STDOUT,
)
pid_file = PROJECT_DIR / ".ea_pid"
pid_file.write_text(str(proc.pid))
logger.info(f"✅ EA 已重启 PID={proc.pid}")
def main():