fix(gate-bot): PnL colors, sync exchange TP/SL to plan display
Color floating PnL on position cards, mirror exchange stop/take prices in the grid and DB, and purge false external-close records on monitor relink.
This commit is contained in:
@@ -244,6 +244,9 @@
|
||||
.pos-value.price-up{color:#4cd97f}
|
||||
.pos-value.price-down{color:#ff6666}
|
||||
.pos-value.price-flat{color:#e8ecf4}
|
||||
.pos-value.pnl-profit{color:#4cd97f;font-weight:700}
|
||||
.pos-value.pnl-loss{color:#ff6666;font-weight:700}
|
||||
.pos-value.pnl-neutral{color:#cfd3ef;font-weight:600}
|
||||
.pos-footer{display:flex;flex-wrap:wrap;gap:14px 18px;font-size:.75rem;color:#6d7689}
|
||||
.pos-empty{padding:18px;text-align:center;color:#8892b0;font-size:.85rem;background:#141923;border:1px dashed #2a3348;border-radius:10px}
|
||||
.pos-card-orphan{border-color:#6a5528;background:#1a1810}
|
||||
@@ -478,19 +481,11 @@
|
||||
</div>
|
||||
<div class="pos-cell">
|
||||
<span class="pos-label">止损</span>
|
||||
{% if o.stop_loss %}
|
||||
<span class="pos-value">{{ price_fmt(o.symbol, o.stop_loss) }}</span>
|
||||
{% else %}
|
||||
<span class="pos-value pos-val-dash">—</span>
|
||||
{% endif %}
|
||||
<span class="pos-value" id="order-plan-sl-{{ o.id }}">{{ price_fmt(o.symbol, o.stop_loss) if o.stop_loss else '—' }}</span>
|
||||
</div>
|
||||
<div class="pos-cell">
|
||||
<span class="pos-label">止盈</span>
|
||||
{% if o.take_profit %}
|
||||
<span class="pos-value">{{ price_fmt(o.symbol, o.take_profit) }}</span>
|
||||
{% else %}
|
||||
<span class="pos-value pos-val-dash">—</span>
|
||||
{% endif %}
|
||||
<span class="pos-value" id="order-plan-tp-{{ o.id }}">{{ price_fmt(o.symbol, o.take_profit) if o.take_profit else '—' }}</span>
|
||||
</div>
|
||||
<div class="pos-cell">
|
||||
<span class="pos-label">盈亏比</span>
|
||||
@@ -1647,6 +1642,24 @@ function paintExchangeTpslRow(orderId, tpsl){
|
||||
if(slBtn) slBtn.disabled = !(data.sl && data.sl.order_id);
|
||||
if(tpBtn) tpBtn.disabled = !(data.tp && data.tp.order_id);
|
||||
}
|
||||
function paintPlanTpslDisplay(orderId, snap){
|
||||
if(!snap) return;
|
||||
const card = document.getElementById(`order-row-${orderId}`);
|
||||
const slEl = document.getElementById(`order-plan-sl-${orderId}`);
|
||||
const tpEl = document.getElementById(`order-plan-tp-${orderId}`);
|
||||
const rrEl = document.getElementById(`order-rr-${orderId}`);
|
||||
const slDisp = snap.stop_loss_display;
|
||||
const tpDisp = snap.take_profit_display;
|
||||
if(slEl && slDisp) slEl.innerText = slDisp;
|
||||
if(tpEl && tpDisp) tpEl.innerText = tpDisp;
|
||||
if(card){
|
||||
if(snap.stop_loss_raw != null && snap.stop_loss_raw !== "") card.setAttribute('data-plan-sl', formatPriceForInput(snap.stop_loss_raw));
|
||||
else if(slDisp) card.setAttribute('data-plan-sl', slDisp);
|
||||
if(snap.take_profit_raw != null && snap.take_profit_raw !== "") card.setAttribute('data-plan-tp', formatPriceForInput(snap.take_profit_raw));
|
||||
else if(tpDisp) card.setAttribute('data-plan-tp', tpDisp);
|
||||
}
|
||||
if(rrEl && typeof snap.rr_ratio !== "undefined") rrEl.innerText = formatRrRatio(snap.rr_ratio);
|
||||
}
|
||||
function toggleTpslModalMode(){
|
||||
const mode = (document.getElementById('tpsl-modal-mode')||{}).value || 'price';
|
||||
const pct = mode === 'pct';
|
||||
@@ -1696,6 +1709,13 @@ function submitTpslEntrust(){
|
||||
alert(data.msg || '已提交');
|
||||
closeTpslEntrustModal();
|
||||
if(data.exchange_tpsl) paintExchangeTpslRow(orderId, data.exchange_tpsl);
|
||||
paintPlanTpslDisplay(orderId, {
|
||||
stop_loss_raw: data.stop_loss,
|
||||
take_profit_raw: data.take_profit,
|
||||
stop_loss_display: data.stop_loss != null ? formatPriceForInput(data.stop_loss) : null,
|
||||
take_profit_display: data.take_profit != null ? formatPriceForInput(data.take_profit) : null,
|
||||
rr_ratio: data.planned_rr,
|
||||
});
|
||||
refreshPriceSnapshotConditional();
|
||||
}).catch(()=>alert('委托请求失败'));
|
||||
};
|
||||
@@ -1839,14 +1859,14 @@ function refreshPriceSnapshotConditional(){
|
||||
if(pnlEl){
|
||||
pnlEl.innerText = `${formatSigned(o.float_pnl, 2)}U (${formatSigned(o.float_pct, 2)}%)`;
|
||||
pnlEl.classList.remove("price-up","price-down","price-flat","pnl-profit","pnl-loss","pnl-neutral");
|
||||
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 fp = Number(o.float_pnl);
|
||||
if(fp > 0) pnlEl.classList.add("pnl-profit");
|
||||
else if(fp < 0) pnlEl.classList.add("pnl-loss");
|
||||
else pnlEl.classList.add("pnl-neutral");
|
||||
}
|
||||
const rrEl = document.getElementById(`order-rr-${o.id}`);
|
||||
if(rrEl) rrEl.innerText = formatRrRatio(o.rr_ratio);
|
||||
paintBreakevenBadge(o.id, o.sl_breakeven_secured);
|
||||
paintExchangeTpslRow(o.id, o.exchange_tpsl || {});
|
||||
paintPlanTpslDisplay(o.id, o);
|
||||
});
|
||||
}
|
||||
}).catch(()=>{});
|
||||
|
||||
Reference in New Issue
Block a user