System - Loren1166/NautilusTrader- GitHub Wiki
System | 系统
class NautilusKernel | Nautilus 内核
class NautilusKernel:
"""
Provides the core Nautilus system kernel.
提供核心 Nautilus 系统内核。
The kernel is common between backtest, sandbox and live environment 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.
如果在 LIVE 上下文中将 LoggingConfig.bypass_logging 设置为 true。
"""
def __init__(
self,
name: str,
config: NautilusKernelConfig,
loop: asyncio.AbstractEventLoop | None = None,
loop_sig_callback: Callable | None = None
):
...
@property
def environment(self) -> Environment:
"""
Return the kernels environment context { BACKTEST, SANDBOX, LIVE }.
返回内核的环境上下文 { BACKTEST, SANDBOX, LIVE }。
Return type: Environment
"""
...
@property
def loop(self) -> AbstractEventLoop:
"""
Return the kernels event loop.
返回内核的事件循环。
Return type: AbstractEventLoop
"""
...
@property
def loop_sig_callback(self) -> Callable | None:
"""
Return the kernels signal handling callback.
返回内核的信号处理回调。
Return type: Callable or None
"""
...
@property
def executor(self) -> ThreadPoolExecutor | None:
"""
Return the kernels default executor.
返回内核的默认执行器。
Return type: ThreadPoolExecutor or None
"""
...
@property
def name(self) -> str:
"""
Return the kernels name.
返回内核的名称。
Return type: str
"""
...
@property
def trader_id(self) -> TraderId:
"""
Return the kernels trader ID.
返回内核的交易员 ID。
Return type: TraderId
"""
...
@property
def machine_id(self) -> str:
"""
Return the kernels machine ID.
返回内核的机器 ID。
Return type: str
"""
...
@property
def instance_id(self) -> UUID4:
"""
Return the kernels instance ID.
返回内核的实例 ID。
Return type: UUID4
"""
...
@property
def ts_created(self) -> int:
"""
Return the UNIX timestamp (nanoseconds) when the kernel was created.
返回内核创建时的 UNIX 时间戳(纳秒)。
Return type: uint64_t
"""
...
@property
def load_state(self) -> bool:
"""
If the kernel has been configured to load actor and strategy state.
如果内核已配置为加载 actor 和策略状态。
Return type: bool
"""
...
@property
def save_state(self) -> bool:
"""
If the kernel has been configured to save actor and strategy state.
如果内核已配置为保存 actor 和策略状态。
Return type: bool
"""
...
@property
def clock(self) -> Clock:
"""
Return the kernels clock.
返回内核的时钟。
Return type: Clock
"""
...
@property
def logger(self) -> Logger:
"""
Return the kernels logger.
返回内核的记录器。
Return type: Logger
"""
...
@property
def msgbus(self) -> MessageBus:
"""
Return the kernels message bus.
返回内核的消息总线。
Return type: MessageBus
"""
...
@property
def msgbus_serializer(self) -> MessageBus:
"""
Return the kernels message bus serializer (if created).
返回内核的消息总线序列化器(如果已创建)。
Return type: MsgSpecSerializer or None
"""
...
@property
def msgbus_database(self) -> MessageBus:
"""
Return the kernels message bus database (if created).
返回内核的消息总线数据库(如果已创建)。
Return type: RedisMessageBusDatabase or None
"""
...
@property
def cache(self) -> CacheFacade:
"""
Return the kernels read-only cache instance.
返回内核的只读缓存实例。
Return type: CacheFacade
"""
...
@property
def portfolio(self) -> PortfolioFacade:
"""
Return the kernels read-only portfolio instance.
返回内核的只读投资组合实例。
Return type: PortfolioFacade
"""
...
@property
def data_engine(self) -> DataEngine:
"""
Return the kernels data engine.
返回内核的数据引擎。
Return type: DataEngine
"""
...
@property
def risk_engine(self) -> RiskEngine:
"""
Return the kernels risk engine.
返回内核的风险引擎。
Return type: RiskEngine
"""
...
@property
def exec_engine(self) -> ExecutionEngine:
"""
Return the kernels execution engine.
返回内核的执行引擎。
Return type: ExecutionEngine
"""
...
@property
def emulator(self) -> OrderEmulator:
"""
Return the kernels order emulator.
返回内核的订单模拟器。
Return type: OrderEmulator
"""
...
@property
def trader(self) -> Trader:
"""
Return the kernels trader instance.
返回内核的交易员实例。
Return type: Trader
"""
...
@property
def writer(self) -> StreamingFeatherWriter | None:
"""
Return the kernels writer.
返回内核的写入器。
Return type: StreamingFeatherWriter or None
"""
...
@property
def catalog(self) -> ParquetDataCatalog | None:
"""
Return the kernels data catalog.
返回内核的数据目录。
Return type: ParquetDataCatalog or None
"""
...
def get_log_guard(self):
"""
Return the global logging systems log guard.
返回全局日志系统的日志守卫。
May return None if the logging system was already initialized.
如果日志系统已初始化,则可能返回 None。
Return type: nautilus_pyo3.LogGuard | LogGuard | None
"""
...
def start(self) -> None:
"""
Start the Nautilus system kernel.
启动 Nautilus 系统内核。
"""
...
async def start_async(self) -> None:
"""
Start the Nautilus system kernel in an asynchronous context with an event loop.
在具有事件循环的异步上下文中启动 Nautilus 系统内核。
Raises:
引发:
RuntimeError – If no event loop has been assigned to the kernel.
如果未向内核分配事件循环,则引发 RuntimeError。
"""
...
async def stop(self) -> None:
"""
Stop the Nautilus system kernel.
停止 Nautilus 系统内核。
"""
...
async def stop_async(self) -> None:
"""
Stop the Nautilus system kernel asynchronously.
异步停止 Nautilus 系统内核。
After a specified delay the internal Trader residual state will be checked.
在指定的延迟之后,将检查内部 Trader 的残留状态。
If save strategy is configured, then strategy states will be saved.
如果配置了保存策略,则将保存策略状态。
Raises:
引发:
RuntimeError – If no event loop has been assigned to the kernel.
如果未向内核分配事件循环,则引发 RuntimeError。
"""
...
def dispose(self) -> None:
"""
Dispose of the Nautilus kernel, releasing system resources.
处理 Nautilus 内核,释放系统资源。
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.
多次调用此方法与调用一次的效果相同(它是幂等的)。一旦调用,它就无法撤消,并且不应在此实例上调用其他方法。
"""
...
def cancel_all_tasks(self) -> None:
"""
Cancel all tasks currently running for the Nautilus kernel.
取消当前为 Nautilus 内核运行的所有任务。
Raises:
引发:
RuntimeError – If no event loop has been assigned to the kernel.
如果未向内核分配事件循环,则引发 RuntimeError。
"""
...