nautechsystems/nautilus_trader · error · anyhow::Error

Failed to preview aggressive limit order: {e}

Error message

Failed to preview aggressive limit order: {e}

What it means

AX has no native market order type; the adapter emulates it by first calling preview_aggressive_limit_order to obtain the take-through price, then submitting an aggressive IOC limit at that price. This error means the preview REST call itself failed; the {e} carries the AxHttpError (network error, 4xx/5xx from the venue, auth token expiry, rate limit). The market order is never submitted.

Source

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

            {
                let preview_result: anyhow::Result<Price> = async {
                    let symbol = instrument_id.symbol.inner();
                    let ax_side = AxOrderSide::try_from(order_side)
                        .map_err(|e| anyhow::anyhow!("Invalid order side: {e}"))?;
                    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 a4b06ed870)

Solutions

  1. Inspect the wrapped AxHttpError: 429 -> throttle market-order frequency; 401 -> token refresh issue; network -> check egress
  2. Retry the market order after a short backoff (preview failures are often transient); the adapter does not auto-retry the preview
  3. If the error persists, submit an aggressive LIMIT order priced from your own book view instead of relying on emulation
  4. Check the Architect status page/API for ongoing degradation

Example fix

// before
self.submit_order(&market_order); // one-shot, preview failure loses the trade
// after: retry emulation, else fall back to aggressive limit
match self.submit_order(&market_order) {
    Ok(_) => {}
    Err(_) if attempt < MAX => { /* backoff, resubmit */ }
    _ => self.submit_order(&aggressive_limit),
}
Defensive patterns

Strategy: retry

Try / catch

// Around order submission: classify preview failures as transient
match result {
    Err(err) if err.to_string().contains("Failed to preview") => {
        // transient REST failure: back off and resubmit once
        tokio::time::sleep(Duration::from_millis(500)).await;
        resubmit(order).await
    }
    other => other,
}

Prevention

When it happens

Trigger: submit_order(OrderType::Market) when the AX REST endpoint errors on preview: transient network drop, 429 rate limit, expired bearer token mid-session, venue 5xx, or malformed preview request (symbol/quantity rejected).

Common situations: Burst of market orders hitting the REST quota; long-running session whose token expired and re-auth raced the preview; venue maintenance window; flaky egress while preview-only traffic is fine on the orders socket.

Related errors


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