diff --git a/src/Managing.Application/Bots/TradingBotBase.cs b/src/Managing.Application/Bots/TradingBotBase.cs index 063d6361..a08977c6 100644 --- a/src/Managing.Application/Bots/TradingBotBase.cs +++ b/src/Managing.Application/Bots/TradingBotBase.cs @@ -397,7 +397,9 @@ public class TradingBotBase : ITradingBot // Position found on the broker, means the position is filled var brokerNetPnL = brokerPosition.GetNetPnL(); UpdatePositionPnl(positionForSignal.Identifier, brokerNetPnL); - internalPosition.ProfitAndLoss = new ProfitAndLoss { Realized = brokerNetPnL }; + var totalFees = internalPosition.GasFees + internalPosition.UiFees; + var netPnl = brokerNetPnL - totalFees; + internalPosition.ProfitAndLoss = new ProfitAndLoss { Realized = brokerNetPnL, Net = netPnl }; internalPosition.Status = PositionStatus.Filled; await SetPositionStatus(internalPosition.SignalIdentifier, PositionStatus.Filled); @@ -1330,11 +1332,16 @@ public class TradingBotBase : ITradingBot if (position.ProfitAndLoss == null) { - position.ProfitAndLoss = new ProfitAndLoss { Realized = pnl }; + var totalFees = position.GasFees + position.UiFees; + var netPnl = pnl - totalFees; + position.ProfitAndLoss = new ProfitAndLoss { Realized = pnl, Net = netPnl }; } else if (position.ProfitAndLoss.Realized == 0) { + var totalFees = position.GasFees + position.UiFees; + var netPnl = pnl - totalFees; position.ProfitAndLoss.Realized = pnl; + position.ProfitAndLoss.Net = netPnl; } // Fees are now tracked separately in UiFees and GasFees properties @@ -1466,16 +1473,22 @@ public class TradingBotBase : ITradingBot private void UpdatePositionPnl(Guid identifier, decimal realized) { - if (Positions[identifier].ProfitAndLoss == null) + var position = Positions[identifier]; + var totalFees = position.GasFees + position.UiFees; + var netPnl = realized - totalFees; + + if (position.ProfitAndLoss == null) { - Positions[identifier].ProfitAndLoss = new ProfitAndLoss() + position.ProfitAndLoss = new ProfitAndLoss() { - Realized = realized + Realized = realized, + Net = netPnl }; } else { - Positions[identifier].ProfitAndLoss.Realized = realized; + position.ProfitAndLoss.Realized = realized; + position.ProfitAndLoss.Net = netPnl; } }