Fix win and loses count
This commit is contained in:
@@ -475,14 +475,15 @@ public class DataController : ControllerBase
|
|||||||
decimal totalVolume = strategy.Volume;
|
decimal totalVolume = strategy.Volume;
|
||||||
decimal volumeLast24h = strategy.Volume;
|
decimal volumeLast24h = strategy.Volume;
|
||||||
|
|
||||||
// Calculate win/loss statistics
|
|
||||||
(int wins, int losses) = (strategy.TradeWins, strategy.TradeLosses);
|
|
||||||
|
|
||||||
int winRate = wins + losses > 0 ? (wins * 100) / (wins + losses) : 0;
|
|
||||||
|
|
||||||
// Fetch positions associated with this bot using the provided trading service
|
// Fetch positions associated with this bot using the provided trading service
|
||||||
var positions = await tradingService.GetPositionsByInitiatorIdentifierAsync(strategy.Identifier);
|
var positions = await tradingService.GetPositionsByInitiatorIdentifierAsync(strategy.Identifier);
|
||||||
|
|
||||||
|
// Calculate win/loss statistics from actual positions (including open positions)
|
||||||
|
int wins = positions.Count(p => p.ProfitAndLoss != null && p.ProfitAndLoss.Realized > 0);
|
||||||
|
int losses = positions.Count(p => p.ProfitAndLoss != null && p.ProfitAndLoss.Realized <= 0);
|
||||||
|
|
||||||
|
int winRate = wins + losses > 0 ? (wins * 100) / (wins + losses) : 0;
|
||||||
|
|
||||||
// Convert positions to view models
|
// Convert positions to view models
|
||||||
var positionViewModels = positions.Select(MapPositionToViewModel).ToList();
|
var positionViewModels = positions.Select(MapPositionToViewModel).ToList();
|
||||||
|
|
||||||
|
|||||||
@@ -526,6 +526,7 @@ public static class TradingBox
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the win/loss counts from positions
|
/// Gets the win/loss counts from positions
|
||||||
|
/// Counts all positions including open ones based on their current PnL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="positions">List of positions to analyze</param>
|
/// <param name="positions">List of positions to analyze</param>
|
||||||
/// <returns>A tuple containing (wins, losses)</returns>
|
/// <returns>A tuple containing (wins, losses)</returns>
|
||||||
@@ -540,7 +541,7 @@ public static class TradingBox
|
|||||||
{
|
{
|
||||||
wins++;
|
wins++;
|
||||||
}
|
}
|
||||||
else
|
else if (position.ProfitAndLoss != null && position.ProfitAndLoss.Realized <= 0)
|
||||||
{
|
{
|
||||||
losses++;
|
losses++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ public class PostgreSqlBotRepository : IBotRepository
|
|||||||
? query.OrderBy(b => b.Pnl)
|
? query.OrderBy(b => b.Pnl)
|
||||||
: query.OrderByDescending(b => b.Pnl),
|
: query.OrderByDescending(b => b.Pnl),
|
||||||
"winrate" => sortDirection.ToLower() == "asc"
|
"winrate" => sortDirection.ToLower() == "asc"
|
||||||
? query.OrderBy(b => b.TradeWins / (b.TradeWins + b.TradeLosses))
|
? query.OrderBy(b => (b.TradeWins + b.TradeLosses) > 0 ? (double)b.TradeWins / (b.TradeWins + b.TradeLosses) : 0)
|
||||||
: query.OrderByDescending(b => b.TradeWins / (b.TradeWins + b.TradeLosses)),
|
: query.OrderByDescending(b => (b.TradeWins + b.TradeLosses) > 0 ? (double)b.TradeWins / (b.TradeWins + b.TradeLosses) : 0),
|
||||||
"agentname" => sortDirection.ToLower() == "asc"
|
"agentname" => sortDirection.ToLower() == "asc"
|
||||||
? query.OrderBy(b => b.User.AgentName)
|
? query.OrderBy(b => b.User.AgentName)
|
||||||
: query.OrderByDescending(b => b.User.AgentName),
|
: query.OrderByDescending(b => b.User.AgentName),
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ function AgentSearch({ index }: { index: number }) {
|
|||||||
const calculateSummary = () => {
|
const calculateSummary = () => {
|
||||||
if (!agentData?.strategies.length) return null
|
if (!agentData?.strategies.length) return null
|
||||||
|
|
||||||
|
console.log(agentData.strategies)
|
||||||
const totalPnL = agentData.strategies.reduce((sum, strategy) => sum + (strategy.pnL || 0), 0)
|
const totalPnL = agentData.strategies.reduce((sum, strategy) => sum + (strategy.pnL || 0), 0)
|
||||||
const totalNetPnL = agentData.strategies.reduce((sum, strategy) => sum + (strategy.netPnL || 0), 0)
|
const totalNetPnL = agentData.strategies.reduce((sum, strategy) => sum + (strategy.netPnL || 0), 0)
|
||||||
const totalVolume = agentData.strategies.reduce((sum, strategy) => sum + (strategy.totalVolumeTraded || 0), 0)
|
const totalVolume = agentData.strategies.reduce((sum, strategy) => sum + (strategy.totalVolumeTraded || 0), 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user