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:
2026-01-06 00:43:51 +07:00
parent efbb116ed2
commit 5e7b2b34d4
10 changed files with 1264 additions and 72 deletions

View File

@@ -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);
}
}