Refactor ETH balance and gas fee checks in SpotBot
- Updated balance checks to utilize user-defined thresholds for minimum trading and swap balances, enhancing flexibility. - Improved gas fee validation by incorporating user settings, allowing for more personalized transaction management. - Enhanced logging to provide clearer messages regarding balance sufficiency and gas fee limits, improving user feedback during operations.
This commit is contained in:
@@ -51,10 +51,13 @@ namespace Managing.Application.Trading.Handlers
|
||||
if (account.Exchange == TradingExchanges.Evm || account.Exchange == TradingExchanges.GmxV2)
|
||||
{
|
||||
var currentGasFees = await exchangeService.GetFee(account);
|
||||
if (currentGasFees > Constants.GMX.Config.MaximumGasFeeUsd)
|
||||
// Use user's max gas fee setting, fallback to default constant
|
||||
var maxGasFeeThreshold = request.User.MaxTxnGasFeePerPosition ?? Constants.GMX.Config.MaximumGasFeeUsd;
|
||||
|
||||
if (currentGasFees > maxGasFeeThreshold)
|
||||
{
|
||||
throw new InsufficientFundsException(
|
||||
$"Gas fee too high for position opening: {currentGasFees:F2} USD (threshold: {Constants.GMX.Config.MaximumGasFeeUsd} USD). Position opening rejected.",
|
||||
$"Gas fee too high for position opening: {currentGasFees:F2} USD (threshold: {maxGasFeeThreshold:F2} USD). Position opening rejected.",
|
||||
InsufficientFundsType.HighNetworkFee);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user