Expand description
§betfair-rs
A high-performance Rust library for interacting with the Betfair Exchange API, featuring real-time market data streaming, order management, and an interactive terminal dashboard for trading.
§Quick Start
use betfair_rs::{BetfairClient, Config};
use betfair_rs::dto::market::{MarketFilter, ListMarketCatalogueRequest};
// Load configuration from config.toml
let config = Config::new()?;
// Create API client and login
let mut client = BetfairClient::new(config);
client.login().await?;
// List available sports (event types)
let sports = client.list_sports(None).await?;
// Get markets for a specific event type
let filter = MarketFilter {
event_type_ids: Some(vec!["1".to_string()]), // Soccer
..Default::default()
};
let request = ListMarketCatalogueRequest {
filter,
market_projection: None,
sort: None,
max_results: Some(10),
locale: None,
};
let markets = client.list_market_catalogue(request).await?;
§Features
- REST API Client: Complete implementation of Betfair’s JSON-RPC API
- Real-time Streaming: WebSocket streaming for live market data and orderbook updates
- Order Management: Place, cancel, and monitor orders programmatically
- Rate Limiting: Built-in rate limiting to respect API limits
- Retry Logic: Automatic retry with exponential backoff for transient failures
- Terminal Dashboard: Interactive TUI for real-time trading (binary included)
§Configuration
Create a config.toml
file in your project root:
[betfair]
username = "your_username"
password = "your_password"
api_key = "your_api_key"
pem_path = "/path/to/certificate.pem"
§Example: Streaming Market Data
use betfair_rs::{BetfairClient, StreamingClient, Config};
use std::time::Duration;
let config = Config::new()?;
let mut api_client = BetfairClient::new(config.clone());
api_client.login().await?;
let session_token = api_client.get_session_token()
.ok_or_else(|| anyhow::anyhow!("No session token"))?;
let mut streaming_client = StreamingClient::with_session_token(
config.betfair.api_key.clone(),
session_token
);
streaming_client.start().await?;
streaming_client.subscribe_to_market("1.234567".to_string(), 10).await?;
let orderbooks = streaming_client.get_orderbooks();
Re-exports§
pub use api_client::RestClient;
pub use config::Config;
pub use streaming_client::StreamingClient;
pub use unified_client::BetfairClient;
Modules§
- account
- api_
client - config
- connection_
state - dto
- msg_
model - order
- order_
cache - orderbook
- streaming_
client - unified_
client