{"record":{"id":"5d7e75ffb05900c1","repo":"nautechsystems/nautilus_trader","slug":"market-buy-amount-must-be-positive","errorCode":null,"errorMessage":"market-buy amount must be positive","messagePattern":"market-buy amount must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/parse.rs","lineNumber":525,"sourceCode":"/// amount or balance is non-positive, a fee input is negative, arithmetic overflows,\n/// or the adjusted amount truncates to zero.\npub fn adjust_market_buy_amount(\n    amount: Decimal,\n    user_pusd_balance: Decimal,\n    price: Decimal,\n    fee_rate: Decimal,\n    fee_exponent: Decimal,\n    builder_taker_fee_rate: Decimal,\n) -> anyhow::Result<Decimal> {\n    if price <= Decimal::ZERO || price >= Decimal::ONE {\n        anyhow::bail!(\n            \"invalid market-buy price {price}: must satisfy 0 < price < 1 for fee adjustment\",\n        );\n    }\n\n    let platform_fee_rate = fee_curve_rate(fee_rate, price, fee_exponent)?;\n\n    anyhow::ensure!(amount > Decimal::ZERO, \"market-buy amount must be positive\");\n    anyhow::ensure!(\n        user_pusd_balance > Decimal::ZERO,\n        \"market-buy balance must be positive\"\n    );\n    anyhow::ensure!(\n        builder_taker_fee_rate >= Decimal::ZERO,\n        \"builder fee rate must be non-negative\"\n    );\n    let platform_fee = amount\n        .checked_div(price)\n        .and_then(|shares| shares.checked_mul(platform_fee_rate))\n        .context(\"market-buy platform fee overflow\")?;\n    let builder_fee = amount\n        .checked_mul(builder_taker_fee_rate)\n        .context(\"market-buy builder fee overflow\")?;\n    let total_cost = amount\n        .checked_add(platform_fee)\n        .and_then(|cost| cost.checked_add(builder_fee))","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/parse.rs#L507-L543","documentation":"adjust_market_buy_amount converts a market-buy notional into a fee-adjusted amount and first validates its inputs. The BUY amount must be strictly positive; a zero or negative amount is rejected with \"market-buy amount must be positive\".","triggerScenarios":"Calling adjust_market_buy_amount (directly or via submit_market_order / benches) with amount <= 0 — e.g. a computed notional that rounded down to zero or a negative order quantity.","commonSituations":"Position sizers producing zero-size orders when capital is exhausted or filters leave no budget; sign errors when converting from a sell-side quantity; uninitialized/default Decimal amounts.","solutions":["Guard the caller so a market BUY is only submitted when the computed amount is > 0; skip the order otherwise.","Fix the upstream sizing/sign logic that produced a zero or negative notional.","If using defaults in tests/benches, pass an explicit positive amount."],"exampleFix":"// before\nlet amount = Decimal::ZERO;\nadjust_market_buy_amount(amount, price, ...)?; // panics/errors\n// after\nif amount > Decimal::ZERO {\n    adjust_market_buy_amount(amount, price, ...)?;\n}","handlingStrategy":"validation","validationCode":"if amount <= Decimal::ZERO { skip_order(); return; }","typeGuard":"fn is_positive_amount(amount: Decimal) -> bool { amount > Decimal::ZERO }","tryCatchPattern":"match adjust_market_buy_amount(amount, price, balance, fee_rate, exponent) {\n    Ok(a) => submit(a),\n    Err(e) if e.to_string().contains(\"amount must be positive\") => tracing::warn!(\"zero-size market buy skipped\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Gate order submission on amount > 0 in the strategy/sizer layer.","Watch for zero-notional orders when capital filters exhaust the budget.","Keep buy/sell sign conventions consistent when deriving amounts."],"tags":["polymarket","market-order","validation","argument-check"],"backgroundTag":"invalid-argument-value","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"}