diff --git a/.gitignore b/.gitignore index a9ab8f41..42c16539 100644 --- a/.gitignore +++ b/.gitignore @@ -30,9 +30,12 @@ Thumbs.db # 环境变量 .env config.json -data.db* configbak.json +# 数据目录(数据库、日志等) +data/ +*.db + # 决策日志 decision_logs/ coin_pool_cache/ diff --git a/data/nofx.db b/data/nofx.db deleted file mode 100644 index e69de29b..00000000 diff --git a/store/position.go b/store/position.go index 361be6ab..fb5f0c08 100644 --- a/store/position.go +++ b/store/position.go @@ -929,6 +929,21 @@ func (s *PositionStore) CreateFromClosedPnL(traderID, exchangeID string, record now := time.Now() exitTime := record.ExitTime + entryTime := record.EntryTime + + // Handle zero entry time - use exit time or current time as fallback + if entryTime.IsZero() || entryTime.Year() < 2000 { + if !exitTime.IsZero() && exitTime.Year() >= 2000 { + entryTime = exitTime // Use exit time as approximation + } else { + entryTime = now // Last resort: use current time + } + } + + // Handle zero exit time + if exitTime.IsZero() || exitTime.Year() < 2000 { + exitTime = now + } _, err = s.db.Exec(` INSERT INTO trader_positions ( @@ -940,7 +955,7 @@ func (s *PositionStore) CreateFromClosedPnL(traderID, exchangeID string, record ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'CLOSED', ?, 'sync', ?, ?) `, traderID, exchangeID, exchangePositionID, record.Symbol, side, record.Quantity, - record.EntryPrice, "", record.EntryTime.Format(time.RFC3339), + record.EntryPrice, "", entryTime.Format(time.RFC3339), record.ExitPrice, record.OrderID, exitTime.Format(time.RFC3339), record.RealizedPnL, record.Fee, record.Leverage, record.CloseType, now.Format(time.RFC3339), now.Format(time.RFC3339),