nautechsystems/nautilus_trader · error

Invalid venue order ID: {e}

Error message

Invalid venue order ID: {e}

What it means

Thrown by BinanceFuturesHttpClient::cancel_order when the supplied venue_order_id string cannot be parsed as an i64 and no client_order_id was provided as a fallback. Binance USD-M/Coin-M futures REST cancels key off a numeric orderId, so NautilusTrader parses VenueOrderId.inner() into i64; if parsing fails the client can only fall back to origClientOrderId, and with neither identifier usable it bails. The {e} suffix carries the underlying std::num::ParseIntError (e.g. 'invalid digit found in string').

Source

Thrown at crates/adapters/binance/src/futures/http/client.rs:2381

        client_order_id: Option<ClientOrderId>,
    ) -> anyhow::Result<VenueOrderId> {
        anyhow::ensure!(
            venue_order_id.is_some() || client_order_id.is_some(),
            "Either venue_order_id or client_order_id must be provided"
        );

        let symbol = format_binance_symbol(&instrument_id);

        let order_id = match venue_order_id {
            Some(venue_order_id) => match venue_order_id.inner().parse::<i64>() {
                Ok(order_id) => Some(order_id),
                Err(e) if client_order_id.is_some() => {
                    log::warn!(
                        "Unable to parse venue_order_id {venue_order_id} for cancel, canceling by client_order_id: {e}"
                    );
                    None
                }
                Err(e) => anyhow::bail!("Invalid venue order ID: {e}"),
            },
            None => None,
        };

        let params = BinanceCancelOrderParams {
            symbol,
            order_id,
            orig_client_order_id: client_order_id
                .map(|id| encode_broker_id(&id, BINANCE_NAUTILUS_FUTURES_BROKER_ID)),
            recv_window: None,
        };

        let order = self.inner.cancel_order(&params).await?;
        Ok(VenueOrderId::new(order.order_id.to_string()))
    }

    /// Cancels an algo order (conditional order) via the Binance Algo Service.
    ///

View on GitHub (pinned to a4b06ed870)

Solutions

  1. Pass the client_order_id alongside the venue_order_id so the client can fall back to origClientOrderId when the parse fails
  2. Verify the VenueOrderId actually originated from a Binance Futures execution report (it is always a decimal integer string) before calling cancel_order
  3. If the target is a conditional/stop order, call cancel_algo_order(client_order_id) instead of cancel_order
  4. Sanitize stored IDs before replay: strip prefixes/suffixes and confirm str::parse::<i64>() succeeds

Example fix

// before
client.cancel_order(instrument_id, Some(venue_order_id), None).await?;

// after
client
    .cancel_order(instrument_id, Some(venue_order_id), Some(client_order_id))
    .await?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_binance_venue_id(id: &VenueOrderId) -> bool {
    id.inner().parse::<i64>().is_ok()
}

if !is_binance_venue_id(&venue_order_id) && client_order_id.is_none() {
    log::warn!("non-numeric venue order id {venue_order_id} with no client id fallback");
    return Ok(());
}

Type guard

fn is_binance_venue_id(id: &VenueOrderId) -> bool {
    id.inner().parse::<i64>().is_ok()
}

Try / catch

Match on the anyhow message prefix "Invalid venue order ID" and surface a typed InvalidOrderId error to the caller; always pair venue_order_id with client_order_id so the library's built-in fallback path can engage.

Prevention

When it happens

Trigger: Calling cancel_order(instrument_id, Some(venue_order_id), None) where venue_order_id contains a non-numeric string (e.g. 'abc-123', an algo/conditional order ID, or an ID minted by another venue or a custom ClientOrderId scheme) or a number outside i64 range. The sibling branch (client_order_id.is_some()) logs a warning and falls back instead, so this exact error only fires when client_order_id is None.

Common situations: Porting a strategy from another venue and reusing VenueOrderIds from that venue; canceling a Binance 'Algo' (conditional) order through the regular cancel endpoint (algo orders use cancel_algo_order with client_algo_id); reconstructing VenueOrderId from a database where it was stored with decorations; empty-string or UUID-style IDs passed in integration glue code.

Related errors


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