Expand description
§rithmic-rs
rithmic-rs is a Rust client library for the Rithmic R | Protocol API.
§Features
- Stream real-time market data (trades, quotes, order book depth)
- Submit and manage orders (bracket orders, modifications, cancellations)
- Access historical market data (ticks and time bars)
- Manage risk and track positions and P&L
- Connection health monitoring with heartbeat and forced logout handling
§Quick Start
use rithmic_rs::{
RithmicConfig, RithmicEnv, ConnectStrategy, RithmicTickerPlant,
rti::messages::RithmicMessage,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration from environment variables
let config = RithmicConfig::from_env(RithmicEnv::Demo)?;
// Connect with Simple strategy (recommended default)
let ticker_plant = RithmicTickerPlant::connect(&config, ConnectStrategy::Simple).await?;
let mut handle = ticker_plant.get_handle();
// Login and subscribe to market data
handle.login().await?;
handle.subscribe("ESM1", "CME").await?;
// Process real-time updates
loop {
match handle.subscription_receiver.recv().await {
Ok(update) => {
// Check for connection health issues
if let Some(error) = &update.error {
eprintln!("Error: {}", error);
break;
}
// Process market data
match update.message {
RithmicMessage::LastTrade(trade) => {
println!("Trade: {:?}", trade);
}
RithmicMessage::BestBidOffer(bbo) => {
println!("BBO: {:?}", bbo);
}
_ => {}
}
}
Err(e) => {
eprintln!("Channel error: {}", e);
break;
}
}
}
Ok(())
}§Connection Strategies
The library provides three connection strategies:
ConnectStrategy::Simple: Single connection attempt (recommended default, fast-fail)ConnectStrategy::Retry: Indefinite retries with exponential backoff capped at 60sConnectStrategy::AlternateWithRetry: Alternates between primary and beta URLs
§Configuration
Use RithmicConfig for modern, ergonomic configuration:
use rithmic_rs::{RithmicConfig, RithmicEnv};
fn example() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// From environment variables
let config = RithmicConfig::from_env(RithmicEnv::Demo)?;
// Or using builder pattern
let config = RithmicConfig::builder(RithmicEnv::Demo)
.user("your_user".to_string())
.password("your_password".to_string())
.system_name("Rithmic Paper Trading".to_string())
.build()?;
Ok(())
}§Module Organization
plants: Specialized clients for different data types (ticker, order, P&L, history)config: Configuration API for connecting to Rithmicapi: Low-level API interfaces for sending and receiving messagesrti: Protocol message definitionsws: WebSocket connectivity and connection strategiesutil: Utility types and helpers (timestamps, order status, instrument info)
Re-exports§
pub use plants::history_plant::RithmicHistoryPlant;pub use plants::history_plant::RithmicHistoryPlantHandle;pub use plants::order_plant::RithmicOrderPlant;pub use plants::order_plant::RithmicOrderPlantHandle;pub use plants::pnl_plant::RithmicPnlPlant;pub use plants::pnl_plant::RithmicPnlPlantHandle;pub use plants::ticker_plant::RithmicTickerPlant;pub use plants::ticker_plant::RithmicTickerPlantHandle;pub use config::ConfigError;pub use config::RithmicConfig;pub use config::RithmicEnv;pub use ws::ConnectStrategy;pub use api::BracketDuration;pub use api::BracketPriceType;pub use api::BracketTransactionType;pub use api::EasyToBorrowRequest;pub use api::ModifyPriceType;pub use api::NewOrderDuration;pub use api::NewOrderPriceType;pub use api::NewOrderTransactionType;pub use api::OcoDuration;pub use api::OcoPriceType;pub use api::OcoTransactionType;pub use api::RithmicBracketOrder;pub use api::RithmicCancelOrder;pub use api::RithmicModifyOrder;pub use api::RithmicOcoOrderLeg;pub use api::RithmicResponse;pub use util::InstrumentInfo;pub use util::OrderStatus;pub use util::rithmic_to_unix_nanos;pub use util::rithmic_to_unix_nanos_precise;
Modules§
- api
- Low-level API types for Rithmic communication.
- config
- Configuration API for connecting to Rithmic Configuration for Rithmic connections.
- plants
- Specialized clients (“plants”) for different Rithmic services.
- rti
- Rithmic protocol message definitions (protobuf-generated).
- util
- Utility types for working with Rithmic data. Utility types for working with Rithmic data.
- ws
- WebSocket connectivity layer