nautechsystems/nautilus_trader · error · anyhow::Error

Order size not set

Error message

Order size not set

What it means

Builder guard in the dYdX order builder's build: no order size was set on the builder before build was called, so a zero-unknown-size order cannot be constructed and the builder reports the missing required field.

Source

Thrown at crates/adapters/dydx/src/grpc/order.rs:423

    /// Set order's expiration.
    #[must_use]
    pub fn until(mut self, gtof: OrderGoodUntil) -> Self {
        self.until = Some(gtof);
        self
    }

    /// Build the order.
    ///
    /// # Errors
    ///
    /// Returns an error if the order parameters are invalid.
    pub fn build(self) -> Result<Order, anyhow::Error> {
        let side = self
            .side
            .ok_or_else(|| anyhow::anyhow!("Order side not set"))?;
        let size = self
            .size
            .ok_or_else(|| anyhow::anyhow!("Order size not set"))?;

        // Quantize size
        let quantums = self.market_params.quantize_quantity(size)?;

        // Build order ID
        let order_id = Some(OrderId {
            subaccount_id: Some(SubaccountId {
                owner: self.subaccount_owner.clone(),
                number: self.subaccount_number,
            }),
            client_id: self.client_id,
            order_flags: match self.flags {
                OrderFlags::ShortTerm => 0,
                OrderFlags::LongTerm => 64,
                OrderFlags::Conditional => 32,
            },
            clob_pair_id: self.market_params.clob_pair_id,
        });

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Always call .size(...) with a positive Decimal before .build()
  2. Guard the caller: skip order submission entirely when the computed size is None or zero
  3. Log the computed size path so silent None sizing is visible

Example fix

// before
let size = self.position.map(|p| p.size); // may be None
let order = builder.size(size).build()?;
// after
let size = self.position.map(|p| p.size)
    .filter(|s| *s > Decimal::ZERO)
    .ok_or_else(|| anyhow::anyhow!("no position to size order from"))?;
let order = builder.size(size).build()?;
Defensive patterns

Strategy: validation

Validate before calling

anyhow::ensure!(size.map(|s| s > Decimal::ZERO).unwrap_or(false), "size must be set and positive");

Prevention

When it happens

Trigger: Calling build() (e.g. via build_conditional_order) without calling the size setter, or a branch that only sets size for certain order types.

Common situations: Sizing logic that computes size lazily and can return None (e.g. zero remaining position); refactor that dropped the .size() call; order-sized-from-position code where position lookup returned nothing.

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/5590e1e86e077e47. Report an issue: GitHub.