Fix position gas fee
This commit is contained in:
@@ -427,11 +427,12 @@ public class TradingBotBase : ITradingBot
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!internalPosition.Status.Equals(PositionStatus.New))
|
||||
// No position on the broker, the position have been closed by the exchange
|
||||
if (internalPosition.Status.Equals(PositionStatus.Filled))
|
||||
{
|
||||
internalPosition.Status = PositionStatus.Filled;
|
||||
internalPosition.Status = PositionStatus.Finished;
|
||||
|
||||
// Update Open trade status when position becomes Filled
|
||||
// Update Open trade status when position becomes Finished
|
||||
if (internalPosition.Open != null)
|
||||
{
|
||||
internalPosition.Open.SetStatus(TradeStatus.Filled);
|
||||
|
||||
@@ -46,16 +46,24 @@ namespace Managing.Application.Trading.Handlers
|
||||
|
||||
// Gas fee check for EVM exchanges
|
||||
decimal gasFeeUsd = 0;
|
||||
if (account.Exchange == TradingExchanges.Evm || account.Exchange == TradingExchanges.GmxV2)
|
||||
if (!request.IsForPaperTrading)
|
||||
{
|
||||
gasFeeUsd = await exchangeService.GetFee(account);
|
||||
if (gasFeeUsd > Constants.GMX.Config.MaximumGasFeeUsd)
|
||||
if (account.Exchange == TradingExchanges.Evm || account.Exchange == TradingExchanges.GmxV2)
|
||||
{
|
||||
throw new InsufficientFundsException(
|
||||
$"Gas fee too high for position opening: {gasFeeUsd:F2} USD (threshold: {Constants.GMX.Config.MaximumGasFeeUsd} USD). Position opening cancelled.",
|
||||
InsufficientFundsType.InsufficientEth);
|
||||
gasFeeUsd = await exchangeService.GetFee(account);
|
||||
if (gasFeeUsd > 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.",
|
||||
InsufficientFundsType.InsufficientEth);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gasFeeUsd = Constants.GMX.Config.GasFeePerTransaction;
|
||||
}
|
||||
|
||||
|
||||
var price = request.IsForPaperTrading && request.Price.HasValue
|
||||
? request.Price.Value
|
||||
@@ -87,7 +95,7 @@ namespace Managing.Application.Trading.Handlers
|
||||
|
||||
// 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)
|
||||
{
|
||||
@@ -97,7 +105,7 @@ namespace Managing.Application.Trading.Handlers
|
||||
{
|
||||
position.GasFees = TradingHelpers.CalculateOpeningGasFees();
|
||||
}
|
||||
|
||||
|
||||
// Set UI fees for opening
|
||||
position.UiFees = TradingHelpers.CalculateOpeningUiFees(positionSizeUsd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user