{"record":{"id":"5bf9e909595ea491","repo":"nautechsystems/nautilus_trader","slug":"livenode-add-exec-algorithm-requires-a-python-v2-e","errorCode":null,"errorMessage":"LiveNode.add_exec_algorithm requires a Python v2 ExecutionAlgorithm instance; use add_exec_algorithm_from_config for DataActor-based algorithms: {e}","messagePattern":"LiveNode\\.add_exec_algorithm requires a Python v2 ExecutionAlgorithm instance; use add_exec_algorithm_from_config for DataActor-based algorithms: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/live/src/python/node.rs","lineNumber":1466,"sourceCode":"            return Err(to_pyruntime_err(\n                \"Cannot add exec algorithm while node is running, add exec algorithms before running the node\",\n            ));\n        }\n\n        log::debug!(\"`add_exec_algorithm` with a constructed instance\");\n\n        let exec_algorithm = exec_algorithm.clone().unbind();\n        let py_exec_algorithm = Python::attach(|py| -> anyhow::Result<PyExecutionAlgorithm> {\n            let bound = exec_algorithm.bind(py);\n            let config = bound\n                .getattr(\"config\")\n                .ok()\n                .filter(|config| !config.is_none());\n            let mut py_exec_algorithm_ref = bound\n                .extract::<PyRefMut<PyExecutionAlgorithm>>()\n                .map_err(Into::<PyErr>::into)\n                .map_err(|e| {\n                    anyhow::anyhow!(\n                        \"LiveNode.add_exec_algorithm requires a Python v2 ExecutionAlgorithm instance; use add_exec_algorithm_from_config for DataActor-based algorithms: {e}\"\n                    )\n                })?;\n\n            if let Some(config) = config.as_ref() {\n                py_exec_algorithm_ref.configure_from_py_config(config)?;\n            }\n\n            py_exec_algorithm_ref.set_python_instance(bound)?;\n            Ok(py_exec_algorithm_ref.clone())\n        })\n        .map_err(to_pyruntime_err)?;\n\n        let exec_algorithm_id = self\n            .node_mut()?\n            .kernel_mut()\n            .trader\n            .borrow_mut()","sourceCodeStart":1448,"sourceCodeEnd":1484,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/python/node.rs#L1448-L1484","documentation":"Raised by LiveNode.add_exec_algorithm when the supplied object cannot be extracted as a native PyExecutionAlgorithm (v2 Python execution algorithm). The message itself points to the remedy: DataActor-based (pure-Python actor) algorithms must be added via add_exec_algorithm_from_config instead.","triggerScenarios":"Calling add_exec_algorithm with an object that is not a v2 pyo3-backed ExecutionAlgorithm instance — e.g. a DataActor/exec-actor subclass built from config, or a custom class not deriving from nautilus_trader.ExecutionAlgorithm.","commonSituations":"Mixing the two registration APIs after refactor; passing an algorithm built with a config object to the instance-based API; porting strategies from the pure-Python engine.","solutions":["If the algorithm is DataActor-based, switch the call to add_exec_algorithm_from_config with its config","If it should be a v2 instance, ensure the class subclasses nautilus_trader's ExecutionAlgorithm","Check import paths — nautilus_trader.execution.algorithm vs custom modules","Use the config path end-to-end for consistency"],"exampleFix":"// before\nnode.add_exec_algorithm(MyDataActorBasedAlgo(config))\n// after\nnode.add_exec_algorithm_from_config(MyExecAlgoConfig(...))","handlingStrategy":"validation","validationCode":"from nautilus_trader.execution.algorithm import ExecutionAlgorithm\nassert isinstance(algo, ExecutionAlgorithm), \"use add_exec_algorithm_from_config for DataActor-based algos\"","typeGuard":"def is_v2_exec_algorithm(obj) -> bool:\n    from nautilus_trader.execution.algorithm import ExecutionAlgorithm\n    return isinstance(obj, ExecutionAlgorithm)","tryCatchPattern":"try:\n    node.add_exec_algorithm(algo)\nexcept Exception as e:\n    if \"requires a Python v2 ExecutionAlgorithm\" in str(e):\n        node.add_exec_algorithm_from_config(algo.config)\n    else:\n        raise","preventionTips":["Route DataActor-based algorithms to add_exec_algorithm_from_config","Keep one registration convention per node config","Check base classes when migrating from the pure-Python engine"],"tags":["pyo3","live-trading","execution-algorithm","wrong-api-usage"],"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-14T05:17:10.506Z"}