Refacto
This commit is contained in:
@@ -189,4 +189,39 @@ public static class TradingHelpers
|
||||
{
|
||||
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