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