Skip to main content

Crate the_odds_api

Crate the_odds_api 

Source
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

EndpointMethodQuota Cost
Sportsget_sports()Free
Eventsget_events(sport)Free
Oddsget_odds(sport)markets × regions
Scoresget_scores(sport)1 (or 2 with days_from)
Event Oddsget_event_odds(sport, event_id)markets × regions
Event Marketsget_event_markets(sport, event_id)1
Participantsget_participants(sport)1
Historical Oddsget_historical_odds(sport)10 × markets × regions
Historical Eventsget_historical_events(sport)1
Historical Event Oddsget_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.
BookmakerMarkets
Bookmaker with available markets (without odds).
Event
A sporting event.
EventMarkets
Event with bookmaker market availability.
EventOdds
An event with odds from bookmakers.
EventScore
An event with scores.
GetEventMarketsRequest
Request builder for getting event markets.
GetEventOddsRequest
Request builder for getting event odds.
GetEventsRequest
Request builder for getting events.
GetHistoricalEventOddsRequest
Request builder for historical event odds.
GetHistoricalEventsRequest
Request builder for historical events.
GetHistoricalOddsRequest
Request builder for historical odds.
GetOddsRequest
Request builder for getting odds.
GetScoresRequest
Request builder for getting scores.
HistoricalResponse
Wrapper for historical API responses.
MarketInfo
A market entry with its key and last update time (without odds).
MarketOdds
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.
TheOddsApiClient
The main client for interacting with The Odds API.
TheOddsApiClientBuilder
Builder for configuring the API client.
UsageInfo
API usage information from response headers.

Enums§

DateFormat
Date format for API responses.
Error
The main error type for The Odds API SDK.
Market
Market types for odds requests.
OddsFormat
Odds format for API responses.
Region
Region codes for bookmaker filtering.

Type Aliases§

EventId
Event ID type alias for clarity.
Result
A specialized Result type for The Odds API operations.
SportKey
Sport key type alias for clarity.