knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width=16, 
  fig.height=8
)
library(gtExtras)
library(gt)
library(knitr)
library(dplyr)

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("sportsdataverse/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:

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.

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))

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))

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

oddsapiR::toa_sports_odds(sport_key = 'basketball_nba', 
                          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()

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 = 'basketball_nba', 
                            days_from = NULL,
                            date_format = 'iso') %>% 
  head(n=20) %>% 
  knitr::kable()

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}
}


saiemgilani/oddsapiR documentation built on March 20, 2023, 5:48 p.m.