Rust Rithmic R | Protocol API client
Unofficial rust client for connecting to Rithmic's R | Protocol API.
Setup
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.2"
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.
There are two ways to configure your connection: loading from environment variables (recommended) or using the builder pattern programmatically.
Load configuration from environment variables:
use ;
let config = from_env?;
Required environment variables:
# 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.
Alternatively, configure using the builder pattern:
use ;
let config = builder
.user
.password
.system_name
.env
.build?;
Connection Strategies
The library provides three connection strategies for initial connection:
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
Note: These strategies are for establishing the initial connection only. If you need to reconnect after a connection is lost, you must listen for disconnection events and manually reconnect:
use ;
async
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
Plants
Rithmic's API is organized into specialized services called "plants". Each plant uses the actor pattern - you connect to a plant and communicate with it via a handle using tokio channels.
Design Philosophy
This library intentionally does not provide a single unified client that manages all plants. Instead, each plant is an independent actor that you connect to and manage separately. This design choice prioritizes flexibility over convenience:
- Thread/task distribution: Run different plants on different threads or async tasks based on your performance needs
- Selective connectivity: Connect only to the plants you need (e.g., market data only, no order management)
- Independent lifecycle: Each plant can be started, stopped, and reconnected independently
- Resource control: Fine-grained control over connection pooling and resource allocation
The trade-off is reduced usability - you must manage multiple connections and handles yourself rather than having a single client object. For most applications, this flexibility is worth the additional setup code.
Ticker Plant
Real-time market data streaming:
- Market data subscriptions: Last trades, best bid/offer (BBO), order book depth
- Symbol discovery: Search symbols, list exchanges, get instruments by underlying
- Reference data: Tick size tables, product codes, front month contracts, volume at price
Order Plant
Order management and execution:
- Order types: Market, limit, bracket orders, OCO (one-cancels-other) orders
- Order operations: Place, modify, cancel orders, exit positions
- Order tracking: Subscribe to order updates, show active orders, order history
- Risk management: Account/product RMS info, trade routes, easy-to-borrow lists
- Agreements: List, accept, and manage exchange agreements
PnL Plant
Profit and loss monitoring:
- Position snapshots: Current P&L for all positions
- Real-time updates: Subscribe to account and instrument-level P&L changes
History Plant
Historical market data:
- Tick data: Load historical tick-by-tick data for any time range
- Time bars: 1-second, 1-minute, 5-minute, daily, and weekly bars
- Volume profile: Minute bars with volume profile data
- Bar subscriptions: Subscribe to real-time time bar and tick bar updates
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)
Upgrading
See CHANGELOG.md for version history and MIGRATION_0.6.0.md for migration guides.
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 below, without any additional terms or conditions.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.