Update netPNl value

This commit is contained in:
2025-10-03 00:56:47 +07:00
parent a31f834a68
commit 39b5fba2f0

View File

@@ -397,7 +397,9 @@ public class TradingBotBase : ITradingBot
// Position found on the broker, means the position is filled // Position found on the broker, means the position is filled
var brokerNetPnL = brokerPosition.GetNetPnL(); var brokerNetPnL = brokerPosition.GetNetPnL();
UpdatePositionPnl(positionForSignal.Identifier, brokerNetPnL); 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; internalPosition.Status = PositionStatus.Filled;
await SetPositionStatus(internalPosition.SignalIdentifier, PositionStatus.Filled); await SetPositionStatus(internalPosition.SignalIdentifier, PositionStatus.Filled);
@@ -1330,11 +1332,16 @@ public class TradingBotBase : ITradingBot
if (position.ProfitAndLoss == null) 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) else if (position.ProfitAndLoss.Realized == 0)
{ {
var totalFees = position.GasFees + position.UiFees;
var netPnl = pnl - totalFees;
position.ProfitAndLoss.Realized = pnl; position.ProfitAndLoss.Realized = pnl;
position.ProfitAndLoss.Net = netPnl;
} }
// Fees are now tracked separately in UiFees and GasFees properties // 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) 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 else
{ {
Positions[identifier].ProfitAndLoss.Realized = realized; position.ProfitAndLoss.Realized = realized;
position.ProfitAndLoss.Net = netPnl;
} }
} }