mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-05 20:11:13 +08:00
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:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -30,9 +30,12 @@ Thumbs.db
|
||||
# 环境变量
|
||||
.env
|
||||
config.json
|
||||
data.db*
|
||||
configbak.json
|
||||
|
||||
# 数据目录(数据库、日志等)
|
||||
data/
|
||||
*.db
|
||||
|
||||
# 决策日志
|
||||
decision_logs/
|
||||
coin_pool_cache/
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user