Add net Pnl in db
This commit is contained in:
@@ -237,7 +237,8 @@ public class AgentGrain : Grain, IAgentGrain
|
||||
{
|
||||
UserId = (int)this.GetPrimaryKeyLong(),
|
||||
AgentName = _state.State.AgentName,
|
||||
TotalPnL = totalPnL, // Use net PnL without fees
|
||||
TotalPnL = totalPnL, // Gross PnL before fees
|
||||
NetPnL = netPnL, // Net PnL after fees
|
||||
Wins = totalWins,
|
||||
Losses = totalLosses,
|
||||
TotalROI = totalROI,
|
||||
|
||||
@@ -720,12 +720,13 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
var (tradeWins, tradeLosses) = TradingBox.GetWinLossCount(_tradingBot.Positions);
|
||||
var pnl = _tradingBot.GetProfitAndLoss();
|
||||
var fees = _tradingBot.GetTotalFees();
|
||||
var netPnl = pnl - fees; // Net PnL after fees
|
||||
var volume = TradingBox.GetTotalVolumeTraded(_tradingBot.Positions);
|
||||
|
||||
// Calculate ROI based on total investment (PnL minus fees)
|
||||
// Calculate ROI based on total investment (Net PnL)
|
||||
var totalInvestment = _tradingBot.Positions.Values
|
||||
.Sum(p => p.Open.Quantity * p.Open.Price);
|
||||
var roi = totalInvestment > 0 ? ((pnl - fees) / totalInvestment) * 100 : 0;
|
||||
var roi = totalInvestment > 0 ? (netPnl / totalInvestment) * 100 : 0;
|
||||
|
||||
// Calculate long and short position counts
|
||||
var longPositionCount = _tradingBot.Positions.Values
|
||||
@@ -745,7 +746,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
CreateDate = _state.State.CreateDate,
|
||||
TradeWins = tradeWins,
|
||||
TradeLosses = tradeLosses,
|
||||
Pnl = pnl,
|
||||
Pnl = pnl, // Gross PnL before fees
|
||||
NetPnL = netPnl, // Net PnL after fees
|
||||
Roi = roi,
|
||||
Volume = volume,
|
||||
Fees = fees,
|
||||
|
||||
@@ -68,6 +68,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
TotalStrategies = 0,
|
||||
TotalVolume = 0,
|
||||
TotalPnL = 0,
|
||||
NetPnL = 0,
|
||||
TotalOpenInterest = 0,
|
||||
TotalLifetimePositionCount = 0,
|
||||
TotalPlatformFees = 0,
|
||||
@@ -170,6 +171,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
_state.State.TotalPlatformVolume = totalVolume;
|
||||
_state.State.TotalPlatformFees = totalFees;
|
||||
_state.State.TotalPlatformPnL = totalPnL;
|
||||
_state.State.NetPnL = totalPnL - totalFees; // Calculate NetPnL
|
||||
_state.State.OpenInterest = totalOpenInterest;
|
||||
_state.State.TotalLifetimePositionCount = totalPositionCount;
|
||||
_state.State.HasPendingChanges = false;
|
||||
@@ -289,6 +291,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
||||
TotalStrategies = _state.State.TotalActiveStrategies,
|
||||
TotalVolume = _state.State.TotalPlatformVolume,
|
||||
TotalPnL = _state.State.TotalPlatformPnL,
|
||||
NetPnL = _state.State.NetPnL,
|
||||
TotalOpenInterest = _state.State.OpenInterest,
|
||||
TotalLifetimePositionCount = _state.State.TotalLifetimePositionCount,
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Managing.Application.ManageBot.Commands
|
||||
public GetPaginatedAgentSummariesCommand(
|
||||
int page = 1,
|
||||
int pageSize = 10,
|
||||
SortableFields sortBy = SortableFields.TotalPnL,
|
||||
SortableFields sortBy = SortableFields.NetPnL,
|
||||
string sortOrder = "desc",
|
||||
IEnumerable<string>? agentNames = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user