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.
How It Works
Three steps, executed in parallel, in under 100 milliseconds. Your agent sends one intent and receives one fill โ the routing complexity is invisible.
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.
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.
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.
Developer API
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}")
Connected Venues
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.
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.
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.
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.
Large Order Execution
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.
# 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 )
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.
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.
Economics
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.
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.
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.
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 โ