System

Kernel

class NautilusKernel ( environment : nautilus_trader.common.Environment , name : str , trader_id : nautilus_trader.model.identifiers.TraderId , cache_config : nautilus_trader.config.common.CacheConfig , cache_database_config : nautilus_trader.config.common.CacheDatabaseConfig , data_config : Union [ nautilus_trader.config.common.DataEngineConfig , nautilus_trader.config.live.LiveDataEngineConfig ] , risk_config : Union [ nautilus_trader.config.common.RiskEngineConfig , nautilus_trader.config.live.LiveRiskEngineConfig ] , exec_config : Union [ nautilus_trader.config.common.ExecEngineConfig , nautilus_trader.config.live.LiveExecEngineConfig ] , emulator_config : Optional [ nautilus_trader.config.common.OrderEmulatorConfig ] = None , streaming_config : Optional [ nautilus_trader.config.common.StreamingConfig ] = None , actor_configs : Optional [ List [ nautilus_trader.config.common.ImportableActorConfig ] ] = None , strategy_configs : Optional [ List [ nautilus_trader.config.common.ImportableStrategyConfig ] ] = None , loop : Optional [ asyncio.events.AbstractEventLoop ] = None , loop_sig_callback : Optional [ Callable ] = None , loop_debug : bool = False , load_state : bool = False , save_state : bool = False , log_level : importlib._bootstrap.LogLevel = LogLevel.INFO , bypass_logging : bool = False )

Bases: object

Provides the core Nautilus system kernel.

The kernel is common between backtest, sandbox and live environment context types.

Parameters
  • environment (Environment { BACKTEST , SANDBOX , LIVE }) – The environment context for the kernel.

  • name ( str ) – The name for the kernel (will prepend all log messages).

  • trader_id ( str ) – The trader ID for the kernel (must be a name and ID tag separated by a hyphen).

  • cache_config ( CacheConfig ) – The cache configuration for the kernel.

  • cache_database_config ( CacheDatabaseConfig ) – The cache database configuration for the kernel.

  • data_config ( Union [ DataEngineConfig , LiveDataEngineConfig ] ) – The live data engine configuration for the kernel.

  • risk_config ( Union [ RiskEngineConfig , LiveRiskEngineConfig ] ) – The risk engine configuration for the kernel.

  • exec_config ( Union [ ExecEngineConfig , LiveExecEngineConfig ] ) – The execution engine configuration for the kernel.

  • emulator_config ( Union [ ExecEngineConfig , LiveExecEngineConfig ] ) – The order emulator configuration for the kernel.

  • streaming_config ( StreamingConfig , optional ) – The configuration for streaming to feather files.

  • actor_configs ( List [ ImportableActorConfig ] , optional ) – The list of importable actor configs.

  • strategy_configs ( List [ ImportableStrategyConfig ] , optional ) – The list of importable strategy configs.

  • loop ( AbstractEventLoop , optional ) – The event loop for the kernel.

  • loop_sig_callback ( Callable , optional ) – The callback for the signal handler.

  • loop_debug ( bool , default False ) – If the event loop should run in debug mode.

  • load_state ( bool , default False ) – If strategy state should be loaded on start.

  • save_state ( bool , default False ) – If strategy state should be saved on stop.

  • log_level ( LogLevel , default LogLevel.INFO ) – The log level for the kernels logger.

  • bypass_logging ( bool , default False ) – If logging to stdout should be bypassed.

Raises
  • TypeError – If environment is not of type Environment .

  • ValueError – If name is not a valid string.

  • TypeError – If any configuration object is not of the expected type.

property environment : nautilus_trader.common.Environment

Return the kernels environment context { BACKTEST , SANDBOX , LIVE }.

Returns

Environment

property loop : Optional [ asyncio.events.AbstractEventLoop ]

Return the kernels event loop.

Returns

AbstractEventLoop or None

property loop_sig_callback : Optional [ Callable ]

Return the kernels signal handling callback.

Returns

Callable or None

property executor : Optional [ concurrent.futures.thread.ThreadPoolExecutor ]

Return the kernels default executor.

Returns

ThreadPoolExecutor or None

property name : str

Return the kernels name.

Returns

str

property trader_id : nautilus_trader.model.identifiers.TraderId

Return the kernels trader ID.

Returns

TraderId

property machine_id : str

Return the kernels machine ID.

Returns

str

property instance_id : nautilus_trader.core.uuid.UUID4

Return the kernels instance ID.

Returns

UUID4

property ts_created : int

Return the UNIX timestamp (nanoseconds) when the kernel was created.

Returns

uint64_t

property clock : nautilus_trader.common.clock.Clock

Return the kernels clock.

Returns

Clock

property log : nautilus_trader.common.logging.LoggerAdapter

Return the kernels logger adapter.

Returns

LoggerAdapter

property logger : nautilus_trader.common.logging.Logger

Return the kernels logger.

Returns

Logger

property msgbus : nautilus_trader.msgbus.bus.MessageBus

Return the kernels message bus.

Returns

MessageBus

property cache : nautilus_trader.cache.base.CacheFacade

Return the kernels read-only cache instance.

Returns

CacheFacade

property portfolio : nautilus_trader.portfolio.base.PortfolioFacade

Return the kernels read-only portfolio instance.

Returns

PortfolioFacade

property data_engine : nautilus_trader.data.engine.DataEngine

Return the kernels data engine.

Returns

DataEngine

property risk_engine : nautilus_trader.risk.engine.RiskEngine

Return the kernels risk engine.

Returns

RiskEngine

property exec_engine : nautilus_trader.execution.engine.ExecutionEngine

Return the kernels execution engine.

Returns

ExecutionEngine

property trader : nautilus_trader.trading.trader.Trader

Return the kernels trader instance.

Returns

Trader

property writer : Optional [ nautilus_trader.persistence.streaming.StreamingFeatherWriter ]

Return the kernels writer.

Returns

StreamingFeatherWriter or None

dispose ( ) None

Dispose of the kernel releasing system resources.

This method is idempotent and irreversible. No other methods should be called after disposal.

add_log_sink ( handler : Callable [ [ Dict ] , None ] )

Register the given sink handler with the nodes logger.

Parameters

handler ( Callable [ [ Dict ] , None ] ) – The sink handler to register.

Raises

KeyError – If handler already registered.