System¶
- class NautilusKernel¶
Bases:
objectProvides the core Nautilus system kernel.
The kernel is common between
backtest,sandboxandliveenvironment context types.- Parameters:
name (str) – The name for the kernel (will prepend all log messages).
config (NautilusKernelConfig) – The configuration for the kernel instance.
loop (asyncio.AbstractEventLoop, optional) – The event loop for the kernel.
loop_sig_callback (Callable, optional) – The callback for the signal handler.
- Raises:
ValueError – If name is not a valid string.
TypeError – If any configuration object is not of the expected type.
InvalidConfiguration – If any configuration object is mismatched with the environment context, (live configurations for ‘backtest’, or backtest configurations for ‘live’).
InvalidConfiguration – If LoggingConfig.bypass_logging is set true in a LIVE context.
- property environment: Environment¶
Return the kernels environment context {
BACKTEST,SANDBOX,LIVE}.- Return type:
- property loop: AbstractEventLoop¶
Return the kernels event loop.
- Return type:
AbstractEventLoop
- property loop_sig_callback: Callable | None¶
Return the kernels signal handling callback.
- Return type:
Callable or
None
- property executor: ThreadPoolExecutor | None¶
Return the kernels default executor.
- Return type:
ThreadPoolExecutor or
None
- property name: str¶
Return the kernels name.
- Return type:
str
- property machine_id: str¶
Return the kernels machine ID.
- Return type:
str
- property ts_created: int¶
Return the UNIX timestamp (nanoseconds) when the kernel was created.
- Return type:
int
- property ts_started: int | None¶
Return the UNIX timestamp (nanoseconds) when the kernel was last started.
- Return type:
int or
None
- property ts_shutdown: int | None¶
Return the UNIX timestamp (nanoseconds) when the kernel was last shutdown.
- Return type:
int or
None
- property load_state: bool¶
If the kernel has been configured to load actor and strategy state.
- Return type:
bool
- property save_state: bool¶
If the kernel has been configured to save actor and strategy state.
- Return type:
bool
- property msgbus: MessageBus¶
Return the kernels message bus.
- Return type:
- property msgbus_serializer: MessageBus¶
Return the kernels message bus serializer (if created).
- Return type:
MsgSpecSerializer or
None
- property msgbus_database: MessageBus¶
Return the kernels message bus database (if created).
- Return type:
RedisMessageBusDatabase or
None
- property cache: CacheFacade¶
Return the kernels read-only cache instance.
- Return type:
- property portfolio: PortfolioFacade¶
Return the kernels read-only portfolio instance.
- Return type:
- property data_engine: DataEngine¶
Return the kernels data engine.
- Return type:
- property risk_engine: RiskEngine¶
Return the kernels risk engine.
- Return type:
- property exec_engine: ExecutionEngine¶
Return the kernels execution engine.
- Return type:
- property emulator: OrderEmulator¶
Return the kernels order emulator.
- Return type:
- property writer: StreamingFeatherWriter | None¶
Return the kernels writer.
- Return type:
StreamingFeatherWriter or
None
- property catalogs: dict[str, ParquetDataCatalog]¶
Return the kernel’s list of data catalogs.
- Return type:
dict[str, ParquetDataCatalog]
- get_log_guard() LogGuard | LogGuard | None¶
Return the global logging subsystems log guard.
May return
Noneif the logging subsystem was already initialized.- Return type:
nautilus_pyo3.LogGuard | LogGuard | None
- is_running() bool¶
Return whether the kernel is running.
- Return type:
bool
- start() None¶
Start the Nautilus system kernel.
- async start_async() None¶
Start the Nautilus system kernel in an asynchronous context with an event loop.
- Raises:
RuntimeError – If no event loop has been assigned to the kernel.
- stop() None¶
Stop the Nautilus system kernel.
- async stop_async() None¶
Stop the Nautilus system kernel asynchronously.
After a specified delay the internal Trader residual state will be checked.
If save strategy is configured, then strategy states will be saved.
- Raises:
RuntimeError – If no event loop has been assigned to the kernel.
- dispose() None¶
Dispose of the Nautilus kernel, releasing system resources.
Calling this method multiple times has the same effect as calling it once (it is idempotent). Once called, it cannot be reversed, and no other methods should be called on this instance.
Notes
The log guard is intentionally not disposed to support running multiple engines sequentially without re-initializing logging.
- cancel_all_tasks() None¶
Cancel all tasks currently running for the Nautilus kernel.
This method handles task cancellation in both synchronous and asynchronous contexts: - 1. All pending tasks are identified and given a cancellation signal. - 2. The kernel waits until the shutdown timeout for tasks to conclude or raise exceptions. - 3. Any tasks that remain unresponsive or encounter errors are logged. - 4. If the event loop is still active, the cancellation proceeds asynchronously; otherwise, it’s handled immediately.
- Raises:
RuntimeError – If no event loop has been assigned to the kernel.
Notes
Tasks that don’t respond to cancellation within timeout are logged but not forcibly terminated.
CancelledError exceptions are expected and handled silently.
Other exceptions from tasks are logged with full stack traces.
If the loop is closed, method exits early with a warning.