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
View File
@@ -118,6 +118,12 @@ func (d *DB) UpdateTradeEntry(id int64, t *TradeRecord) error {
return err
}
// UpdateTradeScale updates scale-in fields on an existing trade (amount_usd, scale_count).
func (d *DB) UpdateTradeScale(id int64, amountUSD float64, scaleCount int) error {
_, err := d.Exec("UPDATE trades SET amount_usd=?, scale_count=? WHERE id=?", amountUSD, scaleCount, id)
return err
}
// GetOpenTrades returns all non-closed trades (status='open' or status='entering').
func (d *DB) GetOpenTrades() ([]TradeRecord, error) {
rows, err := d.Query(`SELECT id, coin, direction, status, entry_spread, exit_spread,