nautechsystems/nautilus_trader · error
Swap quote failed for
Error message
Swap quote failed for {instrument_id}: {e} What it means
This error wraps a failure from the local Uniswap V3 pool quote calculation (`swap_exact_in`) when preparing a SELL swap order. The pool profiler could not compute the expected amount out for the given base amount and direction, so the swap cannot be priced and the order preparation aborts. The underlying cause `e` is embedded in the message.
Solutions
- Inspect the chained cause `e` in the message to see the underlying pool-quote failure (RPC error, revert, math overflow).
- Verify the pool has sufficient liquidity in the swap direction; test with a smaller base_amount.
- Check the instrument's token0/token1 configuration matches the actual pool contract so zero_for_one is correct.
- Ensure the RPC connection is healthy and the client is connected (signer initialized) before submitting.
- Re-create the pool/profiler from fresh on-chain state if cached pool data is stale.
Example fix
// before: submitting a SELL swap against an empty pool
client.submit_order(sell_order)?; // Swap quote failed for ETH/USDC: ...
// after: guard on liquidity first
if profiler.liquidity() == 0 { return Err(anyhow!("pool has no liquidity")); }
client.submit_order(sell_order)?; Defensive patterns
Strategy: validation
Validate before calling
if pool.liquidity == 0 { return Err("pool has no liquidity for swap"); }
if !client.is_connected() { return Err("client not connected"); } Type guard
fn is_quoteable(pool: &Pool) -> bool { pool.liquidity > 0 && pool.token0.valid() && pool.token1.valid() } Try / catch
match client.submit_order(order) { Err(e) if e.to_string().contains("Swap quote failed") => { log_cause_and_retry_with_fresh_pool(e); } Ok(r) => r } Prevention
- Check pool liquidity before submitting swaps
- Keep instrument token0/token1 config in sync with on-chain pool
- Monitor RPC health before quoting
When it happens
Trigger: Calling submit_order for a SELL order on a DEX instrument where the internal `profiler.swap_exact_in(base_amount, zero_for_one, None)` returns Err — e.g. pool state cannot be fetched, the tick math overflows, or the pool has no liquidity for the direction.
Common situations: Trading against a newly created or empty pool with zero liquidity; pool contract reverted during quote; stale or disconnected RPC during state sync; instrument/token address misconfiguration so the direction flag (zero_for_one) is wrong.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- Cannot quote swap with zero amount
- Cannot calculate execution price with zero amounts
- Cannot calculate price impact, the spot price before is not…
- Cannot calculate slippage, the spot price before is not set
- Cannot decode inverted price from zero sqrt_price_x96
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/4858adcc28c534f3.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/blockchain/src/execution/client.rs:1676
.ok_or_else(|| {
anyhow::anyhow!(
"No pool profiler for {instrument_id}; an active data subscription is required to quote the swap"
)
})?;
if !profiler.is_initialized {
anyhow::bail!("Pool profiler for {instrument_id} is not initialized");
}
let profiler_position = profiler.last_processed_event.clone().ok_or_else(|| {
anyhow::anyhow!("Pool profiler for {instrument_id} has processed no events")
})?;
let zero_for_one = token_in == pool.token0.address;
let (amount_in, quoted_amount_out) = match order.order_side() {
OrderSide::Sell => {
let quote = profiler
.swap_exact_in(base_amount, zero_for_one, None)
.map_err(|e| anyhow::anyhow!("Swap quote failed for {instrument_id}: {e}"))?;
let amount_filled = if zero_for_one {
quote.amount0
} else {
quote.amount1
};
if amount_filled != I256::from(base_amount) {
anyhow::bail!(
"Local quote for {instrument_id} filled {amount_filled} of the {base_amount} order amount; pool liquidity cannot fill the order"
);
}
(base_amount, exact_output_amount("e, zero_for_one)?)
}
OrderSide::Buy => {
let quote = profiler
.swap_exact_out(base_amount, zero_for_one, None)
.map_err(|e| anyhow::anyhow!("Swap quote failed for {instrument_id}: {e}"))?;
let amount_in = quote.get_input_amount();View on GitHub (pinned to 18893faf8b)