nautechsystems/nautilus_trader · error
ExecutionAlgorithm not registered: Portfolio not initialized
Error message
ExecutionAlgorithm not registered: Portfolio not initialized
What it means
ExecutionAlgorithm's portfolio_rc accessor unwraps the Option<Rc<RefCell<Portfolio>>> held by ExecutionAlgorithmCore. It is Some only after the algorithm has been registered with a system/kernel that owns an initialized Portfolio; otherwise any portfolio access panics.
Source
Thrown at crates/trading/src/algorithm/core.rs:109
/// plug-in authoring surface. Native borrows, `Rc<RefCell<_>>`, and core
/// references do not cross those boundaries.
pub trait ExecutionAlgorithmNative: DataActorNative {
/// Returns the execution algorithm core.
fn exec_algorithm_core(&self) -> &ExecutionAlgorithmCore;
/// Returns the mutable execution algorithm core.
fn exec_algorithm_core_mut(&mut self) -> &mut ExecutionAlgorithmCore;
/// Returns a clone of the reference-counted portfolio.
///
/// # Panics
///
/// Panics if the execution algorithm has not been registered.
fn portfolio_rc(&self) -> Rc<RefCell<Portfolio>> {
self.exec_algorithm_core()
.portfolio
.as_ref()
.expect("ExecutionAlgorithm not registered: Portfolio not initialized")
.clone()
}
}
impl Debug for ExecutionAlgorithmCore {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!(ExecutionAlgorithmCore))
.field("actor", &self.actor)
.field("config", &self.config)
.field("exec_algorithm_id", &self.exec_algorithm_id)
.field("exec_spawn_ids", &self.exec_spawn_ids.len())
.field("subscribed_strategies", &self.subscribed_strategies.len())
.field(
"pending_spawn_reductions",
&self.pending_spawn_reductions.len(),
)
.field("submit_params", &self.submit_params.len())
.field(View on GitHub (pinned to 18893faf8b)
Solutions
- Run the algorithm inside a fully built TradingNode so registration injects the Portfolio.
- Verify the node's portfolio configuration is present and enabled.
- Defer portfolio access until after the algorithm is registered (e.g. post on_start wiring).
- In tests, register the algorithm with a core that has a Portfolio set up first.
Example fix
// before
fn on_start(&mut self) {
let pos = self.portfolio_rc().borrow().is_flat(&instrument_id); // panics if unregistered
}
// after
fn on_start(&mut self) {
if !self.is_registered() {
log::warn("portfolio unavailable; skipping check");
return;
}
let pos = self.portfolio_rc().borrow().is_flat(&instrument_id);
} Defensive patterns
Strategy: type-guard
Validate before calling
// guard before portfolio access
if !algorithm.is_registered() {
return; // or log and defer
} Type guard
fn has_portfolio(core: &ExecutionAlgorithmCore) -> bool { core.portfolio.is_some() } Try / catch
let portfolio = std::panic::catch_unwind(|| self.portfolio_rc())
.ok()
.map(|p| p.borrow()); Prevention
- Only run ExecutionAlgorithms inside a fully constructed TradingNode
- Confirm portfolio is enabled/configured in the node config
- Defer portfolio-dependent logic until after kernel registration (post on_start)
- In unit tests, register the algorithm with an initialized Portfolio first
When it happens
Trigger: Calling any ExecutionAlgorithm method that reaches portfolio_rc (e.g. order/position queries, portfolio state access) before the algorithm was registered via a trading node/kernel, or when the node started without a Portfolio configured.
Common situations: Using an ExecutionAlgorithm standalone (outside a TradingNode) or in unit tests without registering it; constructing a node with portfolio disabled/misconfigured; calling algorithm methods in on_start before the kernel wires the portfolio.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Logging already initialized but new guard could not be creat
- Failed to create LogGuard from global sender
- Strategy not registered: Portfolio not initialized
- Active execution intent {intent_id} was not found
- Latency model should be initialized
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/3cff387b75566cf3.
Report an issue: GitHub.