Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Nautechsystems Nautilus trader TradingNode Build Run

From Leeroopedia


Field Value
sources https://github.com/nautechsystems/nautilus_trader, https://nautilustrader.io/docs/
domains algorithmic trading, system lifecycle, asynchronous programming
last_updated 2026-02-10 12:00 GMT

Overview

Concrete tool for building and running a live trading node provided by NautilusTrader.

Description

After constructing a TradingNode and registering client factories, the operator drives the lifecycle through three primary methods:

  • build() -- Invokes the TradingNodeBuilder to instantiate data and execution clients from registered factories. Sets the _is_built flag. Raises RuntimeError if called twice.
  • run(raise_exception=False) -- Synchronous entry point. If the event loop is already running, creates an async task for run_async(); otherwise blocks on loop.run_until_complete(run_async()). Optionally re-raises runtime exceptions.
  • run_async() -- Asynchronous entry point. Validates that the node is built, starts the kernel (which connects clients, loads instruments, runs reconciliation, starts strategies), then gathers all engine queue tasks. Optionally spawns an external message streaming task. The method completes only when all queue tasks finish (i.e., on shutdown).

Supporting lifecycle methods include:

  • stop() / stop_async() -- Triggers graceful shutdown of the kernel.
  • dispose() -- Cancels streaming tasks, disposes the kernel, shuts down the executor, and stops or closes the event loop, all within a configurable disconnection timeout.

Usage

Call build() once after registering all factories, then call run() or await run_async() to start the live trading process. The node will run until a stop signal is received (SIGINT, SIGTERM, or a programmatic call to stop()).

Code Reference

Source Location

Item Path
build() nautilus_trader/live/node.py lines 272-281
run() nautilus_trader/live/node.py lines 283-303
run_async() nautilus_trader/live/node.py lines 338-379
stop() / stop_async() nautilus_trader/live/node.py lines 381-407
dispose() nautilus_trader/live/node.py lines 409-473

Signature

def build(self) -> None: ...

def run(self, raise_exception: bool = False) -> None: ...

async def run_async(self) -> None: ...

def stop(self) -> None: ...

async def stop_async(self) -> None: ...

def dispose(self) -> None: ...

Import

from nautilus_trader.live.node import TradingNode

I/O Contract

build()

Parameter Type Required Description
(none) -- -- Uses internal config and registered factories.
Output Type Description
(none) None Side effect: data and execution clients are instantiated and registered with their respective engines.

run()

Parameter Type Required Description
raise_exception bool No If True, runtime exceptions are re-raised in addition to being logged. Default False.
Output Type Description
(none) None Blocks until the node is stopped (sync mode) or schedules an async task (if loop is already running).

run_async()

Parameter Type Required Description
(none) -- -- --
Output Type Description
(none) None Awaitable coroutine that runs until all engine queue tasks complete.

Errors

Exception Condition
RuntimeError build() called when node is already built.
RuntimeError run_async() called when node has not been built.

Usage Examples

Standard Synchronous Deployment

from nautilus_trader.live.node import TradingNode
from nautilus_trader.config import TradingNodeConfig

config = TradingNodeConfig(trader_id="TRADER-001")
node = TradingNode(config=config)

# ... register factories ...

node.build()
try:
    node.run()
finally:
    node.dispose()

Async Deployment (e.g., Jupyter Notebook)

import asyncio
from nautilus_trader.live.node import TradingNode
from nautilus_trader.config import TradingNodeConfig

config = TradingNodeConfig(trader_id="TRADER-001")
node = TradingNode(config=config)

# ... register factories ...

node.build()
await node.run_async()

Programmatic Stop

import asyncio

async def run_for_duration(node, seconds):
    node.build()
    task = asyncio.ensure_future(node.run_async())
    await asyncio.sleep(seconds)
    node.stop()
    await task
    node.dispose()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment