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.6.0"
Breaking Changes
Version 0.6.0 (Latest)
- Removed deprecated
connection_infomodule (useRithmicConfiginstead) - Removed
return_heartbeat_response()method (connection health now automatic) - Updated to
dotenvycrate (from deprecateddotenv) - Plant constructors use
connect()with explicit connection strategies - Connection health events delivered through subscription channel
📖 See MIGRATION_0.6.0.md for migration guide from 0.4.x or 0.5.x.
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_ACCOUNT_ID=your_account_id
RITHMIC_DEMO_FCM_ID=your_fcm_id
RITHMIC_DEMO_IB_ID=your_ib_id
RITHMIC_DEMO_USER=your_username
RITHMIC_DEMO_PW=your_password
RITHMIC_DEMO_URL=<provided_by_rithmic>
RITHMIC_DEMO_ALT_URL=<provided_by_rithmic>
# For Live environment
RITHMIC_LIVE_ACCOUNT_ID=your_account_id
RITHMIC_LIVE_FCM_ID=your_fcm_id
RITHMIC_LIVE_IB_ID=your_ib_id
RITHMIC_LIVE_USER=your_username
RITHMIC_LIVE_PW=your_password
RITHMIC_LIVE_URL=<provided_by_rithmic>
RITHMIC_LIVE_ALT_URL=<provided_by_rithmic>
# For Test environment
RITHMIC_TEST_ACCOUNT_ID=your_account_id
RITHMIC_TEST_FCM_ID=your_fcm_id
RITHMIC_TEST_IB_ID=your_ib_id
RITHMIC_TEST_USER=your_username
RITHMIC_TEST_PW=your_password
RITHMIC_TEST_URL=<provided_by_rithmic>
RITHMIC_TEST_ALT_URL=<provided_by_rithmic>
See examples/.env.blank for a template with all required variables and connection URLs.
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
Connection Health Monitoring
Connection health is monitored automatically via WebSocket ping/pong. Monitor the subscription channel for health events:
loop
Connection Health Events:
HeartbeatTimeout: Server heartbeat error or WebSocket ping timeoutForcedLogout: Server-initiated disconnectionConnectionError: WebSocket connection failure
Examples
The repository includes several examples to help you get started. Examples use environment variables for configuration - set the required variables (listed above) in your environment or use a .env file.
Basic Connection
Market Data
# Stream live market data
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.