feat中控市价单:实例按第一档实值与杠杆立即全仓开仓。

EOF

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-11-03 18:50:46 +08:00
parent 4e14c92385
commit 8a29f2d51b
6 changed files with 947 additions and 1 deletions
+71
View File
@@ -549,6 +549,77 @@ def register_hub_bridge_routes(app: Flask, app_module: Any) -> None:
finally:
conn.close()
@app.route("/api/hub/options/market_orders", methods=["GET"])
def api_hub_options_market_orders_list():
if not hub_bridge_token_ok(request.headers):
return jsonify({"ok": False, "msg": "未授权", "version": 1}), 401
hub_ctx = app.config.get("HUB_CTX") or {}
cfg = hub_ctx.get("options_cfg")
if not isinstance(cfg, dict):
return jsonify({"ok": False, "msg": "期权未就绪", "version": 1}), 503
from lib.options.options_db import init_options_tables
from lib.options.options_market_order_lib import list_market_orders
conn = cfg["get_db"]()
try:
init_options_tables(conn)
orders = list_market_orders(conn, active_only=False)
return jsonify({"ok": True, "version": 1, "orders": orders})
finally:
conn.close()
@app.route("/api/hub/options/market_orders", methods=["POST"])
def api_hub_options_market_orders_create():
if not hub_bridge_token_ok(request.headers):
return jsonify({"ok": False, "msg": "未授权", "version": 1}), 401
hub_ctx = app.config.get("HUB_CTX") or {}
cfg = hub_ctx.get("options_cfg")
if not isinstance(cfg, dict):
return jsonify({"ok": False, "msg": "期权未就绪", "version": 1}), 503
from lib.options.options_market_order_lib import execute_market_open
data = request.get_json(silent=True) or {}
ex = cfg.get("exchange_options")
out = execute_market_open(
cfg,
ex,
data,
get_db=cfg.get("get_db"),
send_wechat=cfg.get("send_wechat"),
account_label=str(cfg.get("account_label") or ""),
)
if not isinstance(out, dict):
out = {"ok": False, "msg": "市价开仓返回异常"}
out["version"] = 1
return jsonify(out)
@app.route("/api/hub/options/market_orders/<hub_order_id>/exit", methods=["POST"])
def api_hub_options_market_orders_exit(hub_order_id: str):
if not hub_bridge_token_ok(request.headers):
return jsonify({"ok": False, "msg": "未授权", "version": 1}), 401
hub_ctx = app.config.get("HUB_CTX") or {}
cfg = hub_ctx.get("options_cfg")
if not isinstance(cfg, dict):
return jsonify({"ok": False, "msg": "期权未就绪", "version": 1}), 503
from lib.options.options_db import init_options_tables
from lib.options.options_market_order_lib import update_market_order_exit
data = request.get_json(silent=True) or {}
conn = cfg["get_db"]()
try:
init_options_tables(conn)
out = update_market_order_exit(
conn,
hub_order_id,
target_index=data.get("target_index"),
profit_exit_enabled=data.get("profit_exit_enabled"),
profit_exit_mult=data.get("profit_exit_mult"),
)
out["version"] = 1
return jsonify(out)
finally:
conn.close()
@app.route("/api/hub/version", methods=["GET"])
def hub_version():
"""中控探测客户端当前 git 版本/在线."""