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:
@@ -410,7 +410,9 @@ public class AgentGrain : Grain, IAgentGrain
|
||||
}
|
||||
|
||||
// If ETH balance is sufficient, return success
|
||||
if (balanceData.EthValueInUsd >= Constants.GMX.Config.MinimumTradeEthBalanceUsd)
|
||||
// Use user's low ETH alert threshold as the minimum trading balance
|
||||
var minTradeEthBalance = user.LowEthAmountAlert ?? Constants.GMX.Config.MinimumTradeEthBalanceUsd;
|
||||
if (balanceData.EthValueInUsd >= minTradeEthBalance)
|
||||
{
|
||||
return new BalanceCheckResult
|
||||
{
|
||||
@@ -421,13 +423,15 @@ public class AgentGrain : Grain, IAgentGrain
|
||||
};
|
||||
}
|
||||
|
||||
if (balanceData.EthValueInUsd < Constants.GMX.Config.MinimumSwapEthBalanceUsd)
|
||||
// Check if ETH is below absolute minimum (half of the alert threshold)
|
||||
var minSwapEthBalance = minTradeEthBalance * 0.67m; // 67% of alert threshold
|
||||
if (balanceData.EthValueInUsd < minSwapEthBalance)
|
||||
{
|
||||
return new BalanceCheckResult
|
||||
{
|
||||
IsSuccessful = false,
|
||||
FailureReason = BalanceCheckFailureReason.InsufficientEthBelowMinimum,
|
||||
Message = "ETH balance below minimum required amount",
|
||||
Message = $"ETH balance below minimum required amount ({minSwapEthBalance:F2} USD)",
|
||||
ShouldStopBot = true
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user