Skip to content

Add SwapExecutor with connector-level retry#142

Open
fengtality wants to merge 10 commits intomainfrom
feature/connector-level-retry
Open

Add SwapExecutor with connector-level retry#142
fengtality wants to merge 10 commits intomainfrom
feature/connector-level-retry

Conversation

@fengtality
Copy link
Copy Markdown
Contributor

@fengtality fengtality commented Mar 29, 2026

Summary

  • Add SwapExecutor support with proper event handling
  • Create GatewaySwap connector for router-type connectors (e.g., jupiter/router)
  • Ensure swap connector is loaded and OrdersRecorder subscribed before execution
  • Fix OrderFilledEvent timing to ensure trades are recorded in database
  • Update Gateway poll integration for simplified endpoint (Gateway PR #620)

Key Changes

  • services/unified_connector_service.py: Distinguish between GatewaySwap (router) and GatewayLp (clmm/amm) connectors
  • services/executor_service.py: Ensure swap connector is loaded via ensure_connector() before executor starts
  • services/gateway_client.py: Remove wallet_address param from poll_transaction
  • services/gateway_transaction_poller.py: Handle new txStatus=-1 and parsed error messages

Related PRs

QA Note: These 4 PRs should be tested together as a coordinated release.

Repo PR Description
hummingbot #8150 Move retry logic from executors to connectors
hummingbot-api #142 Add SwapExecutor with connector-level retry (this PR)
hummingbot-api-client #16 Add swap/lp executor client support
gateway #620 Fix fee calculation, add error parsing

Dependencies

Test plan

  • Verify swap_executor appears in /executors/types/available
  • Verify swap_executor can be created via POST /executors/
  • Verify swap completes with retry on pending transactions
  • Verify order is created in orders table
  • Verify trade fill is recorded in trades table
  • Test with Gateway PR #620 for proper error messages

🤖 Generated with Claude Code

fengtality and others added 7 commits March 11, 2026 19:42
- Register SwapExecutor in EXECUTOR_REGISTRY
- Add swap_executor to available executor types

Requires: hummingbot/hummingbot#8117

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tokens are available immediately after adding - no Gateway restart needed.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add get_bot_lp_history() method to BotsOrchestrator
- Add GET /{bot_name}/lphistory endpoint to bot_orchestration router
- Add "lphistory" to known MQTT command channels

Returns LP-specific data: position_address, order_action, fees collected,
price ranges, and amounts for AMM/CLMM strategies like Meteora.

Fixes #132

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add swap_executor to EXECUTOR_TYPES for single swaps via Gateway
- Add swap_executor example in CreateExecutorRequest
- Handle swap_executor using network instead of connector_name
- Make trading_pair optional for lp_executor (resolved from pool_address)
- Update lp_executor example with simplified config

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create GatewaySwap connector for router-type connectors (e.g., jupiter/router)
- Update executor_service to ensure swap connector is loaded before execution
- Add database access documentation for debugging executors

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains user-specific config and shouldn't be modified in the PR.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@fengtality fengtality force-pushed the feature/connector-level-retry branch from c1953f0 to 51f48de Compare March 29, 2026 04:04
- Remove wallet_address param from poll_transaction (Gateway PR #620)
- Handle new txStatus=-1 for failed transactions
- Use Gateway's parsed error messages (e.g., "SLIPPAGE_EXCEEDED (0x1771): ...")
- Fallback to meta.err if parsed error not available

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The executor_service validates that connector_name is required for swap_executor,
but the example in models/executors.py was missing it.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rapcmia rapcmia self-requested a review March 30, 2026 01:53
@rapcmia
Copy link
Copy Markdown
Contributor

rapcmia commented Mar 31, 2026

Commit 6aafc3b

  • Clone and build local whl and images for ✅
  • Update dockerfile and build docker image ✅
  • Start hummingbot-api and gateway ✅
  • Added solana wallet and setup helius (free ver) as nodeURL ✅
  • Verify if swap_executor exist in /executors/types/available
    curl -s -u admin:XXX http://localhost:8000/executors/types/available | jq '.executor_types[] | select(.type=="swap_executor")'
    {
      "type": "swap_executor",
      "description": "Single swap execution on Gateway AMM connectors",
      "use_case": "Executing swaps on DEXs like Jupiter with retry logic"
    }
    logs: not found related error on logs
    
  • Verify swap_executor can be created via POST /executors/
    • Tested swap_executor using jupiter/router but failed ❌
      curl -s -u admin:XXX -X POST http://localhost:8000/executors/ -H 'Content-Type: application/json' -d '
      {
        "account_name": "master_account",
        "executor_config": {
          "type": "swap_executor",
          "connector_name": "jupiter/router",
          "trading_pair": "SOL-USDC",
          "network": "solana-mainnet-beta",
          "side": 1,
          "amount": "0.035855"
        }
      }' | jq
      
      {
        "executor_id": "rEcgC9dS8673Xgic4WTo5d9aerhz9CGuZkJd8BNZDqx",
        "executor_type": "swap_executor",
        "connector_name": "jupiter/router",
        "trading_pair": "SOL-USDC",
        "status": "TERMINATED",
        "created_at": "2026-03-31T06:01:19.825662+00:00"
      }
      
      logs: 2026-03-31 06:01:19,826 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - ERROR - Connector 'jupiter/router' not found in Gateway. Available router connectors: []
      
      • Same response with side 2
      • logs returned 2026-03-31 06:01:19,826 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - ERROR - Connector 'jupiter/router' not found in Gateway. Available router connectors: []
  • I still tried to use amm or clmm type and got expected return ✅
    2026-03-31 06:09:24,665 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - ERROR - Executor requires /router connector type. 'clmm' is not supported.
    

Pending:

  • Verify swap_executor can be created via POST /executors/
  • Verify swap completes with retry on pending transactions
  • Verify order is created in orders table
  • Verify trade fill is recorded in trades table
  • Test with Gateway PR #620 for proper error messages

- Consolidate swap_executor and lp_executor validation into single block
- Network is optional - uses connector's defaultNetwork if not provided
- Executor handles connector normalization in on_start

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rapcmia
Copy link
Copy Markdown
Contributor

rapcmia commented Apr 1, 2026

PR update:

Tested swap_executor using jupiter/router but failed ❌

  • This is fixed ✅

Verify swap_executor can be created via POST /executors/ ✅

  • Buy and Sell swap_executor worked ok
  • Hummingbot-api logs display status of orders when swap_executor is used
    06:12:04.057 GET /
    INFO:     172.20.0.1:40358 - "GET / HTTP/1.1" 200 OK
    06:12:12.168 POST /gateway/swap/quote
    INFO:     172.20.0.1:49024 - "POST /gateway/swap/quote HTTP/1.1" 200 OK
    2026-04-01 06:12:19,282 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Executing swap: SELL 0.035855 SOL on jupiter/router
    06:12:19.280 POST /executors/
    INFO:     172.20.0.1:52096 - "POST /executors/ HTTP/1.1" 201 Created
    2026-04-01 06:12:19,459 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Swap order placed: sell-SOL-USDC-1775023939459564
    2026-04-01 06:12:23,723 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Order completed: sell-SOL-USDC-1775023939459564
    06:12:40.148 GET /executors/GNydLDkm9CYHbEFfyq3E3HLZEz6U1ZTEbwG3NYJsy5Qt
    

Verify swap completes with retry on pending transactions ✅

  • Set nodeURL to default and do multiple swaps
  • Found the behavior occurred on logs
    INFO:     172.20.0.1:52384 - "GET /executors/3TipJyiWvyrWvYhvsixPnutDxiov7uRoEzyC4g7amSNw HTTP/1.1" 200 OK
    2026-04-01 06:32:53,512 - GatewaySwap - WARNING - swap BUY 0.035855 on SOL-USDC transaction pending (retry 1/10). Signature: 3n8gUwPaqgt3EpG7WhNVeWRT3gZaHdeTz3Brdfyi7VTKQk4kcjk9r5wkQKyZuHoRH9Cn82jBt2CUdNE56YNqAEVS. Retrying...
    2026-04-01 06:33:10,192 - GatewaySwap - WARNING - swap BUY 0.035855 on SOL-USDC transaction pending (retry 2/10). Signature: 2m5AEfGaKEuFuLtkgPWk8DynyZpxZsDjtktiGKgtvGDrNQFhitQyom7MffcnqsgKLKMmBWtvnPki9DdfcyX7485D. Retrying...
    

Verify swap completes with retry on pending transactions ✅

  • Observed pending txns that are retried are completed
  • From hummingbot-api
      2026-04-01 06:32:36,452 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Executing swap: BUY 0.035855 SOL on jupiter/router
      2026-04-01 06:32:36,519 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Swap order placed: buy-SOL-USDC-1775025156519266
      2026-04-01 06:32:53,512 - GatewaySwap - WARNING - swap BUY 0.035855 on SOL-USDC transaction pending (retry 1/10). Signature: 3n8gUwPaqgt3EpG7WhNVeWRT3gZaHdeTz3Brdfyi7VTKQk4kcjk9r5wkQKyZuHoRH9Cn82jBt2CUdNE56YNqAEVS. Retrying...
      2026-04-01 06:33:10,192 - GatewaySwap - WARNING - swap BUY 0.035855 on SOL-USDC transaction pending (retry 2/10). Signature: 2m5AEfGaKEuFuLtkgPWk8DynyZpxZsDjtktiGKgtvGDrNQFhitQyom7MffcnqsgKLKMmBWtvnPki9DdfcyX7485D. Retrying...
      2026-04-01 06:33:13,783 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Order completed: buy-SOL-USDC-1775025156519266
    
  • From gateway
      2026-03-31 22:32:37 | info |  🚀 Sent transaction 3n8gUwPaqgt3EpG7WhNVeWRT3gZaHdeTz3Brdfyi7VTKQk4kcjk9r5wkQKyZuHoRH9Cn82jBt2CUdNE56YNqAEVS, polling for confirmation...
      2026-03-31 22:32:53 | warn |  ❌ Transaction 3n8gUwPaqgt3EpG7WhNVeWRT3gZaHdeTz3Brdfyi7VTKQk4kcjk9r5wkQKyZuHoRH9Cn82jBt2CUdNE56YNqAEVS not confirmed after 10 attempts
      2026-03-31 22:32:53 | warn |  Transaction 3n8gUwPaqgt3EpG7WhNVeWRT3gZaHdeTz3Brdfyi7VTKQk4kcjk9r5wkQKyZuHoRH9Cn82jBt2CUdNE56YNqAEVS pending. No transaction data available.
      2026-03-31 22:32:54 | info |  🚀 Sent transaction 2m5AEfGaKEuFuLtkgPWk8DynyZpxZsDjtktiGKgtvGDrNQFhitQyom7MffcnqsgKLKMmBWtvnPki9DdfcyX7485D, polling for confirmation...
      2026-03-31 22:33:10 | warn |  ❌ Transaction 2m5AEfGaKEuFuLtkgPWk8DynyZpxZsDjtktiGKgtvGDrNQFhitQyom7MffcnqsgKLKMmBWtvnPki9DdfcyX7485D not confirmed after 10 attempts
      2026-03-31 22:33:10 | warn |  Transaction 2m5AEfGaKEuFuLtkgPWk8DynyZpxZsDjtktiGKgtvGDrNQFhitQyom7MffcnqsgKLKMmBWtvnPki9DdfcyX7485D pending. No transaction data available.
      2026-03-31 22:33:11 | info |  🚀 Sent transaction 2WpTP7kQbSXp1GMDdgfnRKoKLXM26H8X4D9NjSfoZRhyT27yTRwLmVgWe8g1Ezto5s1TtWdrvP1yWLjfdJ9BAgw9, polling for confirmation...
      2026-03-31 22:33:13 | info |  ✅ Transaction 2WpTP7kQbSXp1GMDdgfnRKoKLXM26H8X4D9NjSfoZRhyT27yTRwLmVgWe8g1Ezto5s1TtWdrvP1yWLjfdJ9BAgw9 confirmed after 2 attempts
      2026-03-31 22:33:13 | info |  Swap executed successfully: 3.0283 USDC -> 0.0358 SOL
    

Verify order is created in orders table ❌

  • I found that the order that was under retry on pending txn tests is still on open status on DB orde table, see buy-SOL-USDC-1775025156519266
    image
    INFO:     172.20.0.1:47992 - "GET /executors/28W6EDb33NgzAQw7vZLvewRFBNWfGMaY8R6j8nATxQ59 HTTP/1.1" 200 OK
    06:32:36.279 POST /gateway/swap/quote
    INFO:     172.20.0.1:52946 - "POST /gateway/swap/quote HTTP/1.1" 200 OK
    2026-04-01 06:32:36,452 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Executing swap: BUY 0.035855 SOL on jupiter/router
    06:32:36.451 POST /executors/
    INFO:     172.20.0.1:52958 - "POST /executors/ HTTP/1.1" 201 Created
    2026-04-01 06:32:36,519 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Swap order placed: buy-SOL-USDC-1775025156519266
    06:32:41.472 GET /executors/3TipJyiWvyrWvYhvsixPnutDxiov7uRoEzyC4g7amSNw
    INFO:     172.20.0.1:44520 - "GET /executors/3TipJyiWvyrWvYhvsixPnutDxiov7uRoEzyC4g7amSNw HTTP/1.1" 200 OK
    06:32:50.982 GET /executors/3TipJyiWvyrWvYhvsixPnutDxiov7uRoEzyC4g7amSNw
    INFO:     172.20.0.1:52384 - "GET /executors/3TipJyiWvyrWvYhvsixPnutDxiov7uRoEzyC4g7amSNw HTTP/1.1" 200 OK
    2026-04-01 06:32:53,512 - GatewaySwap - WARNING - swap BUY 0.035855 on SOL-USDC transaction pending (retry 1/10). Signature: 3n8gUwPaqgt3EpG7WhNVeWRT3gZaHdeTz3Brdfyi7VTKQk4kcjk9r5wkQKyZuHoRH9Cn82jBt2CUdNE56YNqAEVS. Retrying...
    2026-04-01 06:33:10,192 - GatewaySwap - WARNING - swap BUY 0.035855 on SOL-USDC transaction pending (retry 2/10). Signature: 2m5AEfGaKEuFuLtkgPWk8DynyZpxZsDjtktiGKgtvGDrNQFhitQyom7MffcnqsgKLKMmBWtvnPki9DdfcyX7485D. Retrying...
    2026-04-01 06:33:13,783 - hummingbot.strategy_v2.executors.swap_executor.swap_executor - INFO - Order completed: buy-SOL-USDC-1775025156519266
    06:33:19.249 GET /executors/3TipJyiWvyrWvYhvsixPnutDxiov7uRoEzyC4g7amSNw
    INFO:     172.20.0.1:60300 - "GET /executors/3TipJyiWvyrWvYhvsixPnutDxiov7uRoEzyC4g7amSNw HTTP/1.1" 200 OK
    
    • I tried to retest this time i found a two instances but the buy order got completed while having the retry and the sell did not make it and stuck on open status
      image
      • ❗ Steps to reproduce:
        • Change nodeURL of solana-mainnet-beta to default and run multiple swaps then check order table on DB

Verify order is created in orders table ✅

  • All orders that are completed on testing are listed (11 orders)
  • Observed that the two orders previously noted as OPEN in orders table are also present ❗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants