Add test for dailysnapshot

This commit is contained in:
2025-11-14 19:42:52 +07:00
parent 479fcca662
commit b60295fcb2
3 changed files with 702 additions and 27 deletions

View File

@@ -849,17 +849,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
.Where(p => p.IsValidForMetrics()).ToList();
});
// Calculate statistics using TradingBox helpers
var (tradeWins, tradeLosses) = TradingBox.GetWinLossCount(positionForMetrics);
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);
// Calculate ROI based on total investment (Net PnL)
var totalInvestment = positionForMetrics
.Sum(p => p.Open.Quantity * p.Open.Price);
var roi = totalInvestment > 0 ? (netPnl / totalInvestment) * 100 : 0;
// Calculate statistics using TradingBox.CalculateAgentSummaryMetrics
var agentMetrics = TradingBox.CalculateAgentSummaryMetrics(positionForMetrics);
// Calculate long and short position counts
var longPositionCount = positionForMetrics
@@ -880,13 +871,13 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
LastStopTime = _state.State.LastStopTime,
AccumulatedRunTimeSeconds = _state.State.AccumulatedRunTimeSeconds,
CreateDate = _state.State.CreateDate,
TradeWins = tradeWins,
TradeLosses = tradeLosses,
Pnl = pnl, // Gross PnL before fees
NetPnL = netPnl, // Net PnL after fees
Roi = roi,
Volume = volume,
Fees = fees,
TradeWins = agentMetrics.Wins,
TradeLosses = agentMetrics.Losses,
Pnl = agentMetrics.TotalPnL, // Gross PnL before fees
NetPnL = agentMetrics.NetPnL, // Net PnL after fees
Roi = agentMetrics.TotalROI,
Volume = agentMetrics.TotalVolume,
Fees = agentMetrics.TotalFees,
LongPositionCount = longPositionCount,
ShortPositionCount = shortPositionCount
};