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
.
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)
The Odds API requires an API key, here's a quick run-down:
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.
ODDS_API_KEY
(with quotations) using a command like the following.Sys.setenv(ODDS_API_KEY = "XXXX-YOUR-API-KEY-HERE-XXXXX")
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))
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()
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} }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.