betfair-rs

Crates.iobetfair-rs
lib.rsbetfair-rs
version0.3.3
created_at2025-03-30 08:58:59.712912+00
updated_at2025-10-02 19:43:01.520303+00
descriptionA high-performance Rust library for the Betfair Exchange API with real-time streaming, order management, and interactive terminal dashboard
homepagehttps://github.com/t2o2/betfair-rs
repositoryhttps://github.com/t2o2/betfair-rs
max_upload_size
id1612190
size1,922,867
Chuan (t2o2)

documentation

https://docs.rs/betfair-rs

README

betfair-rs

Unit Tests Release Crates.io Documentation License: MIT

A Rust library for interacting with the Betfair Exchange API, providing trading capabilities, real-time market data streaming, and order management.

Features

  • REST API Client with built-in rate limiting and retry logic
  • WebSocket Streaming for real-time market data and order updates
  • Interactive Terminal Dashboard for live trading
  • Async/await patterns with Tokio runtime
  • Comprehensive error handling with anyhow
  • Modular architecture with unified client design

Installation

Add to your Cargo.toml:

[dependencies]
betfair-rs = { git = "https://github.com/t2o2/betfair-rs" }

Quick Start

Configuration

Create a config.toml file:

[betfair]
username = "your_username"
password = "your_password"
api_key = "your_api_key"
pem_path = "/path/to/client.pem"  # Combined cert + private key

Basic Usage

use betfair_rs::BetfairClient;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Initialize client
    let client = BetfairClient::from_config_file("config.toml").await?;

    // Get markets
    let markets = client.list_market_catalogue(None).await?;

    // Stream market data
    client.subscribe_markets(vec!["1.123456".to_string()]).await?;

    Ok(())
}

Dashboard

Run the interactive terminal UI for real-time trading:

cargo run -- dashboard

Dashboard Screenshot

Features:

  • Real-time market data streaming
  • Live orderbook with bid/ask ladder
  • Order placement and management
  • Account balance tracking
  • Vim-style keyboard navigation

CLI Commands

# Stream market data
cargo run -- stream 1.123456 1.789012 --depth 10

# Run examples
cargo run --example streaming_orderbook
cargo run --example interactive_login_test

Architecture

  • BetfairClient: Unified client combining REST and streaming
  • RestClient: JSON-RPC REST API with rate limiting
  • StreamingClient: WebSocket real-time data streaming
  • Rate Limiting: Automatic throttling per endpoint type
  • Authentication: Certificate-based or interactive login

Development

# Build
cargo build

# Run tests
cargo test

# Lint
cargo clippy

# Format
cargo fmt

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Commit count: 78

cargo fmt