fix: 周重置去掉全平持仓,只清峰值+重启

This commit is contained in:
silencesdg
2026-05-21 20:30:28 +08:00
parent e1691c3c41
commit 5fbfb46b05
+7 -21
View File
@@ -1,9 +1,8 @@
#!/usr/bin/env python3
"""开市后全平持仓 + 清峰值 + 重启 EA"""
import requests, json, time, sys, os, subprocess
"""开市后清峰值 + 重启 EA(不平仓,让持仓自然运行)"""
import time, sys, os, subprocess, requests
API = "http://192.168.1.5:5555/api"
SYMBOL = "XAUUSDz"
PROJECT_DIR = "/home/songkl/mt5_python_ea_suite"
def log(msg):
@@ -26,30 +25,17 @@ else:
log("❌ 等待超时,市场未开市")
sys.exit(1)
# 2. 获取所有持仓并平仓
log("获取持仓...")
r = requests.get(f"{API}/positions/{SYMBOL}")
positions = r.json().get("positions", [])
log(f"{len(positions)}")
total_pnl = 0
for p in positions:
resp = requests.post(f"{API}/close",
json={"ticket": p["ticket"], "symbol": SYMBOL, "volume": p["volume"]})
ok = resp.json().get("success", False)
total_pnl += p["profit"]
log(f"{'' if ok else ''} {p['ticket']} ${p['profit']:+.2f}")
log(f"总盈亏: ${total_pnl:+.2f}")
# 3. 清峰值数据
# 2. 清峰值数据(让拖尾从新一周的峰值重新开始)
peak_file = os.path.join(PROJECT_DIR, "position_peaks.json")
if os.path.exists(peak_file):
os.remove(peak_file)
log("✅ 峰值数据已清除")
# 4. 杀掉旧 EA,启动新 EA
subprocess.run(["pkill", "-9", "-f", "python.*run/realtime.py"], capture_output=True)
# 3. 杀掉旧 EA,启动新 EA(新一周用新配置)
subprocess.run(["pkill", "-f", "python.*run/realtime.py"], capture_output=True)
time.sleep(2)
subprocess.run(["pkill", "-9", "-f", "python.*run/realtime.py"], capture_output=True)
time.sleep(1)
log_file = os.path.join(PROJECT_DIR, "logs", "strategy.log")
with open(log_file, "a") as f: