Enhance SpotBot slippage handling and logging

- Increased slippage tolerance from 0.6% to 0.7% to account for gas reserves.
- Improved logging to provide detailed information when adjusting position quantities due to slippage or when retaining original quantities.
- Updated CloseSpotPositionCommandHandler to use the position's opened quantity instead of the entire wallet balance, ensuring gas fees are preserved.
- Adjusted Web3ProxyService settings for retry attempts and operation timeouts to improve performance.
- Enhanced swap token implementation to handle native tokens correctly and increased operation timeout for better reliability.
This commit is contained in:
2026-01-05 22:13:18 +07:00
parent a0d5e336d5
commit 645bbe6d95
5 changed files with 106 additions and 55 deletions

View File

@@ -48,18 +48,13 @@ public class CloseSpotPositionCommandHandler(
{
// For live trading, call SwapGmxTokensAsync
var account = await accountService.GetAccountById(request.AccountId);
var tokenBalance = await exchangeService.GetBalance(account, request.Position.Ticker);
if (tokenBalance == null || tokenBalance.Amount <= 0)
{
throw new InvalidOperationException(
$"No available balance to close spot position for {request.Position.Ticker}");
}
amountToSwap = tokenBalance.Amount;
// Use the position's opened quantity instead of the entire wallet balance
// This naturally leaves extra ETH for gas fees and avoids the need for explicit reservation
amountToSwap = request.Position.Open.Quantity;
logger?.LogInformation(
"Closing spot position: PositionId={PositionId}, Ticker={Ticker}, TokenBalance={TokenBalance}, Swapping to USDC",
"Closing spot position: PositionId={PositionId}, Ticker={Ticker}, PositionQuantity={PositionQuantity}, Swapping to USDC",
request.Position.Identifier, request.Position.Ticker, amountToSwap);
swapResult = await tradingService.SwapGmxTokensAsync(