fix: data race, scale-in PnL, nonce mutex, dead code, hourly check

- 🔴 Data race: Add GetPositionsCopy() returning deep copies (no shared
  ArbPosition pointers). Use it in dashboard broadcastLoop + handleStatus.
- 🟡 Scale-in PnL: Track LongEntryPrices/ShortEntryPrices on ArbPosition,
  compute weighted average (harmonic mean) at exit for accurate PnL.
- 🟢 CalcNetProfit: Delete dead code from exchange/helpers.go.
- 🟢 HL nonce: Add sync.Mutex around lastNonce++ (thread safety).
- 🟢 Hourly check: Change from 5-second window to minute window.
- 🟢 ExitPrice: Test mode closeLeg already handled by checkExit.
This commit is contained in:
jackyu66git
2026-05-03 18:31:14 +08:00
parent ab48e207a5
commit b08d8490fc
6 changed files with 94 additions and 54 deletions
+3 -3
View File
@@ -187,10 +187,10 @@ func main() {
tickMs, t1.Sub(t0).Milliseconds(), t2.Sub(t1).Milliseconds(), t3.Sub(t2).Milliseconds())
}
// Hourly trade summary
// Hourly trade summary — use hour-based tracking (wider window than second-granularity)
hour := now.Hour()
if now.Minute() == 0 && now.Second() < 5 && hour != lastHour {
positions := trader.GetOpenPositions()
if hour != lastHour && now.Minute() < 1 {
positions := trader.GetPositionsCopy()
notifier.SendTradeSummary(positions, now.Format("2006-01-02 15:04"))
lastHour = hour
}