fix: 中控改委托后同步计划价并去重条件单展示

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-04 21:12:00 +08:00
parent 54c1984ec7
commit be51eee73f
8 changed files with 376 additions and 33 deletions
+40
View File
@@ -777,6 +777,46 @@ def register_hub_routes(app):
return jsonify({"ok": False, "msg": "该实例无趋势回调"}), 400
return jsonify(_invoke_view_get("stop_trend_pullback", f"/stop_trend_pullback/{pid}"))
@app.route("/api/hub/order/sync-tpsl", methods=["POST"])
@_hub_auth_required
def api_hub_order_sync_tpsl():
"""中控 agent 已挂 TP/SL 后:同步 order_monitors 计划价,避免刷新仍显示旧止损止盈。"""
body = request.get_json(silent=True) or {}
symbol = (body.get("symbol") or request.form.get("symbol") or "").strip()
side = (
body.get("side")
or body.get("direction")
or request.form.get("side")
or ""
).strip().lower()
if not symbol:
return jsonify({"ok": False, "msg": "symbol 不能为空"}), 400
if side not in ("long", "short"):
return jsonify({"ok": False, "msg": "side 须为 long 或 short"}), 400
try:
sl = float(body.get("stop_loss"))
tp = float(body.get("take_profit"))
except (TypeError, ValueError):
return jsonify({"ok": False, "msg": "stop_loss / take_profit 须为数字"}), 400
get_db = _ctx().get("get_db")
if not callable(get_db):
return jsonify({"ok": False, "msg": "HUB_CTX 缺少 get_db"}), 500
from lib.hub.hub_symbol_lib import symbols_match
from lib.hub.hub_order_sync_lib import sync_active_monitor_tpsl_prices
conn = get_db()
try:
out = sync_active_monitor_tpsl_prices(
conn, symbol, side, sl, tp, symbols_match=symbols_match
)
if out.get("ok"):
conn.commit()
return jsonify(out)
except Exception as e:
return jsonify({"ok": False, "msg": str(e)}), 500
finally:
conn.close()
@app.route("/api/hub/order/sync-flat", methods=["POST"])
@_hub_auth_required
def api_hub_order_sync_flat():