(function (global) {
function escapeHtml(s) {
return String(s)
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """);
}
function leftTriggerSide(optType) {
return String(optType || "P").toUpperCase() === "C" ? "lte" : "gte";
}
function triggerHintText(optType, px) {
const put = String(optType || "P").toUpperCase() !== "C";
const price = px && String(px).trim() !== "" ? String(px) : "触发价";
if (put) {
return "看跌左侧单:指数上穿 " + price + " 后,在偏离区内开最近实值 Put。";
}
return "看涨左侧单:指数下穿 " + price + " 后,在偏离区内开最近实值 Call。";
}
function syncTriggerHint() {
const hint = document.getElementById("cf-trigger-hint");
const typeEl = document.getElementById("cf-opt-type");
const pxEl = document.getElementById("cf-trigger-px");
if (!hint || !typeEl) return;
hint.textContent = triggerHintText(typeEl.value, pxEl && pxEl.value);
hint.className = "cond-trigger-hint " + (typeEl.value === "C" ? "is-call" : "is-put");
}
function statusLabel(o) {
const st = o.status || "";
const reason = o.end_reason || "";
if (st === "done") {
const map = {
leave_up: "结束·上破",
leave_down: "结束·下破",
cancel: "已取消",
closed: "已完成",
};
return map[reason] || "已结束";
}
const map2 = { armed: "待命", triggering: "触发中", open: "持仓中" };
return map2[st] || st || "—";
}
function statusClass(o) {
const st = o.status || "";
if (st === "open") return "st-open";
if (st === "triggering") return "st-trig";
if (st === "armed") return "st-armed";
return "st-done";
}
function isHubPhone() {
return (
document.documentElement.classList.contains("hub-phone-html") ||
!!(document.body && document.body.classList.contains("hub-phone"))
);
}
function orderTriggerText(o) {
const side = o.trigger_side === "lte" ? "下穿≤" : "上穿≥";
const px = o.trigger_px != null ? String(o.trigger_px) : "";
return side + px;
}
function orderExitText(o) {
const bits = [];
if (o.profit_exit_enabled) bits.push("翻倍×" + (o.profit_exit_mult || ""));
if (o.target_index != null) bits.push("目标" + o.target_index);
return bits.join(" · ");
}
function orderActionHtml(o) {
const canCancel = o.status === "armed" || o.status === "triggering";
const canExit = o.status === "open";
let actions = "";
if (canCancel) {
actions +=
'';
}
if (canExit) {
actions +=
'';
}
return actions;
}
function bindOrderActions(box) {
if (!box) return;
box.querySelectorAll("[data-cancel]").forEach(function (btn) {
btn.addEventListener("click", async function () {
if (!confirm("确认取消该条件单?")) return;
const oid = decodeURIComponent(btn.getAttribute("data-cancel") || "");
const iid = decodeURIComponent(btn.getAttribute("data-iid") || "");
const rr = await fetch("/api/cond_orders/" + encodeURIComponent(oid) + "/cancel", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ instance_id: Number(iid) }),
});
const dd = await rr.json();
alert(dd.msg || (dd.ok ? "已取消" : "失败"));
refresh();
});
});
box.querySelectorAll("[data-exit]").forEach(function (btn) {
btn.addEventListener("click", async function () {
const oid = decodeURIComponent(btn.getAttribute("data-exit") || "");
const iid = decodeURIComponent(btn.getAttribute("data-iid") || "");
const curT = decodeURIComponent(btn.getAttribute("data-target") || "");
const curM = decodeURIComponent(btn.getAttribute("data-mult") || "1");
const pe = btn.getAttribute("data-pe") === "1";
const t = prompt("目标指数(留空清除)", curT);
if (t === null) return;
const peOn = confirm("是否启用翻倍出场?\n当前:" + (pe ? "开" : "关"));
let mult = curM;
if (peOn) {
const m = prompt("翻倍倍数", curM);
if (m === null) return;
mult = m;
}
const rr = await fetch("/api/cond_orders/" + encodeURIComponent(oid) + "/exit", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
instance_id: Number(iid),
target_index: t === "" ? "" : t,
profit_exit_enabled: peOn,
profit_exit_mult: mult,
}),
});
const dd = await rr.json();
alert(dd.msg || (dd.ok ? "已更新" : "失败"));
refresh();
});
});
}
function isActiveOrder(o) {
const st = String((o && o.status) || "");
return st === "armed" || st === "triggering" || st === "open";
}
function formatOpenTime(o) {
const raw = String((o && o.opened_at) || "").trim();
if (!raw) return "—";
return raw.replace("T", " ").slice(0, 19);
}
function renderPhoneOrderCard(o) {
const exit = orderExitText(o);
const meta = [];
if (o.deviation_pct != null) meta.push("偏离 " + o.deviation_pct + "%");
if (o.min_expiry_hours != null) meta.push("到期 " + o.min_expiry_hours + "h");
if (exit) meta.push(exit);
const actions = orderActionHtml(o);
return (
'
| 客户端 | 状态 | 标的 | 触发 | 偏离 | 到期h | 出场 | 开仓时间 | 说明 | 操作 | " + "
|---|