Skip to content

Commit 28b15ca

Browse files
fengtalityclaude
andcommitted
Add swap_executor type and improve executor handling
- 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>
1 parent 02ef8ea commit 28b15ca

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

models/executors.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ class PositionsSummaryResponse(BaseModel):
211211
"twap_executor",
212212
"xemm_executor",
213213
"order_executor",
214-
"lp_executor"
214+
"lp_executor",
215+
"swap_executor"
215216
]
216217

217218

@@ -246,14 +247,14 @@ class CreateExecutorRequest(BaseModel):
246247
},
247248
{
248249
"summary": "LP Executor",
249-
"description": "Create an LP position on a CLMM DEX (Meteora, Raydium)",
250+
"description": "Create an LP position on a CLMM DEX",
250251
"value": {
251252
"account_name": "master_account",
252253
"executor_config": {
253254
"type": "lp_executor",
254-
"connector_name": "meteora/clmm",
255-
"trading_pair": "SOL-USDC",
255+
"connector_name": "meteora",
256256
"pool_address": "HTvjzsfX3yU6BUodCjZ5vZkUrAxMDTrBs3CJaq43ashR",
257+
"network": "solana-mainnet-beta",
257258
"lower_price": "80",
258259
"upper_price": "100",
259260
"base_amount": "0",
@@ -265,6 +266,22 @@ class CreateExecutorRequest(BaseModel):
265266
"keep_position": False
266267
}
267268
}
269+
},
270+
{
271+
"summary": "Swap Executor",
272+
"description": "Execute a single swap on Gateway AMM connectors (Jupiter, Raydium, etc.)",
273+
"value": {
274+
"account_name": "master_account",
275+
"executor_config": {
276+
"type": "swap_executor",
277+
"network": "solana-mainnet-beta",
278+
"trading_pair": "SOL-USDC",
279+
"side": 2,
280+
"amount": "0.1",
281+
"slippage_pct": "0.5",
282+
"swap_providers": ["jupiter/router", "meteora/clmm", "orca/clmm"]
283+
}
284+
}
268285
}
269286
]
270287
}

services/executor_service.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,38 @@ async def create_executor(
349349
trading_interface = self._get_trading_interface(account)
350350

351351
# Extract connector and trading pair from config
352+
# Note: swap_executor uses 'network' instead of 'connector_name' since it calls Gateway directly
352353
connector_name = executor_config.get("connector_name")
353354
trading_pair = executor_config.get("trading_pair")
354-
if not connector_name:
355-
raise HTTPException(status_code=400, detail="connector_name is required in executor_config")
356-
if not trading_pair:
357-
raise HTTPException(status_code=400, detail="trading_pair is required in executor_config")
358355

359-
# Ensure connector and market are ready
360-
await trading_interface.add_market(connector_name, trading_pair)
356+
if executor_type == "swap_executor":
357+
# SwapExecutor uses network, not connector_name
358+
network = executor_config.get("network")
359+
if not network:
360+
raise HTTPException(status_code=400, detail="network is required for swap_executor")
361+
if not trading_pair:
362+
raise HTTPException(status_code=400, detail="trading_pair is required in executor_config")
363+
# Use network as connector_name for metadata tracking
364+
connector_name = network
365+
elif executor_type == "lp_executor":
366+
# LPExecutor: trading_pair is optional (resolved from pool_address)
367+
if not connector_name:
368+
raise HTTPException(status_code=400, detail="connector_name is required for lp_executor")
369+
pool_address = executor_config.get("pool_address")
370+
if not pool_address:
371+
raise HTTPException(status_code=400, detail="pool_address is required for lp_executor")
372+
# Ensure connector is ready (trading_pair resolved in executor on_start)
373+
await trading_interface.ensure_connector(connector_name)
374+
# Use pool_address as trading_pair placeholder for metadata if not provided
375+
if not trading_pair:
376+
trading_pair = pool_address
377+
else:
378+
if not connector_name:
379+
raise HTTPException(status_code=400, detail="connector_name is required in executor_config")
380+
if not trading_pair:
381+
raise HTTPException(status_code=400, detail="trading_pair is required in executor_config")
382+
# Ensure connector and market are ready
383+
await trading_interface.add_market(connector_name, trading_pair)
361384

362385
# Set timestamp if not provided (required for time-based features like time_limit)
363386
if "timestamp" not in executor_config or executor_config["timestamp"] is None:

0 commit comments

Comments
 (0)