Fix status and filtered positions for metrics
This commit is contained in:
@@ -791,22 +791,24 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
}
|
||||
}
|
||||
|
||||
var positionForMetrics = _tradingBot.Positions.Where(p => p.Value.IsValidForMetrics())
|
||||
.Select(p => p.Value).ToList();
|
||||
// Calculate statistics using TradingBox helpers
|
||||
var (tradeWins, tradeLosses) = TradingBox.GetWinLossCount(_tradingBot.Positions);
|
||||
var (tradeWins, tradeLosses) = TradingBox.GetWinLossCount(positionForMetrics);
|
||||
var pnl = _tradingBot.GetProfitAndLoss();
|
||||
var fees = _tradingBot.GetTotalFees();
|
||||
var netPnl = pnl - fees; // Net PnL after fees
|
||||
var volume = TradingBox.GetTotalVolumeTraded(_tradingBot.Positions);
|
||||
var volume = TradingBox.GetTotalVolumeTraded(positionForMetrics);
|
||||
|
||||
// Calculate ROI based on total investment (Net PnL)
|
||||
var totalInvestment = _tradingBot.Positions.Values
|
||||
var totalInvestment = positionForMetrics
|
||||
.Sum(p => p.Open.Quantity * p.Open.Price);
|
||||
var roi = totalInvestment > 0 ? (netPnl / totalInvestment) * 100 : 0;
|
||||
|
||||
// Calculate long and short position counts
|
||||
var longPositionCount = _tradingBot.Positions.Values
|
||||
var longPositionCount = positionForMetrics
|
||||
.Count(p => p.OriginDirection == TradeDirection.Long);
|
||||
var shortPositionCount = _tradingBot.Positions.Values
|
||||
var shortPositionCount = positionForMetrics
|
||||
.Count(p => p.OriginDirection == TradeDirection.Short);
|
||||
|
||||
// Create complete Bot object with all statistics
|
||||
|
||||
Reference in New Issue
Block a user