Rust Rithmic R | Protocol API client
Unofficial rust client for connecting to Rithmic's R | Protocol API.
Quick Start
Add to your Cargo.toml:
[]
= "0.7.0"
Set your environment variables:
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>
# See examples/.env.blank for Live
Stream live market data:
use ;
async
See examples/ for more usage patterns including reconnection handling and historical data loading.
Architecture
This library uses the actor pattern where each Rithmic service runs independently in its own thread. All communication happens through tokio channels.
RithmicTickerPlant- Real-time market data (trades, quotes, order book)RithmicOrderPlant- Order entry and managementRithmicHistoryPlant- Historical tick and bar dataRithmicPnlPlant- Position and P&L tracking
Ticker Plant
// Subscribe to real-time quotes
handle.subscribe.await?;
// Symbol discovery
let symbols = handle.search_symbols.await?;
let front_month = handle.get_front_month_contract.await?;
Order Plant
// Place orders
handle.place_limit_order.await?;
handle.place_bracket_order.await?;
// Manage positions
handle.cancel_order.await?;
handle.exit_position.await?;
History Plant
// Load historical data (bar_type, period, start_time, end_time as i32 unix seconds)
let bars = handle.load_time_bars.await?;
let ticks = handle.load_ticks.await?;
PnL Plant
// Monitor P&L
handle.subscribe_pnl_updates.await?;
let snapshot = handle.pnl_position_snapshots.await?;
Connection Strategies
Three strategies for initial connection:
Simple: Single attempt, fast-fail (recommended default)Retry: Exponential backoff, capped at 60 secondsAlternateWithRetry: Alternates between primary and alt URLs
Reconnection
If you need to handle disconnections and automatically reconnect, you must implement your own reconnection loop. See examples/reconnect.rs for a complete example that tracks subscriptions and re-subscribes after reconnect.
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.