feat(web): trade detail modal with prices, fees, timestamps

- Click any trade row in history table to open detail modal
- Modal shows 6 sections: 概览, 时间, 价差, 手续费, 多仓, 空仓
- Entries and exits displayed with 6 decimal precision
- Fee entry/exit and total fee displayed
- Open/close timestamps with full date-time format
- Duration, scale count, total amount, exit reason
- Orders sub-table if available
- Escape key and overlay click to close
This commit is contained in:
jackyu66git
2026-05-03 18:59:28 +08:00
parent 02b74f1ec0
commit 505137bcb0
6 changed files with 229 additions and 4 deletions
+12 -2
View File
@@ -119,7 +119,10 @@ type Trader struct {
mu sync.Mutex
positions map[string]*ArbPosition // coin -> position
lastTradeTime map[string]time.Time
closedTrades []TradeRecord // history of closed trades
closedTrades []TradeRecord // history of closed trades (current session)
// Historical stats loaded from DB on startup — combined with session stats in GetClosedStats
dbConverged, dbDiverged, dbFlat, dbTotal int
OnTradeEvent func(event string, data interface{}) // P3-4: real-time SSE push
@@ -163,6 +166,10 @@ func NewTrader(cfg *Config, database *db.DB) *Trader {
// Restore open positions from DB on restart
if database != nil {
t.restoreOpenPositions()
// Load historical closed trade stats for convergence display
if c, d, f, tot, err := database.GetClosedStats(); err == nil {
t.dbConverged, t.dbDiverged, t.dbFlat, t.dbTotal = c, d, f, tot
}
}
return t
@@ -720,10 +727,13 @@ func weightedAvgPrice(prices []float64, amountPerTrade float64) float64 {
return totalCost / totalShares
}
// GetClosedStats returns convergence stats from all closed trades.
// GetClosedStats returns convergence stats from all closed trades (DB history + current session).
func (t *Trader) GetClosedStats() (converged, diverged, flat, total int) {
t.mu.Lock()
defer t.mu.Unlock()
// Start with DB historical counts
converged, diverged, flat, total = t.dbConverged, t.dbDiverged, t.dbFlat, t.dbTotal
// Add in-memory session trades
for _, tr := range t.closedTrades {
total++
switch tr.Convergence {