Add agent fees
This commit is contained in:
@@ -45,25 +45,19 @@ namespace Managing.Application.Trading.Handlers
|
||||
}
|
||||
|
||||
// Gas fee check for EVM exchanges
|
||||
decimal gasFeeUsd = 0;
|
||||
if (!request.IsForPaperTrading)
|
||||
{
|
||||
if (account.Exchange == TradingExchanges.Evm || account.Exchange == TradingExchanges.GmxV2)
|
||||
{
|
||||
gasFeeUsd = await exchangeService.GetFee(account);
|
||||
if (gasFeeUsd > Constants.GMX.Config.MaximumGasFeeUsd)
|
||||
var currentGasFees = await exchangeService.GetFee(account);
|
||||
if (currentGasFees > Constants.GMX.Config.MaximumGasFeeUsd)
|
||||
{
|
||||
throw new InsufficientFundsException(
|
||||
$"Gas fee too high for position opening: {gasFeeUsd:F2} USD (threshold: {Constants.GMX.Config.MaximumGasFeeUsd} USD). Position opening cancelled.",
|
||||
$"Gas fee too high for position opening: {currentGasFees:F2} USD (threshold: {Constants.GMX.Config.MaximumGasFeeUsd} USD). Position opening cancelled.",
|
||||
InsufficientFundsType.InsufficientEth);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gasFeeUsd = Constants.GMX.Config.GasFeePerTransaction;
|
||||
}
|
||||
|
||||
|
||||
var price = request.IsForPaperTrading && request.Price.HasValue
|
||||
? request.Price.Value
|
||||
@@ -94,19 +88,11 @@ namespace Managing.Application.Trading.Handlers
|
||||
position.Open = trade;
|
||||
|
||||
// Calculate and set fees for the position
|
||||
var positionSizeUsd = (position.Open.Price * position.Open.Quantity) * position.Open.Leverage;
|
||||
|
||||
// Set gas fees (only for EVM exchanges)
|
||||
if (account.Exchange == TradingExchanges.Evm || account.Exchange == TradingExchanges.GmxV2)
|
||||
{
|
||||
position.GasFees = gasFeeUsd;
|
||||
}
|
||||
else
|
||||
{
|
||||
position.GasFees = TradingHelpers.CalculateOpeningGasFees();
|
||||
}
|
||||
position.GasFees = TradingHelpers.CalculateOpeningGasFees();
|
||||
|
||||
// Set UI fees for opening
|
||||
var positionSizeUsd = TradingHelpers.GetVolumeForPosition(position);
|
||||
position.UiFees = TradingHelpers.CalculateOpeningUiFees(positionSizeUsd);
|
||||
|
||||
var closeDirection = request.Direction == TradeDirection.Long
|
||||
|
||||
Reference in New Issue
Block a user