fix: handle zero entry_time in position sync and update gitignore

- Add fallback for zero/invalid entry_time when syncing positions
- Update .gitignore to ignore data/ directory and all .db files
- Remove accidentally committed nofx.db and image files
This commit is contained in:
tinkle-community
2025-12-10 15:06:06 +08:00
parent 8f07869d74
commit f6869a3d30
3 changed files with 20 additions and 2 deletions

5
.gitignore vendored
View File

@@ -30,9 +30,12 @@ Thumbs.db
# 环境变量
.env
config.json
data.db*
configbak.json
# 数据目录(数据库、日志等)
data/
*.db
# 决策日志
decision_logs/
coin_pool_cache/

View File

View File

@@ -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),