Rust Rithmic R | Protocol API client
Unofficial rust client for connecting to Rithmic's R | Protocol API.
rithmic protocol version: 0.84.0.0
Not all functionality has been implemented, but this is currently being used to trade live capital through Rithmic.
Only order_plant, ticker_plant, pnl_plant, history_plant are provided. Each plant uses the actor pattern so you'll want to start a plant, and communicate / call commands with it using it's handle. The crate is setup to be used with tokio channels.
The history_plant supports loading both historical tick data and time bar data (1-second, 1-minute, 5-minute, daily, and weekly bars).
Installation
You can install it from crates.io
$ cargo add rithmic-rs
Or manually add it to your Cargo.toml file.
[dependencies]
rithmic-rs = "0.5.1"
Breaking Changes in 0.5.0
Version 0.5.0 introduces breaking changes for improved stability and error handling:
- Plant constructors changed from
new()toconnect()with explicit connection strategies - New unified
RithmicConfigAPI replaces separateAccountInfotypes - Heartbeat errors and forced logout events now delivered through subscription channel
📖 See MIGRATION_0.5.0.md for step-by-step migration guide with code examples.
Also see CHANGELOG.md for complete list of changes.
Usage
Configuration
Rithmic supports three types of account environments: RithmicEnv::Demo for paper trading, RithmicEnv::Live for funded accounts, and RithmicEnv::Test for the test environment before app approval.
Configure your connection using the builder pattern:
use ;
let config = builder
.user
.password
.system_name
.env
.build?;
Alternatively, you can load from environment variables using from_env():
let config = from_env?;
Required environment variables for from_env():
# For Demo environment
RITHMIC_DEMO_USER=your_username
RITHMIC_DEMO_PW=your_password
# For Live environment
RITHMIC_LIVE_USER=your_username
RITHMIC_LIVE_PW=your_password
# For Test environment
RITHMIC_TEST_USER=your_username
RITHMIC_TEST_PW=your_password
Note: The
dotenvdependency will become optional in version 0.6.0. The builder pattern is recommended for new projects.
Connection Strategies
The library provides three connection strategies:
Simple: Single connection attempt (recommended default, fast-fail)Retry: Indefinite retries with exponential backoff capped at 60 secondsAlternateWithRetry: Alternates between primary and beta URLs with retries
Quick Start
To use this crate, create a configuration and connect to a plant with your chosen strategy. Each plant uses the actor pattern and spawns a task that listens to commands via a handle. Plants like the ticker plant also include a broadcast channel for real-time updates.
use ;
async
Heartbeat Monitoring (Optional)
By default, heartbeats are sent automatically but timeout monitoring is disabled. Enable connection health monitoring to detect if the server stops responding:
// Enable connection health monitoring
handle.return_heartbeat_response.await;
// Monitor for heartbeat timeouts (only failures are reported)
loop
Connection Health Verification
When enabled with return_heartbeat_response(true), the library tracks pending heartbeats and reports ONLY failures:
- If heartbeat response arrives within 30 seconds: Silent (connection is healthy)
- If no response after 30 seconds:
HeartbeatTimeoutmessage sent to subscription channel
This "silent success, noisy failure" approach reduces channel noise while ensuring you're alerted to connection issues.
Note: Enable during critical trading periods to verify the connection is alive. Disable during off-hours to avoid false alarms when the server may not respond.
Examples
The repository includes several examples to help you get started:
Environment Variables
Before running examples, copy .env.blank to .env and fill in your credentials:
# Edit .env with your Rithmic credentials
Basic Connection
Historical Data
# Load historical tick data
# Load historical time bars (1-minute, 5-minute, daily)
Contribution
Contributions encouraged and welcomed!
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.