feat条件单新建按标的过滤匹配币种的客户端。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+95
-25
@@ -203,6 +203,31 @@
|
||||
}
|
||||
|
||||
var candidatesById = {};
|
||||
var allCandidates = [];
|
||||
|
||||
function selectedCreateUnderlying() {
|
||||
const el = document.getElementById("cf-underlying");
|
||||
const u = el ? String(el.value || "ETH").trim().toUpperCase() : "ETH";
|
||||
return u === "BTC" ? "BTC" : "ETH";
|
||||
}
|
||||
|
||||
function candidateMatchesUnderlying(it, uly) {
|
||||
const u = String(uly || "ETH").toUpperCase();
|
||||
const raw = it && it.allowed_underlys;
|
||||
const allow = Array.isArray(raw)
|
||||
? raw
|
||||
.map(function (x) {
|
||||
return String(x || "")
|
||||
.trim()
|
||||
.toUpperCase();
|
||||
})
|
||||
.filter(function (x) {
|
||||
return x === "ETH" || x === "BTC";
|
||||
})
|
||||
: [];
|
||||
if (!allow.length) return true;
|
||||
return allow.indexOf(u) >= 0;
|
||||
}
|
||||
|
||||
function fmtTradingU(v) {
|
||||
if (v == null || v === "") return "—";
|
||||
@@ -412,6 +437,60 @@
|
||||
);
|
||||
}
|
||||
|
||||
function paintCandidates(checkedIds) {
|
||||
const box = document.getElementById("cf-instances");
|
||||
if (!box) return;
|
||||
const uly = selectedCreateUnderlying();
|
||||
const list = (allCandidates || []).filter(function (it) {
|
||||
return candidateMatchesUnderlying(it, uly);
|
||||
});
|
||||
if (!(allCandidates || []).length) {
|
||||
box.innerHTML = '<span class="muted">暂无启用实例</span>';
|
||||
return;
|
||||
}
|
||||
if (!list.length) {
|
||||
box.innerHTML =
|
||||
'<span class="muted">当前标的 ' +
|
||||
escapeHtml(uly) +
|
||||
" 下暂无匹配客户端(请确认实例 OKX_OPTIONS_UNDERLYINGS)</span>";
|
||||
return;
|
||||
}
|
||||
const keep = {};
|
||||
(checkedIds || []).forEach(function (id) {
|
||||
keep[String(id)] = true;
|
||||
});
|
||||
const filteredChecked = list
|
||||
.map(function (it) {
|
||||
return String(it.id);
|
||||
})
|
||||
.filter(function (id) {
|
||||
return keep[id];
|
||||
});
|
||||
const sim = [];
|
||||
const live = [];
|
||||
const other = [];
|
||||
list.forEach(function (it) {
|
||||
const m = instanceMode(it);
|
||||
if (m === "sim") sim.push(it);
|
||||
else if (m === "live") live.push(it);
|
||||
else other.push(it);
|
||||
});
|
||||
box.innerHTML =
|
||||
renderCandidateGroup("sim", sim, filteredChecked) +
|
||||
renderCandidateGroup("live", live, filteredChecked) +
|
||||
renderCandidateGroup("", other, filteredChecked);
|
||||
box.querySelectorAll(".cond-inst-xfer").forEach(function (btn) {
|
||||
btn.addEventListener("click", function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
transferInternal(
|
||||
btn.getAttribute("data-inst-id") || "",
|
||||
btn.getAttribute("data-dir") || "to_trading"
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function loadCandidates() {
|
||||
const box = document.getElementById("cf-instances");
|
||||
if (!box) return;
|
||||
@@ -423,35 +502,12 @@
|
||||
const r = await fetch("/api/cond_orders/candidates");
|
||||
const d = await r.json();
|
||||
const list = d.instances || [];
|
||||
if (!list.length) {
|
||||
box.innerHTML = '<span class="muted">暂无启用实例</span>';
|
||||
return;
|
||||
}
|
||||
const sim = [];
|
||||
const live = [];
|
||||
const other = [];
|
||||
allCandidates = list;
|
||||
candidatesById = {};
|
||||
list.forEach(function (it) {
|
||||
const m = instanceMode(it);
|
||||
candidatesById[String(it.id)] = it;
|
||||
if (m === "sim") sim.push(it);
|
||||
else if (m === "live") live.push(it);
|
||||
else other.push(it);
|
||||
});
|
||||
box.innerHTML =
|
||||
renderCandidateGroup("sim", sim, checkedIds) +
|
||||
renderCandidateGroup("live", live, checkedIds) +
|
||||
renderCandidateGroup("", other, checkedIds);
|
||||
box.querySelectorAll(".cond-inst-xfer").forEach(function (btn) {
|
||||
btn.addEventListener("click", function (ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
transferInternal(
|
||||
btn.getAttribute("data-inst-id") || "",
|
||||
btn.getAttribute("data-dir") || "to_trading"
|
||||
);
|
||||
});
|
||||
});
|
||||
paintCandidates(checkedIds);
|
||||
}
|
||||
|
||||
function renderDesktopRows(list) {
|
||||
@@ -729,6 +785,20 @@
|
||||
const pxEl = document.getElementById("cf-trigger-px");
|
||||
if (typeEl) typeEl.addEventListener("change", syncTriggerHint);
|
||||
if (pxEl) pxEl.addEventListener("input", syncTriggerHint);
|
||||
const ulyEl = document.getElementById("cf-underlying");
|
||||
if (ulyEl) {
|
||||
ulyEl.addEventListener("change", function () {
|
||||
const box = document.getElementById("cf-instances");
|
||||
const checkedIds = box
|
||||
? Array.prototype.slice
|
||||
.call(box.querySelectorAll('input[name="cf-inst"]:checked'))
|
||||
.map(function (el) {
|
||||
return decodeURIComponent(el.value || "");
|
||||
})
|
||||
: [];
|
||||
paintCandidates(checkedIds);
|
||||
});
|
||||
}
|
||||
syncTriggerHint();
|
||||
// 读缓存秒开 + SSE;不再前端定时现场拉实例
|
||||
refresh();
|
||||
|
||||
Reference in New Issue
Block a user