Get Started with Lighter
Lighter is available through the Rust engine. You can use it from a pure Rust project, or from
Python through PyO3 bindings that expose the same Rust data and execution clients to a Python
LiveNode.
The shortest path is to start with public data. Once data subscriptions work, add execution credentials and then add a strategy that can submit orders.
Choose a setup path
| Path | Use when | First step |
|---|---|---|
| Pure Rust | You want a compiled app with no Python runtime. | Copy the Rust quickstart. |
| Python | You want Python scripts on the Rust engine. | Run the Python data tester. |
| RWA example | You want Databento signal data and Lighter trading. | Read the composite market making tutorial. |
Start from these files:
- Rust quickstart:
examples/quickstarts/lighter-rust-data-client/. - Python data tester:
examples/live/lighter/data_tester.py. - RWA tutorial: Composite market making tutorial.
The Rust and Python paths both use these pieces:
LighterDataClientConfigselects mainnet or testnet and optional transport settings.LighterExecClientConfigadds trader/account IDs and resolves credentials.LighterDataClientFactoryandLighterExecutionClientFactoryregister clients withLiveNode.DataTesterandExecTesterprovide smoke-test actors before you write a custom strategy.
Pure Rust starter
Copy the quickstart into your own workspace:
cp -R examples/quickstarts/lighter-rust-data-client ~/lighter-rust-data-client
cd ~/lighter-rust-data-client
cargo runThis builds a LiveNode, registers the Lighter data client, adds a DataTester, and connects to
testnet public streams. Stop it with Ctrl+C.
The core setup uses builders, which fill in optional defaults for you:
let data_config = LighterDataClientConfig::builder()
.environment(LighterEnvironment::Testnet)
.build();
let mut node = LiveNode::builder(trader_id, Environment::Live)?
.with_name("LIGHTER-DATA-STARTER-001".to_string())
.add_data_client(
None,
Box::new(LighterDataClientFactory::new()),
Box::new(data_config),
)?
.build()?;After the data path works, add an execution client to the builder before calling .build():
let exec_config = LighterExecClientConfig::builder()
.trader_id(trader_id)
.account_id(account_id)
.environment(LighterEnvironment::Testnet)
.build();
let mut node = LiveNode::builder(trader_id, Environment::Live)?
.with_name("LIGHTER-EXEC-STARTER-001".to_string())
.add_data_client(
None,
Box::new(LighterDataClientFactory::new()),
Box::new(data_config),
)?
.add_exec_client(
None,
Box::new(LighterExecutionClientFactory::new()),
Box::new(exec_config),
)?
.build()?;For execution, set the matching environment variables before connecting:
export LIGHTER_TESTNET_ACCOUNT_INDEX="123456"
export LIGHTER_TESTNET_API_KEY_INDEX="0"
export LIGHTER_TESTNET_API_SECRET="your-lighter-api-secret"Use LIGHTER_ACCOUNT_INDEX, LIGHTER_API_KEY_INDEX, and LIGHTER_API_SECRET for mainnet.
Python starter
Python uses the Rust engine through PyO3. Install a Python development wheel outside a source checkout, or build the package from source before running these examples. See Python installation.
From the repository root with Python installed:
.venv/bin/python examples/live/lighter/data_tester.py --lighter-environment testnetThat command builds the node and exits. Pass --run to connect:
.venv/bin/python examples/live/lighter/data_tester.py \
--lighter-environment testnet \
--instrument BTC-PERP.LIGHTER \
--runThe Python script mirrors the Rust setup:
builder = LiveNode.builder(
"LIGHTER-DATA-TESTER-001",
TraderId.from_str("TESTER-001"),
Environment.LIVE,
).add_data_client(
None,
LighterDataClientFactory(),
LighterDataClientConfig(environment=LighterEnvironment.TESTNET),
)Use the execution tester only after the data tester works:
.venv/bin/python examples/live/lighter/exec_tester.py \
--lighter-environment testnet \
--instrument DOGE-PERP.LIGHTERLike the data tester, that command builds the node and exits. Pass --run to connect in dry-run
mode, then add --live-orders to submit real orders.
Move to a strategy
The starter paths prove client wiring, subscriptions, and credential lookup. The next step is to replace the tester with a strategy:
- Use Write a Strategy (Rust) for a pure Rust strategy.
- Use
examples/live/lighter/nvda_composite_mm.pyfor Python node wiring with the built-in RustCompositeMarketMakerstrategy. - Use Composite market making on Lighter RWA when you need the full Databento signal setup.
Rust execution examples can submit live orders when you set DRY_RUN to false. Python execution
examples can submit live orders when you pass --run --live-orders. Start on testnet or use the
smallest accepted size, and confirm the instrument, environment, account index, API key index, and
private key before you run.
For emergency cleanup, cargo run --bin lighter-flatten -p nautilus-lighter cancels open orders
and closes positions for the configured Lighter account. Review it before use because it scans the
account, can take several minutes under the standard 60 req/min quota, and affects more than one
strategy or market when the account has broader exposure.
Configure a Live Trading Node
Set up a LiveNode for live market connectivity. For the node lifecycle, see Live trading. For command outcomes, see Execution. For state recovery, see...
Write an Actor (Rust)
An actor receives market data, custom data/signals, and system events but does not manage orders. This guide walks through building a SpreadMonitor that...