Refacto
This commit is contained in:
@@ -3,7 +3,7 @@ using Managing.Application.Abstractions.Grains;
|
|||||||
using Managing.Application.Abstractions.Services;
|
using Managing.Application.Abstractions.Services;
|
||||||
using Managing.Application.Orleans;
|
using Managing.Application.Orleans;
|
||||||
using Managing.Domain.Candles;
|
using Managing.Domain.Candles;
|
||||||
using Managing.Domain.Trades;
|
using Managing.Domain.Shared.Helpers;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using static Managing.Common.Enums;
|
using static Managing.Common.Enums;
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable
|
|||||||
foreach (var position in positions)
|
foreach (var position in positions)
|
||||||
{
|
{
|
||||||
// Calculate volume using the dedicated method
|
// Calculate volume using the dedicated method
|
||||||
var positionVolume = GetVolumeForPosition(position);
|
var positionVolume = TradingHelpers.GetVolumeForPosition(position);
|
||||||
totalVolume += positionVolume;
|
totalVolume += positionVolume;
|
||||||
|
|
||||||
// Add to open interest for active positions only
|
// 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
|
// Event handlers for immediate updates
|
||||||
public async Task UpdateActiveStrategyCountAsync(int newActiveCount)
|
public async Task UpdateActiveStrategyCountAsync(int newActiveCount)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -189,4 +189,39 @@ public static class TradingHelpers
|
|||||||
{
|
{
|
||||||
return Constants.GMX.Config.GasFeePerTransaction;
|
return Constants.GMX.Config.GasFeePerTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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>
|
||||||
|
public static 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user