Fix ROI calculation for Strategy
This commit is contained in:
@@ -791,12 +791,18 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
var positionForMetrics = _tradingBot.Positions.Where(p => p.Value.IsValidForMetrics())
|
||||
.Select(p => p.Value).ToList();
|
||||
var positionForMetrics = await ServiceScopeHelpers.WithScopedService<ITradingService, List<Position>>(
|
||||
_scopeFactory,
|
||||
async tradingService =>
|
||||
{
|
||||
return (await tradingService.GetPositionsByInitiatorIdentifierAsync(this.GetPrimaryKey()))
|
||||
.Where(p => p.IsValidForMetrics()).ToList();
|
||||
});
|
||||
|
||||
// Calculate statistics using TradingBox helpers
|
||||
var (tradeWins, tradeLosses) = TradingBox.GetWinLossCount(positionForMetrics);
|
||||
var pnl = _tradingBot.GetProfitAndLoss();
|
||||
var fees = _tradingBot.GetTotalFees();
|
||||
var pnl = positionForMetrics.Sum(p => p.ProfitAndLoss.Realized);
|
||||
var fees = positionForMetrics.Sum(p => p.CalculateTotalFees());
|
||||
var netPnl = pnl - fees; // Net PnL after fees
|
||||
var volume = TradingBox.GetTotalVolumeTraded(positionForMetrics);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user