nautechsystems/nautilus_trader · error

venue_order_id required for query_order

Error message

venue_order_id required for query_order

What it means

Raised in `DeribitExecutionClient::query_order` when the `QueryOrder` command carries no `venue_order_id`. Deribit order state queries are keyed by the venue (Deribit) order_id, so the adapter refuses the request rather than guessing. It is a pre-flight argument validation error via `ok_or_else` on `cmd.venue_order_id`.

Source

Thrown at crates/adapters/deribit/src/execution.rs:796

                .request_account_state(account_id)
                .await
                .context("failed to query account state (check API credentials are valid)")?;

            emitter.send_account_state(account_state);
            Ok(())
        });

        Ok(())
    }

    fn query_order(&self, cmd: QueryOrder) -> anyhow::Result<()> {
        let ws_client = self.ws_client.clone();

        // Extract venue order ID (Deribit's order_id)
        let order_id = cmd
            .venue_order_id
            .as_ref()
            .ok_or_else(|| anyhow::anyhow!("venue_order_id required for query_order"))?
            .to_string();

        let client_order_id = cmd.client_order_id;
        let trader_id = cmd.trader_id;
        let strategy_id = cmd.strategy_id;
        let instrument_id = cmd.instrument_id;

        log::debug!("Querying order state: order_id={order_id}, client_order_id={client_order_id}");

        // Spawn async task to query order state via WebSocket
        // Response will be dispatched through the WebSocket stream handler as OrderStatusReport
        self.spawn_task("query_order", async move {
            ws_client
                .query_order(
                    &order_id,
                    client_order_id,
                    trader_id,
                    strategy_id,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Wait for the order-submit acknowledgement (which carries `venue_order_id`) before issuing query_order, or subscribe to order events instead.
  2. Populate `cmd.venue_order_id` with the Deribit order_id before sending the command.
  3. For orders known only by client_order_id, look up the venue id from prior order events or use a Deribit `get_order_state_by_label`-style path if the adapter supports it.
  4. Guard caller code: skip or defer the query when `venue_order_id` is None.

Example fix

// before
bus.send(QueryOrder { instrument_id, client_order_id: Some(cid), venue_order_id: None, .. });

// after
if let Some(venue_order_id) = cache.venue_order_id(&client_order_id) {
    bus.send(QueryOrder { instrument_id, client_order_id: Some(cid), venue_order_id: Some(venue_order_id), .. });
}
Defensive patterns

Strategy: validation

Validate before calling

// Rust, before issuing the command
if cmd.venue_order_id.is_none() {
    // defer query until the venue acknowledges the order
    return Ok(());
}

Type guard

fn has_venue_order_id(cmd: &QueryOrder) -> Option<VenueOrderId> {
    cmd.venue_order_id
}

Prevention

When it happens

Trigger: Sending a `QueryOrder` command (e.g. via the trading kernel's `query_order` / a `QueryOrder` message) for an order that was never accepted by Deribit — hence has no venue_order_id assigned — or constructing the command manually without setting `venue_order_id`.

Common situations: Querying an order that was rejected before venue acknowledgement, querying a locally-generated order whose submit never completed, custom strategy code building QueryOrder with only `client_order_id`, or a race where the query fires before the `VenueOrderId` is assigned.

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


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