{"record":{"id":"5590e1e86e077e47","repo":"nautechsystems/nautilus_trader","slug":"order-size-not-set","errorCode":null,"errorMessage":"Order size not set","messagePattern":"Order size not set","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/grpc/order.rs","lineNumber":423,"sourceCode":"    /// Set order's expiration.\n    #[must_use]\n    pub fn until(mut self, gtof: OrderGoodUntil) -> Self {\n        self.until = Some(gtof);\n        self\n    }\n\n    /// Build the order.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the order parameters are invalid.\n    pub fn build(self) -> Result<Order, anyhow::Error> {\n        let side = self\n            .side\n            .ok_or_else(|| anyhow::anyhow!(\"Order side not set\"))?;\n        let size = self\n            .size\n            .ok_or_else(|| anyhow::anyhow!(\"Order size not set\"))?;\n\n        // Quantize size\n        let quantums = self.market_params.quantize_quantity(size)?;\n\n        // Build order ID\n        let order_id = Some(OrderId {\n            subaccount_id: Some(SubaccountId {\n                owner: self.subaccount_owner.clone(),\n                number: self.subaccount_number,\n            }),\n            client_id: self.client_id,\n            order_flags: match self.flags {\n                OrderFlags::ShortTerm => 0,\n                OrderFlags::LongTerm => 64,\n                OrderFlags::Conditional => 32,\n            },\n            clob_pair_id: self.market_params.clob_pair_id,\n        });","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/grpc/order.rs#L405-L441","documentation":"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.","triggerScenarios":"Calling build() (e.g. via build_conditional_order) without calling the size setter, or a branch that only sets size for certain order types.","commonSituations":"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.","solutions":["Always call .size(...) with a positive Decimal before .build()","Guard the caller: skip order submission entirely when the computed size is None or zero","Log the computed size path so silent None sizing is visible"],"exampleFix":"// before\nlet size = self.position.map(|p| p.size); // may be None\nlet order = builder.size(size).build()?;\n// after\nlet size = self.position.map(|p| p.size)\n    .filter(|s| *s > Decimal::ZERO)\n    .ok_or_else(|| anyhow::anyhow!(\"no position to size order from\"))?;\nlet order = builder.size(size).build()?;","handlingStrategy":"validation","validationCode":"anyhow::ensure!(size.map(|s| s > Decimal::ZERO).unwrap_or(false), \"size must be set and positive\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Skip submission when computed size is None or zero instead of building anyway","Test the sizing-to-order pipeline with empty-position cases","Make size a constructor argument rather than an optional setter"],"tags":["dydx","builder-pattern","missing-field","order-construction"],"backgroundTag":"missing-required-argument","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}