中控条件开仓单:客户端本地监控穿越/偏离区并按本机规则开平仓。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -83,6 +83,7 @@ def _register_options_hub_bridge(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
hub_ctx = dict(app.config.get("HUB_CTX") or {})
|
||||
hub_ctx["options_snapshot_fn"] = snapshot_fn
|
||||
hub_ctx["options_close_fn"] = close_fn
|
||||
hub_ctx["options_cfg"] = cfg
|
||||
app.config["HUB_CTX"] = hub_ctx
|
||||
|
||||
|
||||
@@ -1009,6 +1010,21 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
mode = (data.get("mode") or "sheets").strip()
|
||||
mode, mode_note = _normalize_size_mode(mode)
|
||||
signal_note = (data.get("signal_note") or "").strip()
|
||||
# 中控条件单占用时禁止手动开仓
|
||||
try:
|
||||
from lib.options.options_cond_order_lib import cond_order_blocks_manual_open_msg
|
||||
from lib.options.options_db import init_options_tables
|
||||
|
||||
conn_blk = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn_blk)
|
||||
block = cond_order_blocks_manual_open_msg(conn_blk)
|
||||
if block:
|
||||
return jsonify({"ok": False, "msg": block, "cond_order_locked": True})
|
||||
finally:
|
||||
conn_blk.close()
|
||||
except Exception:
|
||||
pass
|
||||
if mode_note and mode == "sheets" and (data.get("mode") or "").strip() == "compound_full":
|
||||
# 前端残留全仓复利选中时,已自动改指定张数;继续开仓
|
||||
pass
|
||||
@@ -1487,7 +1503,32 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
conn_b.close()
|
||||
except Exception:
|
||||
spot_sell_hint = None
|
||||
return jsonify({"ok": True, "positions": rows, "spot_sell": spot_sell_hint})
|
||||
cond_locked = False
|
||||
cond_msg = ""
|
||||
try:
|
||||
from lib.options.options_cond_order_lib import has_active_cond_order, list_cond_orders
|
||||
|
||||
conn_c = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn_c)
|
||||
cond_locked = has_active_cond_order(conn_c)
|
||||
if cond_locked:
|
||||
act = list_cond_orders(conn_c, active_only=True)
|
||||
if act:
|
||||
cond_msg = str(act[0].get("message") or act[0].get("status") or "")
|
||||
finally:
|
||||
conn_c.close()
|
||||
except Exception:
|
||||
pass
|
||||
return jsonify(
|
||||
{
|
||||
"ok": True,
|
||||
"positions": rows,
|
||||
"spot_sell": spot_sell_hint,
|
||||
"cond_order_locked": cond_locked,
|
||||
"cond_order_msg": cond_msg,
|
||||
}
|
||||
)
|
||||
|
||||
@app.route("/api/options/targets")
|
||||
@lr
|
||||
@@ -2001,6 +2042,16 @@ def _start_monitor_thread(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
pass
|
||||
return out
|
||||
|
||||
def _cond_order_tick(conn) -> None:
|
||||
from lib.options.options_cond_order_lib import run_cond_orders_tick
|
||||
|
||||
run_cond_orders_tick(
|
||||
conn,
|
||||
cfg,
|
||||
send_wechat=cfg.get("send_wechat"),
|
||||
account_label=str(cfg.get("account_label") or ""),
|
||||
)
|
||||
|
||||
t = threading.Thread(
|
||||
target=options_monitor_loop,
|
||||
kwargs={
|
||||
@@ -2017,6 +2068,7 @@ def _start_monitor_thread(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
"profit_exit_close_fn": _profit_exit_close,
|
||||
"profit_exit_cfg": cfg,
|
||||
"stale_pending_fn": _stale_pending,
|
||||
"cond_order_tick_fn": _cond_order_tick,
|
||||
},
|
||||
daemon=True,
|
||||
name="options-monitor",
|
||||
|
||||
Reference in New Issue
Block a user