Expand description
§The Odds API Rust SDK
A comprehensive Rust SDK for The Odds API, providing access to sports betting odds, scores, and related data from bookmakers worldwide.
§Features
- Full coverage of The Odds API v4 endpoints
- Strongly-typed request parameters and responses
- Builder pattern for flexible request configuration
- Async/await support with
reqwest - API usage tracking via response headers
- Comprehensive error handling
§Quick Start
use the_odds_api::{TheOddsApiClient, Region, Market};
#[tokio::main]
async fn main() -> the_odds_api::Result<()> {
// Create a client with your API key
let client = TheOddsApiClient::new("your-api-key");
// Get all in-season sports
let sports = client.get_sports().await?;
println!("Found {} sports", sports.data.len());
// Get NFL odds from US bookmakers
let odds = client
.get_odds("americanfootball_nfl")
.regions(&[Region::Us])
.markets(&[Market::H2h, Market::Spreads])
.send()
.await?;
// Check API usage
println!("Requests remaining: {:?}", odds.usage.requests_remaining);
Ok(())
}§Endpoints
| Endpoint | Method | Quota Cost |
|---|---|---|
| Sports | get_sports() | Free |
| Events | get_events(sport) | Free |
| Odds | get_odds(sport) | markets × regions |
| Scores | get_scores(sport) | 1 (or 2 with days_from) |
| Event Odds | get_event_odds(sport, event_id) | markets × regions |
| Event Markets | get_event_markets(sport, event_id) | 1 |
| Participants | get_participants(sport) | 1 |
| Historical Odds | get_historical_odds(sport) | 10 × markets × regions |
| Historical Events | get_historical_events(sport) | 1 |
| Historical Event Odds | get_historical_event_odds(sport, event_id) | markets × regions |
§Configuration
Use the builder pattern for advanced configuration:
use the_odds_api::TheOddsApiClient;
let client = TheOddsApiClient::builder("your-api-key")
.use_ipv6() // Use IPv6 endpoint
.build();Structs§
- Bookmaker
- A bookmaker with odds for various markets.
- Bookmaker
Markets - Bookmaker with available markets (without odds).
- Event
- A sporting event.
- Event
Markets - Event with bookmaker market availability.
- Event
Odds - An event with odds from bookmakers.
- Event
Score - An event with scores.
- GetEvent
Markets Request - Request builder for getting event markets.
- GetEvent
Odds Request - Request builder for getting event odds.
- GetEvents
Request - Request builder for getting events.
- GetHistorical
Event Odds Request - Request builder for historical event odds.
- GetHistorical
Events Request - Request builder for historical events.
- GetHistorical
Odds Request - Request builder for historical odds.
- GetOdds
Request - Request builder for getting odds.
- GetScores
Request - Request builder for getting scores.
- Historical
Response - Wrapper for historical API responses.
- Market
Info - A market entry with its key and last update time (without odds).
- Market
Odds - Odds for a specific market from a bookmaker.
- Outcome
- An outcome/selection within a market.
- Participant
- A participant (team or player) in a sport.
- Response
- A response with data and API usage information.
- Score
- Score for a team in an event.
- Sport
- A sport available in the API.
- TheOdds
ApiClient - The main client for interacting with The Odds API.
- TheOdds
ApiClient Builder - Builder for configuring the API client.
- Usage
Info - API usage information from response headers.
Enums§
- Date
Format - Date format for API responses.
- Error
- The main error type for The Odds API SDK.
- Market
- Market types for odds requests.
- Odds
Format - Odds format for API responses.
- Region
- Region codes for bookmaker filtering.