fix: floating PnL now accounts for half-position after TP1

Before: unrealR = full position × price move (wrong after TP1)
After: unrealR = 0.5×TP1_locked + 0.5×current_float (correct)

This fixes the display showing >1R floating profit that never
materializes in final PnL because only half position remains.
This commit is contained in:
root 2026-03-01 09:48:46 +00:00
parent 2f9dce483c
commit 4b841bc5f4

View File

@ -213,7 +213,10 @@ function ActivePositions() {
const entry = p.entry_price || 0; const entry = p.entry_price || 0;
const atr = p.atr_at_entry || 1; const atr = p.atr_at_entry || 1;
const riskDist = 2.0 * 0.7 * atr; const riskDist = 2.0 * 0.7 * atr;
const unrealR = riskDist > 0 ? (p.direction === "LONG" ? (currentPrice - entry) / riskDist : (entry - currentPrice) / riskDist) : 0; // TP1触发后只剩半仓0.5×TP1锁定 + 0.5×当前浮盈
const fullR = riskDist > 0 ? (p.direction === "LONG" ? (currentPrice - entry) / riskDist : (entry - currentPrice) / riskDist) : 0;
const tp1R = riskDist > 0 ? (p.direction === "LONG" ? ((p.tp1_price || 0) - entry) / riskDist : (entry - (p.tp1_price || 0)) / riskDist) : 0;
const unrealR = p.tp1_hit ? 0.5 * tp1R + 0.5 * fullR : fullR;
const unrealUsdt = unrealR * 200; const unrealUsdt = unrealR * 200;
return ( return (
<div key={p.id} className="px-3 py-2"> <div key={p.id} className="px-3 py-2">