Wire manual close to actually flatten option then perp then sell coin.

UI 平仓 now calls /api/hedge-plan/<id>/close instead of end-only (不平仓).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 16:49:24 +08:00
parent b7b1a7e7e0
commit 989accdc50
4 changed files with 304 additions and 8 deletions
+24 -1
View File
@@ -919,7 +919,7 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
@app.route("/api/hedge-plan/<int:plan_id>/end", methods=["POST"])
@lr
def api_hedge_end_plan(plan_id: int):
"""人工结束进行中计划:不自动平仓;未成交腿改为 cancelled."""
"""仅结束计划记录(不平仓).有持仓请用 /close."""
from lib.hedge_plan.hedge_plan_db import init_hedge_plan_tables
from lib.hedge_plan.hedge_plan_orders_lib import execute_manual_end_plan
@@ -934,6 +934,29 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
conn.close()
return jsonify(out)
@app.route("/api/hedge-plan/<int:plan_id>/close", methods=["POST"])
@lr
def api_hedge_close_plan(plan_id: int):
"""人工平仓:期权→永续→卖币,再结束计划."""
from lib.hedge_plan.hedge_plan_db import init_hedge_plan_tables
from lib.hedge_plan.hedge_plan_orders_lib import execute_manual_close_plan
conn = cfg["get_db"]()
try:
init_hedge_plan_tables(conn)
out = execute_manual_close_plan(cfg, conn, plan_id)
if not out.get("ok"):
# 半平成功时也要落库(期权已平/永续失败标记)
try:
conn.commit()
except Exception:
pass
return jsonify(out), 400
conn.commit()
finally:
conn.close()
return jsonify(out)
@app.route("/api/hedge-plan/<int:plan_id>/complete-leg", methods=["POST"])
@lr
def api_hedge_complete_leg(plan_id: int):