#trading #betting

bin+lib betfair-rs

A high-performance Rust library for the Betfair Exchange API with real-time streaming, order management, and interactive terminal dashboard

6 releases

0.3.3 Oct 2, 2025
0.3.2 Oct 1, 2025
0.3.1 Sep 30, 2025
0.2.0 Sep 14, 2025
0.1.0 Mar 30, 2025

#169 in Finance

Download history 3/week @ 2025-08-18 2/week @ 2025-08-25 70/week @ 2025-09-08 86/week @ 2025-09-15 3/week @ 2025-09-22 444/week @ 2025-09-29 62/week @ 2025-10-06 11/week @ 2025-10-13 2/week @ 2025-10-20 63/week @ 2025-11-17

63 downloads per month

MIT license

1.5MB
5.5K SLoC

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.

Dependencies

~27–47MB
~799K SLoC