fix: 重启后加仓数据恢复 + scale_count/amount_usd 实时持久化

- restoreOpenPositions 从 orders 表 count 加仓次数,正确设置 ScaleLevels 和 AmountUSD
- 加仓时立即持久化 amount_usd 和 scale_count 到 trades 表(不等到平仓)
- PnL 图表支持单笔交易显示(原点+累计PnL连线)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jackyu66git
2026-05-05 03:19:26 +08:00
co-authored by Claude Opus 4.7
parent f97ac16b1c
commit 2f4d7869a9
3 changed files with 32 additions and 10 deletions
+6 -1
View File
@@ -651,6 +651,11 @@ function PnlChart() {
// Compute cumulative PnL
const points = []
let cum = 0
// Prepend a zero point so single-trade chart still draws
if (data.length > 0) {
const t0 = new Date(data[0].ClosedAt).getTime() - 1000
points.push({ x: t0, y: 0 })
}
for (const t of data) {
cum += 2 * (t.AmountUSD || 0) * (t.NetPnl || 0) / 100
points.push({ x: new Date(t.ClosedAt).getTime(), y: cum })
@@ -756,7 +761,7 @@ function PnlChart() {
<section className="card card-wide" id="pnl-chart-card">
<h2>📈 总PnL成长曲线 <span className="text-dim" style={{fontSize:11}}>{data.length > 0 ? `$${totalPnl.toFixed(2)}` : ''}</span></h2>
<div className="chart-container" style={{height:260}}>
{data.length < 2 ? (
{data.length < 1 ? (
<div className="loading" style={{paddingTop:100}}>暂无数据...</div>
) : (
<canvas ref={canvasRef} />