fix: 修正盈亏计算以包含实盘数据

使用实盘盈亏和手续费计算有效盈亏,当实盘数据存在时优先使用。
同时保留原有的价格差盈亏计算作为参考。
This commit is contained in:
薇薇安 2026-02-16 11:54:37 +08:00
parent 0eb9b076e3
commit 22efd377a7

View File

@ -100,8 +100,28 @@ const TradeList = () => {
const margin = trade.margin_usdt !== undefined && trade.margin_usdt !== null
? parseFloat(trade.margin_usdt)
: (leverage > 0 ? notional / leverage : 0)
const pnl = parseFloat(trade.pnl || 0)
const pnlPercent = margin > 0 ? (pnl / margin) * 100 : 0
const localPnl = parseFloat(trade.pnl || 0)
const localPnlPercent = margin > 0 ? (localPnl / margin) * 100 : 0
const realizedPnl = trade.realized_pnl !== undefined && trade.realized_pnl !== null
? parseFloat(trade.realized_pnl)
: null
const commission = trade.commission !== undefined && trade.commission !== null
? parseFloat(trade.commission)
: null
const commissionAsset = trade.commission_asset || null
let netBinancePnl = null
if (realizedPnl !== null) {
netBinancePnl = realizedPnl
if (commission !== null && commissionAsset === 'USDT') {
netBinancePnl = netBinancePnl - commission
}
}
const effectivePnl = netBinancePnl !== null ? netBinancePnl : localPnl
const effectivePnlPercent = margin > 0 ? (effectivePnl / margin) * 100 : 0
const row = {
交易ID: trade.id,
@ -113,8 +133,12 @@ const TradeList = () => {
杠杆: leverage,
入场价: parseFloat(trade.entry_price || 0),
出场价: trade.exit_price ? parseFloat(trade.exit_price) : null,
盈亏: pnl,
盈亏比例: pnlPercent,
盈亏: effectivePnl,
盈亏比例: effectivePnlPercent,
盈亏_实盘: netBinancePnl,
盈亏_实盘比例: netBinancePnl !== null && margin > 0 ? (netBinancePnl / margin) * 100 : null,
盈亏_价格差: localPnl,
盈亏_价格差比例: localPnlPercent,
状态: trade.status === 'open' ? '持仓中' : trade.status === 'closed' ? '已平仓' : '已取消',
平仓类型: trade.exit_reason_display || '-',
开仓订单号: trade.entry_order_id || '-',