Skip to contents

Welcome folks,

I’m Saiem Gilani, one of the authors of oddsapiR, and I hope to give the community a high-quality resource for accessing The Odds API.

Install oddsapiR

# You can install using the pacman package using the following code:
if (!requireNamespace('pacman', quietly = TRUE)){
  install.packages('pacman')
}
pacman::p_load_current_gh("saiemgilani/oddsapiR", dependencies = TRUE, update = TRUE)
pacman::p_load_current_gh("jthomasmock/gtExtras", dependencies = TRUE, update = TRUE)
pacman::p_load(dplyr, knitr, gt)

Odds API Keys

The Odds API requires an API key, here’s a quick run-down:

  • Using the key: You can save the key for consistent usage by adding ODDS_API_KEY=XXXX-YOUR-API-KEY-HERE-XXXXX to your .Renviron file (easily accessed via usethis::edit_r_environ()). Run usethis::edit_r_environ(), a new script will pop open named .Renviron, THEN paste the following in the new script that pops up (without quotations)
ODDS_API_KEY = XXXX-YOUR-API-KEY-HERE-XXXXX

Save the script and restart your RStudio session, by clicking Session (in between Plots and Build) and click Restart R (there also exists the shortcut Ctrl + Shift + F10 to restart your session). If set correctly, from then on you should be able to use any of the functions without any other changes.

  • For less consistent usage: At the beginning of every session or within an R environment, save your API key as the environment variable ODDS_API_KEY (with quotations) using a command like the following.
Sys.setenv(ODDS_API_KEY = "XXXX-YOUR-API-KEY-HERE-XXXXX")

The included data

toa_sports_keys - The sports for which The Odds API provides coverage

oddsapiR::toa_sports_keys %>%
  gt() %>% 
  gtExtras::gt_theme_538(table.width = px(650))
key group title description has_outrights
americanfootball_ncaaf American Football NCAAF US College Football FALSE
americanfootball_nfl American Football NFL US Football FALSE
americanfootball_nfl_super_bowl_winner American Football NFL Super Bowl Winner Super Bowl Winner 2022/2023 TRUE
aussierules_afl Aussie Rules AFL Aussie Football FALSE
baseball_mlb Baseball MLB Major League Baseball FALSE
baseball_mlb_world_series_winner Baseball MLB World Series Winner World Series Winner 2022 TRUE
basketball_euroleague Basketball Basketball Euroleague Basketball Euroleague FALSE
basketball_nba Basketball NBA US Basketball FALSE
basketball_nba_championship_winner Basketball NBA Championship Winner Championship Winner 2021/2022 TRUE
basketball_ncaab Basketball NCAAB US College Basketball FALSE
basketball_wnba Basketball WNBA US Basketball FALSE
cricket_big_bash Cricket Big Bash Big Bash League FALSE
cricket_icc_world_cup Cricket ICC World Cup ICC World Cup FALSE
cricket_ipl Cricket IPL Indian Premier League FALSE
cricket_odi Cricket One Day Internationals One Day Internationals FALSE
cricket_test_match Cricket Test Matches International Test Matches FALSE
golf_masters_tournament_winner Golf Masters Tournament Winner 2023 Winner TRUE
golf_pga_championship_winner Golf PGA Championship Winner 2022 Winner TRUE
golf_the_open_championship_winner Golf The Open Winner 2022 Winner TRUE
golf_us_open_winner Golf US Open Winner 2022 Winner TRUE
icehockey_nhl Ice Hockey NHL US Ice Hockey FALSE
icehockey_nhl_championship_winner Ice Hockey NHL Championship Winner Stanley Cup Winner 2021/2022 TRUE
icehockey_sweden_allsvenskan Ice Hockey HockeyAllsvenskan Swedish Hockey Allsvenskan FALSE
icehockey_sweden_hockey_league Ice Hockey SHL Swedish Hockey League FALSE
mma_mixed_martial_arts Mixed Martial Arts MMA Mixed Martial Arts FALSE
politics_us_presidential_election_winner Politics US Presidential Elections Winner 2024 US Presidential Election Winner TRUE
rugbyleague_nrl Rugby League NRL Aussie Rugby League FALSE
soccer_africa_cup_of_nations Soccer Africa Cup of Nations Africa Cup of Nations FALSE
soccer_argentina_primera_division Soccer Primera División - Argentina Argentine Primera División FALSE
soccer_australia_aleague Soccer A-League Aussie Soccer FALSE
soccer_belgium_first_div Soccer Belgium First Div Belgian First Division A FALSE
soccer_brazil_campeonato Soccer Brazil Série A Brasileirão Série A FALSE
soccer_china_superleague Soccer Super League - China FALSE
soccer_conmebol_copa_libertadores Soccer Copa Libertadores CONMEBOL Copa Libertadores FALSE
soccer_denmark_superliga Soccer Denmark Superliga FALSE
soccer_efl_champ Soccer Championship EFL Championship FALSE
soccer_england_efl_cup Soccer EFL Cup League Cup FALSE
soccer_england_league1 Soccer League 1 EFL League 1 FALSE
soccer_england_league2 Soccer League 2 EFL League 2 FALSE
soccer_epl Soccer EPL English Premier League FALSE
soccer_fa_cup Soccer FA Cup Football Association Challenge Cup FALSE
soccer_fifa_world_cup Soccer FIFA World Cup FIFA World Cup 2022 FALSE
soccer_fifa_world_cup_winner Soccer FIFA World Cup Winner FIFA World Cup Winner 2022 TRUE
soccer_finland_veikkausliiga Soccer Veikkausliiga - Finland FALSE
soccer_france_ligue_one Soccer Ligue 1 - France FALSE
soccer_france_ligue_two Soccer Ligue 2 - France French Soccer FALSE
soccer_germany_bundesliga Soccer Bundesliga - Germany German Soccer FALSE
soccer_germany_bundesliga2 Soccer Bundesliga 2 - Germany German Soccer FALSE
soccer_italy_serie_a Soccer Serie A - Italy Italian Soccer FALSE
soccer_italy_serie_b Soccer Serie B - Italy Italian Soccer FALSE
soccer_japan_j_league Soccer J League Japan Soccer League FALSE
soccer_korea_kleague1 Soccer K League 1 Korean Soccer FALSE
soccer_league_of_ireland Soccer League of Ireland Airtricity League Premier Division FALSE
soccer_mexico_ligamx Soccer Liga MX Mexican Soccer FALSE
soccer_netherlands_eredivisie Soccer Dutch Eredivisie Dutch Soccer FALSE
soccer_norway_eliteserien Soccer Eliteserien - Norway Norwegian Soccer FALSE
soccer_portugal_primeira_liga Soccer Primeira Liga - Portugal Portugese Soccer FALSE
soccer_russia_premier_league Soccer Premier League - Russia Russian Soccer FALSE
soccer_spain_la_liga Soccer La Liga - Spain Spanish Soccer FALSE
soccer_spain_segunda_division Soccer La Liga 2 - Spain Spanish Soccer FALSE
soccer_spl Soccer Premiership - Scotland Scottish Premiership FALSE
soccer_sweden_allsvenskan Soccer Allsvenskan - Sweden Swedish Soccer FALSE
soccer_sweden_superettan Soccer Superettan - Sweden Swedish Soccer FALSE
soccer_switzerland_superleague Soccer Swiss Superleague Swiss Soccer FALSE
soccer_turkey_super_league Soccer Turkey Super League Turkish Soccer FALSE
soccer_uefa_champs_league Soccer UEFA Champions European Champions League FALSE
soccer_uefa_europa_league Soccer UEFA Europa European Europa League FALSE
soccer_uefa_nations_league Soccer UEFA Nations League UEFA Nations League FALSE
soccer_usa_mls Soccer MLS Major League Soccer FALSE
tennis_atp_aus_open_singles Tennis ATP Australian Open Men's Singles FALSE
tennis_atp_french_open Tennis ATP French Open Men's Singles FALSE
tennis_atp_us_open Tennis ATP US Open Men's Singles FALSE
tennis_atp_wimbledon Tennis ATP Wimbledon Men's Singles FALSE
tennis_wta_aus_open_singles Tennis WTA Australian Open Women's Singles FALSE
tennis_wta_french_open Tennis WTA French Open Women's Singles FALSE
tennis_wta_us_open Tennis WTA US Open Women's Singles FALSE
tennis_wta_wimbledon Tennis WTA Wimbledon Women's Singles FALSE

Three core functions

One endpoint for looking up the sports the API provides (including currently active status): toa_sports


oddsapiR::toa_sports(all_sports = TRUE) %>%
  head(n=10) %>% 
  gt() %>% 
  gtExtras::gt_theme_538(table.width = px(550))
key group title description active has_outrights
americanfootball_ncaaf American Football NCAAF US College Football TRUE FALSE
americanfootball_nfl American Football NFL US Football TRUE FALSE
americanfootball_nfl_super_bowl_winner American Football NFL Super Bowl Winner Super Bowl Winner 2022/2023 TRUE TRUE
aussierules_afl Aussie Rules AFL Aussie Football TRUE FALSE
baseball_mlb Baseball MLB Major League Baseball TRUE FALSE
baseball_mlb_world_series_winner Baseball MLB World Series Winner World Series Winner 2022 TRUE TRUE
basketball_euroleague Basketball Basketball Euroleague Basketball Euroleague FALSE FALSE
basketball_nba Basketball NBA US Basketball FALSE FALSE
basketball_nba_championship_winner Basketball NBA Championship Winner Championship Winner 2021/2022 FALSE TRUE
basketball_ncaab Basketball NCAAB US College Basketball FALSE FALSE

One endpoint for looking up the current odds from the API: toa_sports_odds

oddsapiR::toa_sports_odds(sport_key = 'baseball_mlb', 
                          regions = 'us', 
                          markets = 'spreads', 
                          odds_format = 'decimal',
                          date_format = 'iso') %>% 
  dplyr::select(c("bookmaker","market_key", "outcomes_name","outcomes_price","outcomes_point","home_team","away_team","commence_time")) %>% 
  head(n=20) %>% 
  knitr::kable()
bookmaker market_key outcomes_name outcomes_price outcomes_point home_team away_team commence_time
LowVig.ag spreads Cincinnati Reds 1.99 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
LowVig.ag spreads Los Angeles Dodgers 1.92 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
DraftKings spreads Cincinnati Reds 2.00 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
DraftKings spreads Los Angeles Dodgers 1.83 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
FOX Bet spreads Cincinnati Reds 1.95 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
FOX Bet spreads Los Angeles Dodgers 1.87 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
William Hill (US) spreads Cincinnati Reds 1.95 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
William Hill (US) spreads Los Angeles Dodgers 1.87 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
BetUS spreads Cincinnati Reds 2.00 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
BetUS spreads Los Angeles Dodgers 1.83 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
BetOnline.ag spreads Cincinnati Reds 2.00 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
BetOnline.ag spreads Los Angeles Dodgers 1.83 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
FanDuel spreads Cincinnati Reds 2.02 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
FanDuel spreads Los Angeles Dodgers 1.82 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
GTbets spreads Cincinnati Reds 2.00 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
GTbets spreads Los Angeles Dodgers 1.83 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
MyBookie.ag spreads Cincinnati Reds 2.00 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
MyBookie.ag spreads Los Angeles Dodgers 1.83 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
BetMGM spreads Cincinnati Reds 1.91 1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z
BetMGM spreads Los Angeles Dodgers 1.91 -1.5 Cincinnati Reds Los Angeles Dodgers 2022-06-21T22:41:00Z

Note: There are two entries per event per bookmaker for the spreads for both sides of the event.

One endpoint for looking up the current scores from the API: toa_sports_scores

oddsapiR::toa_sports_scores(sport_key = 'baseball_mlb', 
                            days_from = NULL,
                            date_format = 'iso') %>% 
  head(n=20) %>% 
  knitr::kable()
id sport_key sport_title commence_time completed home_team away_team scores last_update
142e714d18883681a61a1367ce5375bd baseball_mlb MLB 2022-06-21T22:41:00Z FALSE Cincinnati Reds Los Angeles Dodgers NA NA
04c47ff0f15258f24f6d39ca4e1d401e baseball_mlb MLB 2022-06-21T22:41:00Z FALSE Miami Marlins Colorado Rockies NA NA
c74d38ee5c259fb98d99ed1cf99e8264 baseball_mlb MLB 2022-06-21T23:05:00Z FALSE Baltimore Orioles Washington Nationals NA NA
3fa4d180ce3ecc3a1a70237ee0306708 baseball_mlb MLB 2022-06-21T23:06:00Z FALSE Pittsburgh Pirates Chicago Cubs NA NA
fa81d1b98ecbcf519800990b9084a39e baseball_mlb MLB 2022-06-21T23:10:00Z FALSE Tampa Bay Rays New York Yankees NA NA
4b77bb1b03f7636b1a1e6417d023315d baseball_mlb MLB 2022-06-21T23:11:00Z FALSE Boston Red Sox Detroit Tigers NA NA
cd26b6bbcf454f3bab9151c0553b6013 baseball_mlb MLB 2022-06-21T23:21:00Z FALSE Atlanta Braves San Francisco Giants NA NA
08ffd3b952778a093bfcc7c09099345d baseball_mlb MLB 2022-06-21T23:41:00Z FALSE Minnesota Twins Cleveland Guardians NA NA
c0e018c0e5dbf402525d14eb0634b92b baseball_mlb MLB 2022-06-22T00:06:00Z FALSE Texas Rangers Philadelphia Phillies NA NA
8095252f9335c1c4b0a2e262cf094e32 baseball_mlb MLB 2022-06-22T00:11:00Z FALSE Chicago White Sox Toronto Blue Jays NA NA
5c942a8684b105e5c6e14fbc2d84b0b2 baseball_mlb MLB 2022-06-22T00:11:00Z FALSE Houston Astros New York Mets NA NA
c6f22fee7fe7f9c98b7f7e88749ebd84 baseball_mlb MLB 2022-06-22T00:12:00Z FALSE Milwaukee Brewers St. Louis Cardinals NA NA
fe7eba596c2b1887cbfcd1b412cf1c73 baseball_mlb MLB 2022-06-22T01:39:00Z FALSE Los Angeles Angels Kansas City Royals NA NA
c9c99c5af13d0f7ebb7b87c35a63fe3d baseball_mlb MLB 2022-06-22T01:41:00Z FALSE San Diego Padres Arizona Diamondbacks NA NA
1b2992c9053f4a602847a7e258aa91a3 baseball_mlb MLB 2022-06-22T01:41:00Z FALSE Oakland Athletics Seattle Mariners NA NA

Our Authors

Citations

To cite the oddsapiR R package in publications, use:

BibTex Citation

@misc{gilani_2022_oddsapiR,
  author = {Gilani, Saiem},
  title = {oddsapiR: The SportsDataverse's R Package for The Odds API.},
  url = {https://oddsapiR.sportsdataverse.org},
  year = {2022}
}