nautechsystems/nautilus_trader · error
Trade info not initialized
Error message
Trade info not initialized
What it means
`slippage_for_size_bps` runs a hypothetical swap through the profiler, then computes trade info and reads `quote.trade_info`. If `calculate_trade_info` did not populate `trade_info` (it remains `None`), the function errors with 'Trade info not initialized' instead of unwrapping. This is an internal invariant failure: the swap/quote flow should always set trade info before slippage is read.
Source
Thrown at crates/model/src/defi/pool_analysis/size_estimator.rs:197
/// - The swap simulation fails.
/// - The trade info or slippage calculation fails.
pub fn slippage_for_size_bps(
profiler: &PoolProfiler,
size: U256,
zero_for_one: bool,
) -> anyhow::Result<u32> {
profiler.check_if_initialized(PoolEventKind::Swap)?;
if size.is_zero() {
return Ok(0);
}
let mut quote = profiler.swap_exact_in(size, zero_for_one, None)?;
quote.calculate_trade_info(&profiler.pool.token0, &profiler.pool.token1)?;
let trade_info = quote
.trade_info
.as_ref()
.ok_or_else(|| anyhow::anyhow!("Trade info not initialized"))?;
trade_info.get_slippage_bps()
}
fn binary_search_for_size(
profiler: &PoolProfiler,
impact_bps: u32,
zero_for_one: bool,
config: &EstimationConfig,
) -> anyhow::Result<BinarySearchState> {
// Validate inputs
if impact_bps == 0 {
anyhow::bail!("Impact must be greater than zero");
}
if impact_bps > 10000 {
anyhow::bail!("Impact cannot exceed 100% (10000 bps)");
}View on GitHub (pinned to 18893faf8b)
Solutions
- Ensure the quote's `calculate_trade_info` succeeds before reading slippage; propagate its `?` result and check `trade_info.is_some()` afterwards.
- Verify the pool has liquidity and a non-zero spot price before size estimation; degenerate pools yield no trade info.
- Treat the error as a signal to skip that size in the search rather than aborting.
- Update to a version where trade-info initialization is guaranteed, or file a bug if it's None after a successful calculate.
Example fix
// before
let mut quote = profiler.swap_exact_in(size, zero_for_one, None)?;
quote.calculate_trade_info(&profiler.pool.token0, &profiler.pool.token1)?;
let trade_info = quote.trade_info.as_ref().ok_or_else(|| anyhow::anyhow!("Trade info not initialized"))?;
// after
let mut quote = profiler.swap_exact_in(size, zero_for_one, None)?;
quote.calculate_trade_info(&profiler.pool.token0, &profiler.pool.token1)?;
let Some(trade_info) = quote.trade_info.as_ref() else {
return Ok(None); // no trade info for this size; signal caller instead of erroring
}; Defensive patterns
Strategy: type-guard
Validate before calling
fn quote_ready(quote: &SwapQuote) -> bool {
quote.trade_info.is_some()
} Type guard
fn has_trade_info(quote: &SwapQuote) -> Option<&SwapTradeInfo> { quote.trade_info.as_ref() } Try / catch
let bps = match slippage_for_size_bps(profiler, size, zero_for_one) {
Ok(b) => b,
Err(e) if e.to_string().contains("Trade info not initialized") => return Ok(None),
Err(e) => return Err(e),
}; Prevention
- Check pool liquidity/spot price before running size estimation
- Always call calculate_trade_info immediately after swap_exact_in and check the result
- Handle per-size errors in binary search loops gracefully
When it happens
Trigger: Calling `slippage_for_size_bps` (directly or via `binary_search_for_size` / `size_for_impact_bps_detailed`) where the quote's `calculate_trade_info` step failed silently or was skipped, leaving `quote.trade_info == None`.
Common situations: Simulated swaps on pools with zero liquidity or zero spot price where trade-info computation short-circuits; size-estimation searches hitting edge sizes that produce degenerate quotes.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Cannot calculate slippage, the spot price before is not set
- Failed to calculate slippage: {e}
- Slippage {actual_slippage} bps exceeds tolerance {max_slippa
- Cannot calculate {metric}, the spot price before is zero
- Router allowance {allowance} is below the swap amount {} for
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/f4c8cb9601a3e29c.
Report an issue: GitHub.