fix(grid): update daily PnL when stop loss is executed

The updateDailyPnL() function was added but never called, leaving
DailyPnL always at 0 and preventing daily loss limit checks from
triggering.

This fix updates DailyPnL and TotalProfit directly in checkAndExecuteStopLoss()
when a stop loss is executed. We update directly rather than calling
updateDailyPnL() because the mutex is already held in that function.
This commit is contained in:
tinkle-community
2026-01-14 12:45:31 +08:00
parent 65f333e73c
commit 73789f7fb7

View File

@@ -967,8 +967,12 @@ func (at *AutoTrader) checkAndExecuteStopLoss() {
logger.Errorf("[Grid] Failed to execute stop loss for level %d: %v", i, closeErr)
} else {
level.State = "stopped"
level.UnrealizedPnL = -lossPct * level.AllocatedUSD / 100
realizedLoss := -lossPct * level.AllocatedUSD / 100
level.UnrealizedPnL = realizedLoss
at.gridState.TotalTrades++
// Update daily PnL tracking (lock already held, update directly)
at.gridState.DailyPnL += realizedLoss
at.gridState.TotalProfit += realizedLoss
logger.Infof("[Grid] Stop loss executed: Level %d closed at $%.2f (loss %.2f%%)",
i, currentPrice, lossPct)
}