mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 14:56:57 +08:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user