diff --git a/.cursor/rules/fullstack.mdc b/.cursor/rules/fullstack.mdc index 10d93df9..20cd22d5 100644 --- a/.cursor/rules/fullstack.mdc +++ b/.cursor/rules/fullstack.mdc @@ -99,3 +99,4 @@ Key Principles - do not implement business logic on the controller, keep the business logic for Service files - When adding new property to and Orleans state, always add the property after the last one and increment the id - Do not use "npm" use only "bun" command for Web3Proxy and WebApp + - Do not write .md documentation useless asked by the user in the prompt diff --git a/src/Managing.Application/Bots/SpotBot.cs b/src/Managing.Application/Bots/SpotBot.cs index 33cfa1fe..e5171ce8 100644 --- a/src/Managing.Application/Bots/SpotBot.cs +++ b/src/Managing.Application/Bots/SpotBot.cs @@ -984,6 +984,23 @@ public class SpotBot : TradingBotBase var totalBotFees = position.GasFees + position.UiFees; var brokerRealizedPnl = brokerPosition.ProfitAndLoss.Realized; + // If broker PNL is 0 or invalid, calculate it ourselves using actual prices + if (brokerRealizedPnl == 0 && brokerPosition.Open != null) + { + var entryPrice = position.Open.Price; + var exitPrice = brokerPosition.Open.Price; + var quantity = position.Open.Quantity; + + // Calculate PNL: (exitPrice - entryPrice) * quantity for LONG + brokerRealizedPnl = TradingBox.CalculatePnL(entryPrice, exitPrice, quantity, 1, position.OriginDirection); + + await LogDebugAsync( + $"⚠️ Broker PNL was 0, calculated from prices\n" + + $"Entry Price: `${entryPrice:F2}` | Exit Price: `${exitPrice:F2}`\n" + + $"Quantity: `{quantity:F8}`\n" + + $"Calculated PNL: `${brokerRealizedPnl:F2}`"); + } + position.ProfitAndLoss = new ProfitAndLoss { Realized = brokerRealizedPnl,