fix: 重启后总PnL回到0的问题 + 前端PnL图表公式统一

- trader.go: NewTrader 启动时从DB GetAllClosedTrades() 加载所有已平仓交易到 closedTrades
- trader.go: 新增 safeFloat/safeStr 辅助函数处理DB空指针
- db/trade_repo.go: 新增 GetAllClosedTrades() 方法
- frontend: PnL图表标题和曲线改用 2*AmountUSD*NetPnl/100 公式,与后端Stats一致
This commit is contained in:
jackyu66git
2026-05-04 06:23:35 +08:00
parent 2f4d03f9b1
commit ddaa5badd2
3 changed files with 61 additions and 2 deletions
+2 -2
View File
@@ -562,7 +562,7 @@ function PnlChart() {
.filter(t => t.ClosedAt && t.NetPnl != null)
.sort((a, b) => new Date(a.ClosedAt) - new Date(b.ClosedAt))
setData(trades)
const total = trades.reduce((sum, t) => sum + (t.NetPnl || 0), 0)
const total = trades.reduce((sum, t) => sum + 2 * (t.AmountUSD || 0) * (t.NetPnl || 0) / 100, 0)
setTotalPnl(total)
} catch (e) {}
}
@@ -596,7 +596,7 @@ function PnlChart() {
const points = []
let cum = 0
for (const t of data) {
cum += (t.AmountUSD || 0) * (t.NetPnl || 0) / 100
cum += 2 * (t.AmountUSD || 0) * (t.NetPnl || 0) / 100
points.push({ x: new Date(t.ClosedAt).getTime(), y: cum })
}