Fix mark/PnL display fallback and intraday entry labels
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -891,6 +891,38 @@ function paintPriceTrend(el, key, value){
|
||||
lastPriceMap[key] = value;
|
||||
}
|
||||
|
||||
function formatOrderMarkDisplay(o){
|
||||
const row = o || {};
|
||||
const markRaw = row.exchange_mark_price;
|
||||
const markNum = Number(markRaw);
|
||||
const hasMark = markRaw !== null && markRaw !== undefined && markRaw !== "" && Number.isFinite(markNum) && markNum > 0;
|
||||
if(hasMark){
|
||||
if(row.exchange_mark_price_display && row.exchange_mark_price_display !== "-") return row.exchange_mark_price_display;
|
||||
return markNum.toFixed(6);
|
||||
}
|
||||
if(row.price_display && row.price_display !== "-") return row.price_display;
|
||||
const px = Number(row.price);
|
||||
return Number.isFinite(px) && px > 0 ? px.toFixed(6) : "-";
|
||||
}
|
||||
function paintOrderMarkAndPnl(orderId, o){
|
||||
const pEl = document.getElementById(`order-price-${orderId}`);
|
||||
if(pEl){
|
||||
const disp = formatOrderMarkDisplay(o);
|
||||
pEl.innerText = disp;
|
||||
const markNum = Number(o && o.exchange_mark_price);
|
||||
const pxNum = Number.isFinite(markNum) && markNum > 0 ? markNum : Number(o && o.price);
|
||||
paintPriceTrend(pEl, `o-${orderId}`, Number.isFinite(pxNum) ? pxNum : null);
|
||||
}
|
||||
const pnlEl = document.getElementById(`order-pnl-${orderId}`);
|
||||
if(pnlEl){
|
||||
pnlEl.innerText = `${formatSigned(o.float_pnl, 2)}U (${formatSigned(o.float_pct, 2)}%)`;
|
||||
pnlEl.classList.remove("price-up","price-down","price-flat");
|
||||
if(Number(o.float_pnl) > 0) pnlEl.classList.add("price-up");
|
||||
else if(Number(o.float_pnl) < 0) pnlEl.classList.add("price-down");
|
||||
else pnlEl.classList.add("price-flat");
|
||||
}
|
||||
}
|
||||
|
||||
function refreshPriceSnapshot(){
|
||||
fetch("/api/price_snapshot").then(r=>r.json()).then(data=>{
|
||||
const updatedEl = document.getElementById("price-last-updated");
|
||||
@@ -925,22 +957,7 @@ function refreshPriceSnapshot(){
|
||||
}
|
||||
});
|
||||
(data.order_prices || []).forEach(o=>{
|
||||
const pEl = document.getElementById(`order-price-${o.id}`);
|
||||
if(pEl){
|
||||
const hasMark = (()=>{ const x = o.exchange_mark_price; if(x===null||x===undefined||x==="")return false; const n=Number(x); return !Number.isNaN(n); })();
|
||||
let disp = "";
|
||||
if(hasMark && o.exchange_mark_price_display){
|
||||
disp = o.exchange_mark_price_display;
|
||||
} else if(o.price_display){
|
||||
disp = o.price_display;
|
||||
} else {
|
||||
const px = hasMark ? Number(o.exchange_mark_price) : Number(o.price);
|
||||
disp = Number.isFinite(px) ? px.toFixed(6) : "-";
|
||||
}
|
||||
pEl.innerText = disp;
|
||||
const pxNum = hasMark ? Number(o.exchange_mark_price) : Number(o.price);
|
||||
paintPriceTrend(pEl, `o-${o.id}`, Number.isFinite(pxNum) ? pxNum : px);
|
||||
}
|
||||
paintOrderMarkAndPnl(o.id, o);
|
||||
const exM = document.getElementById(`order-ex-margin-${o.id}`);
|
||||
if(exM){
|
||||
const mv = o.exchange_initial_margin;
|
||||
@@ -952,14 +969,6 @@ function refreshPriceSnapshot(){
|
||||
exM.innerText = (prc === 0) ? "无仓数据" : "-";
|
||||
}
|
||||
}
|
||||
const pnlEl = document.getElementById(`order-pnl-${o.id}`);
|
||||
if(pnlEl){
|
||||
pnlEl.innerText = `${formatSigned(o.float_pnl, 2)}U (${formatSigned(o.float_pct, 2)}%)`;
|
||||
pnlEl.classList.remove("price-up","price-down","price-flat");
|
||||
if(Number(o.float_pnl) > 0) pnlEl.classList.add("price-up");
|
||||
else if(Number(o.float_pnl) < 0) pnlEl.classList.add("price-down");
|
||||
else pnlEl.classList.add("price-flat");
|
||||
}
|
||||
const rrEl = document.getElementById(`order-rr-${o.id}`);
|
||||
if(rrEl){
|
||||
const rr = o.display_rr_ratio != null && o.display_rr_ratio !== "" ? o.display_rr_ratio : o.rr_ratio;
|
||||
@@ -1225,19 +1234,10 @@ function refreshPriceSnapshotConditional(){
|
||||
if(typeof paintKeyMonitorSummary === "function") paintKeyMonitorSummary(k.id, k);
|
||||
});
|
||||
}
|
||||
if(page === "trade"){
|
||||
const tradePage = page === "trade" || !!document.querySelector("[id^='order-price-']");
|
||||
if(tradePage){
|
||||
(data.order_prices || []).forEach(o=>{
|
||||
const pEl = document.getElementById(`order-price-${o.id}`);
|
||||
if(pEl){
|
||||
const hasMark = (()=>{ const x = o.exchange_mark_price; if(x===null||x===undefined||x==="")return false; const n=Number(x); return !Number.isNaN(n); })();
|
||||
let disp = "";
|
||||
if(hasMark && o.exchange_mark_price_display) disp = o.exchange_mark_price_display;
|
||||
else if(o.price_display) disp = o.price_display;
|
||||
else { const px = hasMark ? Number(o.exchange_mark_price) : Number(o.price); disp = Number.isFinite(px) ? px.toFixed(6) : "-"; }
|
||||
pEl.innerText = disp;
|
||||
const pxNum = hasMark ? Number(o.exchange_mark_price) : Number(o.price);
|
||||
paintPriceTrend(pEl, `o-${o.id}`, Number.isFinite(pxNum) ? pxNum : px);
|
||||
}
|
||||
paintOrderMarkAndPnl(o.id, o);
|
||||
const exM = document.getElementById(`order-ex-margin-${o.id}`);
|
||||
if(exM){
|
||||
const mv = o.exchange_initial_margin;
|
||||
@@ -1245,14 +1245,6 @@ function refreshPriceSnapshotConditional(){
|
||||
if(!Number.isNaN(mn)) exM.innerText = `${mn.toFixed(2)}U`;
|
||||
else { const prc = (typeof data.positions_raw_count === "number") ? data.positions_raw_count : null; exM.innerText = (prc === 0) ? "无仓数据" : "-"; }
|
||||
}
|
||||
const pnlEl = document.getElementById(`order-pnl-${o.id}`);
|
||||
if(pnlEl){
|
||||
pnlEl.innerText = `${formatSigned(o.float_pnl, 2)}U (${formatSigned(o.float_pct, 2)}%)`;
|
||||
pnlEl.classList.remove("price-up","price-down","price-flat");
|
||||
if(Number(o.float_pnl) > 0) pnlEl.classList.add("price-up");
|
||||
else if(Number(o.float_pnl) < 0) pnlEl.classList.add("price-down");
|
||||
else pnlEl.classList.add("price-flat");
|
||||
}
|
||||
const rrEl = document.getElementById(`order-rr-${o.id}`);
|
||||
if(rrEl) rrEl.innerText = formatRrRatio(o.rr_ratio);
|
||||
paintBreakevenBadge(o.id, o.sl_breakeven_secured);
|
||||
|
||||
@@ -111,7 +111,7 @@
|
||||
</div>
|
||||
<div class="pos-meta">
|
||||
<span class="pos-meta-item">来源: {{ o.monitor_type|default('下单监控', true) }}{% if o.key_signal_type %} · {{ o.key_signal_type }}{% endif %}</span>
|
||||
<span class="pos-meta-item">{% if o.entry_model_label %}开仓: {{ o.entry_model_label }}{% else %}风格: {{ '波段单' if o.trade_style == 'swing' else '趋势单' }}{% endif %}</span>
|
||||
<span class="pos-meta-item">{% if o.entry_model_label %}开仓: {{ o.entry_model_label }}{% elif intraday_discipline %}开仓: —{% else %}风格: {{ '波段单' if o.trade_style == 'swing' else '趋势单' }}{% endif %}</span>
|
||||
<span class="pos-meta-item">风险: {% if position_sizing_mode == 'full_margin' %}{{ funds_fmt(o.risk_amount) if o.risk_amount is not none else '-' }}U{% else %}{{ o.risk_percent or '-' }}%≈{{ funds_fmt(o.risk_amount) if o.risk_amount is not none else '-' }}U{% endif %}</span>
|
||||
<span class="pos-meta-item" id="order-latest-risk-wrap-{{ o.id }}" style="display:none">最新风险: —</span>
|
||||
<span class="pos-meta-item {% if not intraday_discipline %}{% if o.breakeven_enabled %}pos-meta-on{% else %}pos-meta-off{% endif %}{% endif %}">
|
||||
|
||||
@@ -224,7 +224,7 @@
|
||||
</div>
|
||||
<div class="pos-meta">
|
||||
<span class="pos-meta-item">来源: {{ o.monitor_type|default('下单监控', true) }}{% if o.key_signal_type %} · {{ o.key_signal_type }}{% endif %}</span>
|
||||
<span class="pos-meta-item">{% if o.entry_model_label %}开仓: {{ o.entry_model_label }}{% else %}风格: {{ '波段单' if o.trade_style == 'swing' else '趋势单' }}{% endif %}</span>
|
||||
<span class="pos-meta-item">{% if o.entry_model_label %}开仓: {{ o.entry_model_label }}{% elif intraday_discipline %}开仓: —{% else %}风格: {{ '波段单' if o.trade_style == 'swing' else '趋势单' }}{% endif %}</span>
|
||||
<span class="pos-meta-item">风险: {% if position_sizing_mode == 'full_margin' %}{{ funds_fmt(o.risk_amount) if o.risk_amount is not none else '-' }}U{% else %}{{ o.risk_percent or '-' }}%≈{{ funds_fmt(o.risk_amount) if o.risk_amount is not none else '-' }}U{% endif %}</span>
|
||||
<span class="pos-meta-item" id="order-latest-risk-wrap-{{ o.id }}" style="display:none">最新风险: —</span>
|
||||
<span class="pos-meta-item {% if not intraday_discipline %}{% if o.breakeven_enabled %}pos-meta-on{% else %}pos-meta-off{% endif %}{% endif %}">
|
||||
|
||||
Reference in New Issue
Block a user