Fix agent volume
This commit is contained in:
@@ -9,6 +9,7 @@ using Managing.Common;
|
|||||||
using Managing.Core;
|
using Managing.Core;
|
||||||
using Managing.Core.Exceptions;
|
using Managing.Core.Exceptions;
|
||||||
using Managing.Domain.Bots;
|
using Managing.Domain.Bots;
|
||||||
|
using Managing.Domain.Shared.Helpers;
|
||||||
using Managing.Domain.Statistics;
|
using Managing.Domain.Statistics;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -174,7 +175,7 @@ public class AgentGrain : Grain, IAgentGrain
|
|||||||
|
|
||||||
// Calculate aggregated statistics from position data
|
// Calculate aggregated statistics from position data
|
||||||
var totalPnL = positions.Sum(p => p.ProfitAndLoss?.Realized ?? 0);
|
var totalPnL = positions.Sum(p => p.ProfitAndLoss?.Realized ?? 0);
|
||||||
var totalVolume = positions.Sum(p => p.Open.Price * p.Open.Quantity * p.Open.Leverage);
|
var totalVolume = TradingBox.GetTotalVolumeTraded(positions);
|
||||||
var collateral = positions.Sum(p => p.Open.Price * p.Open.Quantity);
|
var collateral = positions.Sum(p => p.Open.Price * p.Open.Quantity);
|
||||||
var totalFees = positions.Sum(p => p.CalculateTotalFees());
|
var totalFees = positions.Sum(p => p.CalculateTotalFees());
|
||||||
|
|
||||||
|
|||||||
@@ -461,22 +461,24 @@ public static class TradingBox
|
|||||||
foreach (var position in positions)
|
foreach (var position in positions)
|
||||||
{
|
{
|
||||||
// Add entry volume
|
// Add entry volume
|
||||||
totalVolume += position.Open.Quantity * position.Open.Price;
|
totalVolume += position.Open.Quantity * position.Open.Price * position.Open.Leverage;
|
||||||
|
|
||||||
// Add exit volumes from stop loss or take profits if they were executed
|
// Add exit volumes from stop loss or take profits if they were executed
|
||||||
if (position.StopLoss.Status == TradeStatus.Filled)
|
if (position.StopLoss.Status == TradeStatus.Filled)
|
||||||
{
|
{
|
||||||
totalVolume += position.StopLoss.Quantity * position.StopLoss.Price;
|
totalVolume += position.StopLoss.Quantity * position.StopLoss.Price * position.StopLoss.Leverage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position.TakeProfit1.Status == TradeStatus.Filled)
|
if (position.TakeProfit1.Status == TradeStatus.Filled)
|
||||||
{
|
{
|
||||||
totalVolume += position.TakeProfit1.Quantity * position.TakeProfit1.Price;
|
totalVolume += position.TakeProfit1.Quantity * position.TakeProfit1.Price *
|
||||||
|
position.TakeProfit1.Leverage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position.TakeProfit2 != null && position.TakeProfit2.Status == TradeStatus.Filled)
|
if (position.TakeProfit2 != null && position.TakeProfit2.Status == TradeStatus.Filled)
|
||||||
{
|
{
|
||||||
totalVolume += position.TakeProfit2.Quantity * position.TakeProfit2.Price;
|
totalVolume += position.TakeProfit2.Quantity * position.TakeProfit2.Price *
|
||||||
|
position.TakeProfit2.Leverage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,10 +99,17 @@ function AgentSearch({ index }: { index: number }) {
|
|||||||
? agentData.strategies.reduce((sum, strategy) => sum + (strategy.winRate || 0), 0) / agentData.strategies.length
|
? agentData.strategies.reduce((sum, strategy) => sum + (strategy.winRate || 0), 0) / agentData.strategies.length
|
||||||
: 0
|
: 0
|
||||||
|
|
||||||
|
// Calculate total collateral from all positions (quantity * price)
|
||||||
|
const totalCollateral = agentData.positions.reduce((sum, position) => {
|
||||||
|
const collateral = (position.Open?.quantity || 0) * (position.Open?.price || 0)
|
||||||
|
return sum + collateral
|
||||||
|
}, 0)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
totalPnL,
|
totalPnL,
|
||||||
totalNetPnL,
|
totalNetPnL,
|
||||||
totalVolume,
|
totalVolume,
|
||||||
|
totalCollateral,
|
||||||
totalWins,
|
totalWins,
|
||||||
totalLosses,
|
totalLosses,
|
||||||
avgWinRate,
|
avgWinRate,
|
||||||
@@ -460,7 +467,7 @@ function AgentSearch({ index }: { index: number }) {
|
|||||||
<div className="stat-title text-xs">ROI</div>
|
<div className="stat-title text-xs">ROI</div>
|
||||||
<div className="stat-value text-lg">
|
<div className="stat-value text-lg">
|
||||||
<span className={summary.totalNetPnL >= 0 ? 'text-green-500' : 'text-red-500'}>
|
<span className={summary.totalNetPnL >= 0 ? 'text-green-500' : 'text-red-500'}>
|
||||||
{((summary.totalNetPnL / (summary.totalVolume || 1)) * 100).toFixed(2)}%
|
{((summary.totalNetPnL / (summary.totalCollateral || 1)) * 100).toFixed(2)}%
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="stat-desc text-xs">Return on Investment</div>
|
<div className="stat-desc text-xs">Return on Investment</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user