Refine SpotBot token balance handling and logging
- Adjusted max dust amount threshold based on token type: increased for ETH to account for gas reserves, while maintaining a lower threshold for other tokens. - Enhanced logging to clarify when a position is closed, indicating if the remaining balance is expected for gas reserves or if it was successfully closed.
This commit is contained in:
@@ -1149,8 +1149,12 @@ public class SpotBot : TradingBotBase
|
||||
_scopeFactory,
|
||||
async exchangeService => await exchangeService.GetBalance(Account, Config.Ticker));
|
||||
|
||||
// Token balance should be zero or very small (dust) after closing
|
||||
var maxDustAmount = 0.0001m; // Consider amounts less than this as cleared
|
||||
// For ETH, remaining balance is expected (gas reserve) - use higher threshold
|
||||
// For other tokens, very small dust amounts are acceptable
|
||||
var maxDustAmount = Config.Ticker == Ticker.ETH
|
||||
? 0.01m // ETH: up to 0.01 ETH is acceptable (gas reserve)
|
||||
: 0.0001m; // Other tokens: only dust amounts acceptable
|
||||
|
||||
if (tokenBalance is { Amount: > 0 } && tokenBalance.Amount > maxDustAmount)
|
||||
{
|
||||
await LogWarningAsync(
|
||||
@@ -1171,7 +1175,7 @@ public class SpotBot : TradingBotBase
|
||||
$"Position: `{closedPosition.Identifier}`\n" +
|
||||
$"Ticker: {Config.Ticker}\n" +
|
||||
$"Token Balance: `{tokenBalance?.Amount ?? 0:F5}`\n" +
|
||||
$"Position successfully closed on exchange");
|
||||
$"{(Config.Ticker == Ticker.ETH && tokenBalance?.Amount > 0 ? "(Gas reserve - expected)" : "Position successfully closed on exchange")}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user