{"record":{"id":"19ced749a8f3e5f9","repo":"nautechsystems/nautilus_trader","slug":"failed-to-convert-instrumentany-to-python-e","errorCode":null,"errorMessage":"Failed to convert InstrumentAny to Python: {e}","messagePattern":"Failed to convert InstrumentAny to Python: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1095,"sourceCode":"    fn on_signal(&mut self, signal: &Signal) -> anyhow::Result<()> {\n        self.dispatch_on_signal(signal)\n            .map_err(|e| anyhow::anyhow!(\"Python on_signal failed: {e}\"))\n    }\n\n    fn on_queue_state(&mut self, event: &QueueStateChanged) -> anyhow::Result<()> {\n        self.dispatch_on_queue_state(event)\n            .map_err(|e| anyhow::anyhow!(\"Python on_queue_state failed: {e}\"))\n    }\n\n    fn on_socket_state(&mut self, event: &SocketStateChanged) -> anyhow::Result<()> {\n        self.dispatch_on_socket_state(event)\n            .map_err(|e| anyhow::anyhow!(\"Python on_socket_state failed: {e}\"))\n    }\n\n    fn on_instrument(&mut self, instrument: &InstrumentAny) -> anyhow::Result<()> {\n        Python::attach(|py| {\n            let py_instrument = instrument_any_to_pyobject(py, instrument.clone())\n                .map_err(|e| anyhow::anyhow!(\"Failed to convert InstrumentAny to Python: {e}\"))?;\n            self.dispatch_on_instrument(py_instrument)\n                .map_err(|e| anyhow::anyhow!(\"Python on_instrument failed: {e}\"))\n        })\n    }\n\n    fn on_quote(&mut self, quote: &QuoteTick) -> anyhow::Result<()> {\n        self.dispatch_on_quote(*quote)\n            .map_err(|e| anyhow::anyhow!(\"Python on_quote failed: {e}\"))\n    }\n\n    fn on_trade(&mut self, tick: &TradeTick) -> anyhow::Result<()> {\n        self.dispatch_on_trade(*tick)\n            .map_err(|e| anyhow::anyhow!(\"Python on_trade failed: {e}\"))\n    }\n\n    fn on_bar(&mut self, bar: &Bar) -> anyhow::Result<()> {\n        self.dispatch_on_bar(*bar)\n            .map_err(|e| anyhow::anyhow!(\"Python on_bar failed: {e}\"))","sourceCodeStart":1077,"sourceCodeEnd":1113,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1077-L1113","documentation":"This error is raised in `on_instrument` when converting a Rust `InstrumentAny` domain object into a Python object fails before the Python handler is even called. The conversion (`instrument_any_to_pyobject`) could not produce a valid PyO3-backed Python instrument, so the dispatch never happens.","triggerScenarios":"An instrument definition arrives at a Python actor's `on_instrument` and the Rust->Python conversion of the instrument (any of Instrument:: variants) fails, typically due to an unregistered/unsupported instrument type or invalid PyO3 conversion for that variant.","commonSituations":"Using a custom or newly added instrument type not covered by the conversion, a corrupted/invalid instrument definition received from a data client, or version mismatch between adapter producing the instrument and the core conversion code.","solutions":["Log the instrument definition received and check which Instrument variant fails conversion","Verify the instrument comes from a supported adapter and passes its own validation (e.g. `InstrumentAny` construction)","Update NautilusTrader and the adapter to matching versions so the variant is supported","Register/subscribe only for instrument types your code supports"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# validate the instrument before it reaches the actor\ndef validate_instrument(inst):\n    assert inst.id is not None and inst.id.value, 'instrument id missing'\n    assert inst.price_increment is not None, 'price_increment missing'\n    return inst","typeGuard":"def is_supported_instrument(instrument) -> bool:\n    return type(instrument).__name__ in {\n        'CurrencyPair', 'CryptoPerpetual', 'CryptoFuture', 'Equity',\n        'FuturesContract', 'OptionsContract', 'Bond', 'Commodity'}","tryCatchPattern":null,"preventionTips":["Only subscribe to instrument types supported by your NautilusTrader version","Keep core and adapters on matching versions","Validate instrument definitions received from custom adapters"],"tags":["python","conversion","instrument","pyo3"],"backgroundTag":"type-conversion-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}