From f6869a3d30529a4f1cb3f47e431983507e703b46 Mon Sep 17 00:00:00 2001 From: tinkle-community Date: Wed, 10 Dec 2025 15:06:06 +0800 Subject: [PATCH] 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 --- .gitignore | 5 ++++- data/nofx.db | 0 store/position.go | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) delete mode 100644 data/nofx.db 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),