Fix global PNL
This commit is contained in:
@@ -505,6 +505,28 @@ public class PostgreSqlTradingRepository : ITradingRepository
|
||||
return PostgreSqlMappers.Map(positions);
|
||||
}
|
||||
|
||||
public async Task<decimal> GetGlobalPnLFromPositionsAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await PostgreSqlConnectionHelper.EnsureConnectionOpenAsync(_context);
|
||||
|
||||
// Calculate total PnL from all finished positions (closed positions)
|
||||
// Only include positions that are Finished or Flipped (closed positions)
|
||||
var totalPnL = await _context.Positions
|
||||
.AsNoTracking()
|
||||
.Where(p => p.Status == PositionStatus.Finished || p.Status == PositionStatus.Flipped)
|
||||
.SumAsync(p => p.ProfitAndLoss)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return totalPnL;
|
||||
}
|
||||
finally
|
||||
{
|
||||
await PostgreSqlConnectionHelper.SafeCloseConnectionAsync(_context);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Signal Methods
|
||||
|
||||
Reference in New Issue
Block a user