中控条件开仓单:客户端本地监控穿越/偏离区并按本机规则开平仓。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -173,6 +173,9 @@ def _enrich_hub_protocol(snap: dict[str, Any], *, app_module: Any) -> dict[str,
|
||||
"ratio_pct": ratio_pct,
|
||||
}
|
||||
out["positions_brief"] = slim_pos
|
||||
out["cond_order_locked"] = bool(out.get("cond_order_locked"))
|
||||
active_cond = out.get("cond_orders_active")
|
||||
out["cond_orders_active"] = active_cond if isinstance(active_cond, list) else []
|
||||
try:
|
||||
from lib.options.options_time_lib import options_app_now_str
|
||||
|
||||
@@ -229,6 +232,104 @@ def register_hub_bridge_routes(app: Flask, app_module: Any) -> None:
|
||||
out["version"] = 1
|
||||
return jsonify(out)
|
||||
|
||||
@app.route("/api/hub/options/cond_orders", methods=["GET"])
|
||||
def api_hub_options_cond_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_cond_order_lib import list_cond_orders
|
||||
from lib.options.options_db import init_options_tables
|
||||
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
orders = list_cond_orders(conn, active_only=False)
|
||||
return jsonify({"ok": True, "version": 1, "orders": orders})
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@app.route("/api/hub/options/cond_orders", methods=["POST"])
|
||||
def api_hub_options_cond_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_cond_order_lib import (
|
||||
create_cond_order,
|
||||
machine_has_option_position,
|
||||
)
|
||||
from lib.options.options_db import init_options_tables
|
||||
|
||||
ex = cfg.get("exchange_options")
|
||||
if machine_has_option_position(cfg, ex):
|
||||
return jsonify({"ok": False, "msg": "本机已有期权仓,拒绝条件单", "version": 1})
|
||||
data = request.get_json(silent=True) or {}
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
out = create_cond_order(conn, data)
|
||||
out["version"] = 1
|
||||
return jsonify(out)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@app.route("/api/hub/options/cond_orders/<hub_order_id>/cancel", methods=["POST"])
|
||||
def api_hub_options_cond_orders_cancel(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_cond_order_lib import cancel_cond_order
|
||||
from lib.options.options_db import init_options_tables
|
||||
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
out = cancel_cond_order(
|
||||
conn,
|
||||
hub_order_id,
|
||||
send_wechat=cfg.get("send_wechat"),
|
||||
account_label=str(cfg.get("account_label") or ""),
|
||||
)
|
||||
out["version"] = 1
|
||||
return jsonify(out)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@app.route("/api/hub/options/cond_orders/<hub_order_id>/exit", methods=["POST"])
|
||||
def api_hub_options_cond_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_cond_order_lib import update_cond_order_exit
|
||||
from lib.options.options_db import init_options_tables
|
||||
|
||||
data = request.get_json(silent=True) or {}
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
out = update_cond_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("/hub_sso")
|
||||
def hub_sso_login():
|
||||
token = (request.args.get("token") or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user