From 73789f7fb723d637f148757e8652567467ac20c1 Mon Sep 17 00:00:00 2001 From: tinkle-community Date: Wed, 14 Jan 2026 12:45:31 +0800 Subject: [PATCH] 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. --- trader/auto_trader_grid.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/trader/auto_trader_grid.go b/trader/auto_trader_grid.go index c417c7ed..ca17fbfa 100644 --- a/trader/auto_trader_grid.go +++ b/trader/auto_trader_grid.go @@ -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) }