nautechsystems/nautilus_trader · error

Failed to preview aggressive limit order

Error message

Failed to preview aggressive limit order: {e}

What it means

Raised in `submit_order_internal` when the HTTP call `preview_aggressive_limit_order` fails while converting a market order into a priced aggressive limit order. The adapter previews the order against AX to obtain a limit price and fill estimate; any transport or API error in that preview is wrapped with this message.

Solutions

  1. Inspect the wrapped inner error to determine whether it is network, HTTP status, or auth related.
  2. Verify HTTP credentials/token validity and re-authenticate if expired.
  3. Check the quantity converts to a valid contracts amount for the instrument (min size, precision).
  4. Confirm AX REST endpoint reachability and service status.
  5. Retry the submission if the failure was transient (timeout, 5xx).

Example fix

// before
let response = http_client.inner.preview_aggressive_limit_order(&request).await?;
// after
match http_client.inner.preview_aggressive_limit_order(&request).await {
    Ok(resp) => resp,
    Err(e) if e.is_timeout() || e.status().map_or(false, |s| s.is_server_error()) => {
        // retry once with backoff
        tokio::time::sleep(Duration::from_millis(250)).await;
        http_client.inner.preview_aggressive_limit_order(&request).await?
    }
    Err(e) => return Err(e.into()),
}
Defensive patterns

Strategy: retry

Validate before calling

if quantity.as_decimal() < instrument.min_quantity().unwrap().as_decimal() {
    anyhow::bail!("quantity {quantity} below AX minimum for {instrument_id}");
}

Try / catch

match result {
    Err(e) if e.to_string().contains("Failed to preview aggressive limit order") => {
        // inspect cause: network -> retry, auth -> re-auth, 4xx -> fail fast
        log::error!("preview failed: {e:#}");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Submitting a MARKET order on AX when the preview HTTP request fails: network error, HTTP error response from AX, auth/token expired for the HTTP API, or invalid preview request parameters (symbol, contracts quantity, side).

Common situations: AX API outage or 5xx during order submission; expired HTTP auth token; quantity converted to contracts below the instrument's minimum; network partition to the AX REST endpoint; malformed request due to unexpected quantity precision.

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


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/9da6c99cb520c86c. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/architect_ax/src/execution.rs:265

                == OrderType::Market
            {
                let preview_result: anyhow::Result<Price> = async {
                    let symbol = instrument_id.symbol.inner();
                    let ax_side = AxOrderSide::from(order_side);
                    let qty_contracts = quantity_to_contracts(quantity)?;

                    let instrument = http_client.get_instrument(&symbol).ok_or_else(|| {
                        anyhow::anyhow!("Instrument {instrument_id} not found in cache")
                    })?;

                    let request =
                        PreviewAggressiveLimitOrderRequest::new(symbol, qty_contracts, ax_side);
                    let response = http_client
                        .inner
                        .preview_aggressive_limit_order(&request)
                        .await
                        .map_err(|e| {
                            anyhow::anyhow!("Failed to preview aggressive limit order: {e}")
                        })?;

                    if response.remaining_quantity > 0 {
                        log::warn!(
                            "Market order book depth insufficient: \
                             filled_qty={} remaining_qty={} for {instrument_id}",
                            response.filled_quantity,
                            response.remaining_quantity,
                        );
                    }

                    let limit_price_decimal = response.limit_price.ok_or_else(|| {
                        anyhow::anyhow!(
                            "No liquidity available for market order on {instrument_id}"
                        )
                    })?;

                    let price =

View on GitHub (pinned to 18893faf8b)