nautechsystems/nautilus_trader · error

Python FeeModel.get_commission_with_context failed: {e}

Error message

Python FeeModel.get_commission_with_context failed: {e}

What it means

Wraps any failure of the Python FeeModel.get_commission_with_context call with a descriptive prefix identifying the failing bridge boundary. The `{e}` carries the inner cause: either the Python call raised an exception or the result could not be extracted to the expected Rust type.

Source

Thrown at crates/execution/src/python/fee.rs:229

                return obj
                    .call_method1(
                        "get_commission",
                        (order, fill_quantity, fill_px, instrument),
                    )?
                    .extract()
                    .map_err(|e| anyhow::anyhow!("{e}"));
            }

            let order = order_any_to_pyobject(py, order.clone())?;
            let instrument = instrument_any_to_pyobject(py, instrument.clone())?;
            obj.call_method1(
                "get_commission_with_context",
                (order, fill_quantity, fill_px, instrument, underlying_px),
            )?
            .extract()
            .map_err(|e| anyhow::anyhow!("{e}"))
        })
        .map_err(|e| anyhow::anyhow!("Python FeeModel.get_commission_with_context failed: {e}"))
    }
}

fn has_method_override_before_base(
    py: Python<'_>,
    obj: &Bound<'_, PyAny>,
    method_name: &str,
) -> PyResult<bool> {
    let base_type = py.get_type::<PyFeeModel>();
    for cls in obj.get_type().getattr("__mro__")?.try_iter()? {
        let cls = cls?;
        if cls.is(base_type.as_any()) {
            return Ok(false);
        }

        if cls.getattr("__dict__")?.contains(method_name)? {
            return Ok(true);
        }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the full anyhow error chain (source of this message) to find the original Python exception
  2. Fix the Python FeeModel implementation or its return type
  3. Match the current NautilusTrader FeeModel.get_commission_with_context signature
  4. Add unit tests for the Python model against representative orders/instruments
Defensive patterns

Strategy: try-catch

Try / catch

try:
    commission = fee_model.get_commission_with_context(order, qty, px, instrument, underlying_px)
except Exception as e:
    log.error(f"FeeModel.get_commission_with_context failed: {e}")
    commission = fallback_commission(qty, px)

Prevention

When it happens

Trigger: Any error propagated from the inner Python FFI call in get_commission_with_context — Python exception, argument conversion failure, or extract() type mismatch.

Common situations: Deploying a custom fee model written against an older NautilusTrader Python API; returning a custom object instead of a numeric commission; Python exceptions such as KeyError on instrument_id.

Related errors


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