@@ -491,7 +491,47 @@
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeMarketSymbol(raw) {
|
||||
let s = (raw || "").trim().toUpperCase();
|
||||
if (!s) return "";
|
||||
if (s.includes(":")) {
|
||||
const base = s.split(":")[0];
|
||||
if (base.includes("/")) return base;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function resolveExchangeKey(exchangeId) {
|
||||
const row = (lastMonitorRows || []).find((r) => String(r.id) === String(exchangeId));
|
||||
return (row && (row.key || row.id)) || exchangeId;
|
||||
}
|
||||
|
||||
function openMarketForPosition(exchangeId, symbol, exchangeKey) {
|
||||
const exKey = exchangeKey || resolveExchangeKey(exchangeId);
|
||||
const sym = normalizeMarketSymbol(symbol);
|
||||
if (!exKey || !sym) {
|
||||
showToast("无法打开行情:缺少交易所或合约", true);
|
||||
return;
|
||||
}
|
||||
if (expandedExchangeId) {
|
||||
closeExchangeFullscreen();
|
||||
}
|
||||
const qs = new URLSearchParams({ exchange_key: exKey, symbol: sym });
|
||||
history.pushState({}, "", "/market?" + qs.toString());
|
||||
setActiveNav();
|
||||
if (window.hubMarketChart && window.hubMarketChart.openWith) {
|
||||
window.hubMarketChart.openWith(exKey, sym);
|
||||
}
|
||||
}
|
||||
|
||||
function bindMonitorInteractions(box) {
|
||||
box.querySelectorAll(".btn-open-market").forEach((btn) => {
|
||||
btn.onclick = (ev) => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
openMarketForPosition(btn.dataset.exId, btn.dataset.symbol, btn.dataset.exKey);
|
||||
};
|
||||
});
|
||||
box.querySelectorAll(".btn-open-instance").forEach((btn) => {
|
||||
btn.onclick = (ev) => {
|
||||
ev.preventDefault();
|
||||
@@ -662,8 +702,9 @@
|
||||
return row("止损", sl) + row("止盈", tp);
|
||||
}
|
||||
|
||||
function renderLivePositionCard(exchangeId, pos, monitorOrder) {
|
||||
function renderLivePositionCard(exchangeId, exchangeKey, pos, monitorOrder) {
|
||||
const symbol = pos.symbol || "";
|
||||
const exKeyAttr = esc(exchangeKey || exchangeId || "").replace(/"/g, """);
|
||||
const side = (pos.side || "long").toLowerCase();
|
||||
const sideCn = sideDirLabel(side);
|
||||
const sideCls = sideDirCls(side) || "side-long";
|
||||
@@ -706,7 +747,7 @@
|
||||
return `<div class="pos-card hub-pos-card">
|
||||
<div class="pos-card-head">
|
||||
<div class="pos-card-symbol">
|
||||
<strong>${esc(symbol)}</strong>
|
||||
<button type="button" class="btn-open-market sym-link pos-symbol-link" data-ex-id="${esc(exchangeId)}" data-ex-key="${exKeyAttr}" data-symbol="${symAttr}" title="打开行情区"><strong>${esc(symbol)}</strong></button>
|
||||
<span class="pos-side-badge ${sideCls}">${sideCn}</span>
|
||||
</div>
|
||||
<div class="pos-head-actions">
|
||||
@@ -807,8 +848,9 @@
|
||||
.join("");
|
||||
}
|
||||
|
||||
function renderPositionBlock(exchangeId, x) {
|
||||
function renderPositionBlock(exchangeId, exchangeKey, x) {
|
||||
const symAttr = esc(x.symbol || "").replace(/"/g, """);
|
||||
const exKeyAttr = esc(exchangeKey || exchangeId || "").replace(/"/g, """);
|
||||
const sideAttr = esc((x.side || "").toLowerCase()).replace(/"/g, """);
|
||||
const contractsAttr = esc(String(x.contracts != null ? x.contracts : "")).replace(/"/g, """);
|
||||
const cond = condOrdersFromPosition(x);
|
||||
@@ -820,7 +862,7 @@
|
||||
<div class="table-scroll">
|
||||
<table class="data-table"><thead><tr><th>合约</th><th>方向</th><th>张数</th><th>浮盈</th><th>操作</th></tr></thead><tbody>
|
||||
<tr>
|
||||
<td>${esc(x.symbol)}</td>
|
||||
<td><button type="button" class="btn-open-market sym-link" data-ex-id="${esc(exchangeId)}" data-ex-key="${exKeyAttr}" data-symbol="${symAttr}" title="打开行情区">${esc(x.symbol)}</button></td>
|
||||
<td class="${sideDirCls(x.side)}">${renderDirectionHtml(x.side)}</td>
|
||||
<td>${fmt(x.contracts, 4)}</td>
|
||||
<td class="${pnlCls(x.unrealized_pnl)}">${fmt(x.unrealized_pnl, 2)}</td>
|
||||
@@ -844,7 +886,7 @@
|
||||
</div>`;
|
||||
inner += `<div class="section-title">交易所持仓 · ${pos.length} 仓</div>`;
|
||||
if (pos.length) {
|
||||
inner += pos.map((p) => renderPositionBlock(row.id, p)).join("");
|
||||
inner += pos.map((p) => renderPositionBlock(row.id, row.key || row.id, p)).join("");
|
||||
} else {
|
||||
inner += '<div class="empty-hint">无持仓</div>';
|
||||
}
|
||||
@@ -937,7 +979,7 @@
|
||||
html += `<div class="hub-pos-list ${posListCls}" data-pos-count="${posCount}">`;
|
||||
if (posCount) {
|
||||
pos.forEach((p) => {
|
||||
html += renderLivePositionCard(row.id, p, findMonitorOrder(orders, p.symbol, p.side));
|
||||
html += renderLivePositionCard(row.id, row.key || row.id, p, findMonitorOrder(orders, p.symbol, p.side));
|
||||
});
|
||||
} else {
|
||||
html += '<div class="pos-empty">暂无持仓</div>';
|
||||
|
||||
Reference in New Issue
Block a user