This commit is contained in:
2025-09-28 19:34:06 +07:00
parent fdb56dbb08
commit fd2387932e
2 changed files with 37 additions and 37 deletions

View File

@@ -3,7 +3,7 @@ using Managing.Application.Abstractions.Grains;
using Managing.Application.Abstractions.Services;
using Managing.Application.Orleans;
using Managing.Domain.Candles;
using Managing.Domain.Trades;
using Managing.Domain.Shared.Helpers;
using Microsoft.Extensions.Logging;
using static Managing.Common.Enums;
@@ -117,7 +117,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
foreach (var position in positions)
{
// Calculate volume using the dedicated method
var positionVolume = GetVolumeForPosition(position);
var positionVolume = TradingHelpers.GetVolumeForPosition(position);
totalVolume += positionVolume;
// Add to open interest for active positions only
@@ -184,41 +184,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
}
}
/// <summary>
/// Calculates the total volume for a position based on its status and filled trades
/// </summary>
/// <param name="position">The position to calculate volume for</param>
/// <returns>The total volume for the position</returns>
private decimal GetVolumeForPosition(Position position)
{
// Always include the opening trade volume
var totalVolume = position.Open.Price * position.Open.Quantity * position.Open.Leverage;
// For closed positions, add volume from filled closing trades
if (position.IsFinished())
{
// Add Stop Loss volume if filled
if (position.StopLoss?.Status == TradeStatus.Filled)
{
totalVolume += position.StopLoss.Price * position.StopLoss.Quantity * position.StopLoss.Leverage;
}
// Add Take Profit 1 volume if filled
if (position.TakeProfit1?.Status == TradeStatus.Filled)
{
totalVolume += position.TakeProfit1.Price * position.TakeProfit1.Quantity * position.TakeProfit1.Leverage;
}
// Add Take Profit 2 volume if filled
if (position.TakeProfit2?.Status == TradeStatus.Filled)
{
totalVolume += position.TakeProfit2.Price * position.TakeProfit2.Quantity * position.TakeProfit2.Leverage;
}
}
return totalVolume;
}
// Event handlers for immediate updates
public async Task UpdateActiveStrategyCountAsync(int newActiveCount)
{