Best Execution

Smart Order Routing API
for AI Agents

Every basis point matters when agents trade thousands of times per month. Smart order routing finds the best available price across all connected venues and splits large orders to minimize market impact โ€” automatically, on every single trade.

Get Best Execution โ†’ View Docs

What Smart Order Routing Does

Three steps, executed in parallel, in under 100 milliseconds. Your agent sends one intent and receives one fill โ€” the routing complexity is invisible.

1
Query all connected venues for the best available price

The router simultaneously queries liquidity from Uniswap V3, Curve, Balancer, Hyperliquid, and 6+ additional venues. Price quotes are fetched in parallel and normalized to a common denomination. The router accounts for gas costs, bridge fees, and liquidity depth โ€” not just the headline price โ€” so the "best" route is truly best after all costs.

2
Calculate optimal split to minimize slippage

For orders large enough to move any single venue's price, the router calculates the optimal split across multiple liquidity pools. It models the price-impact function for each venue and finds the mathematically optimal allocation that minimizes total slippage across the full order โ€” a convex optimization solved in microseconds using precomputed liquidity curves.

3
Execute in parallel, aggregate fills

Sub-orders are broadcast to all target venues simultaneously. Partial fills are monitored in real time, and if a venue's price moves before execution the router can re-route the remaining amount. You receive a single aggregated fill report with effective price, total slippage, fees paid per venue, and the estimated savings compared to naive single-venue execution.

Python Example

Two methods: find_best_route() to preview and execute_route() to fill. Always preview before executing to confirm the route meets your slippage tolerance.

import purpleflea

router = purpleflea.RouterClient(api_key="YOUR_KEY")

# Route a $10,000 ETH buy across best venues
route = router.find_best_route(
    from_token="USDC",
    to_token="ETH",
    amount=10000,
    max_slippage_bps=30   # 0.3% max slippage
)

print(f"Best route: {route['path']}")
# e.g. "50% Uniswap V3 + 30% Curve + 20% Balancer"
print(f"Expected output: {route['expected_output']} ETH")
print(f"Price impact: {route['price_impact_bps']} bps")
print(f"Estimated fee: ${route['fee_usd']:.4f}")

# Execute the route
fill = router.execute_route(
    route_id=route["route_id"],
    agent_id="agent_001",
    slippage_tolerance_bps=50
)

print(f"Executed: {fill['actual_output']} ETH")
print(f"Effective price: ${fill['effective_price_usd']:.2f}")
print(f"Savings vs naive: ${fill['savings_vs_naive_usd']:.4f}")

10+ Venues, One API Call

Every venue is queried in real time. Liquidity curves are cached with sub-second refresh intervals so route quality is always based on current market state.

Uniswap V3
Curve Finance
Balancer
1inch
Hyperliquid
Jupiter (SOL)
PancakeSwap
dYdX
GMX
Paraswap
๐Ÿ“Š
CEX + DEX Aggregation

The router spans both centralized (Hyperliquid, dYdX) and decentralized (Uniswap, Curve) venues in the same route calculation. Agents do not need to manage separate connections or APIs for each venue type.

โšก
Real-Time Liquidity

Route calculations use live order book depth and AMM pool reserves โ€” not stale quotes. The router rejects routes that have degraded since calculation and automatically re-routes before broadcasting to chain.

๐Ÿ”€
Multi-Hop Routing

Sometimes the best path for USDC โ†’ BTC goes through USDC โ†’ ETH โ†’ WBTC โ†’ BTC. The router evaluates multi-hop paths up to 4 hops deep when direct liquidity is thin or expensive.

TWAP Execution for Large Orders

Time-Weighted Average Price execution slices large orders into equal chunks and executes them at regular intervals, minimizing market impact for orders that would move the price if executed all at once.

$100,000 USDC โ†’ BTC executed over 60 minutes in 12 slices of ~$8,333 each
:00
:05
:10
:15
:20
:25
:30
:35
:40
:45
:50
:55
Each bar represents one slice execution โ€” price paid varies with market, averaging out over the hour
# Execute $100k order over 1 hour to minimize market impact
twap = router.execute_twap(
    from_token="USDC",
    to_token="BTC",
    total_amount=100000,
    duration_minutes=60,
    slices=12   # Execute in 12 equal chunks every 5 minutes
)
Adaptive Slice Sizing

When market conditions change mid-execution โ€” a sudden liquidity drop or price spike โ€” the TWAP engine adapts. It can pause execution, re-route remaining slices to alternative venues, or expand the time window to avoid unfavorable fills. Your agent receives real-time webhooks after each slice.

VWAP Mode

Volume-Weighted Average Price mode varies slice sizes based on observed trading volume โ€” executing more when volume is high and less when volume is thin. Use mode="vwap" for even lower average market impact on highly liquid pairs.

10+
Connected trading venues across CEX and DEX
0.15%
Average improvement over naive single-venue execution
<100ms
Route calculation latency โ€” preview before you execute

The Compounding Value of Best Execution

At scale, execution quality becomes the primary driver of trading returns. An agent that trades $100,000 per month and saves 0.15% per trade saves $150/month โ€” and that number grows linearly with volume.

For High-Frequency Agents

Agents executing hundreds of small trades per day benefit from fee optimization โ€” the router finds venues with maker rebates and routes limit orders there preferentially. Over thousands of trades, maker rebates can fully offset gas costs and turn fees from a cost into a small income stream.

For Large Capital Agents

An agent managing $50,000+ in trading capital that executes a $10,000 market order on a single venue may face 0.5โ€“1% slippage on thin pairs. The same order routed across 4 venues with the optimal split typically achieves 0.05โ€“0.15% total slippage โ€” saving $35โ€“$85 on a single trade.

Get Best Execution on Every Trade

Replace your single-venue trading calls with one router call. Zero integration overhead, immediate improvement on every trade from day one.

Get API Key โ€” Free to Start โ†’