Title: | Access Live Sports Odds from the Odds API |
---|---|
Description: | A utility to quickly obtain clean and tidy sports odds from The Odds API <https://the-odds-api.com>. |
Authors: | Saiem Gilani [aut, cre] |
Maintainer: | Saiem Gilani <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.3 |
Built: | 2024-11-08 03:27:43 UTC |
Source: | https://github.com/sportsdataverse/oddsapir |
This is a thin wrapper on data.table::fread
csv_from_url(...)
csv_from_url(...)
... |
passed to data.table::fread |
a dataframe as created by data.table::fread()
This function helps add progress-reporting to any function - given function f()
and progressor p()
, it will return a new function that calls f()
and then (on-exiting) will call p()
after every iteration.
progressively(f, p = NULL)
progressively(f, p = NULL)
f |
a function to add progressr functionality to. |
p |
a progressor function as created by |
This is inspired by purrr's safely
, quietly
, and possibly
function decorators.
a function that does the same as f
but it calls p()
after iteration.
Load .rds file from a remote connection
rds_from_url(url)
rds_from_url(url)
url |
a character url |
a dataframe as created by readRDS()
Save your API Key as a system environment variable ODDS_API_KEY
toa_key() has_toa_key() check_toa_key()
toa_key() has_toa_key() check_toa_key()
To get access to an API key, follow the instructions at https://the-odds-api.com
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 toa_
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")
Called as a side-effect to ensure that a user has an API key stored in their environment before making a call to the Odds API service.
Get the odds for the sports which the Odds API provides coverage
try(toa_sports_odds(sport_key = 'baseball_mlb', regions = 'us', markets = 'spreads', odds_format = 'decimal', date_format = 'iso'))
toa_event_odds( sport_key, event_id, regions = "us", markets = "spreads", odds_format = "decimal", date_format = "iso", bookmakers = NULL )
toa_event_odds( sport_key, event_id, regions = "us", markets = "spreads", odds_format = "decimal", date_format = "iso", bookmakers = NULL )
sport_key |
The |
event_id |
The |
regions |
The region to pull odds from. Options include:
|
markets |
The type of odds to return. Multiple can be specified if comma delimited. Options include:
NFL Player Props:
NBA + NCAAB Player Props:
NHL Player Props:
|
odds_format |
The format in which to return odds. Options include:
|
date_format |
Date format. Options include:
|
bookmakers |
Comma-separated list of bookmakers to be returned. If both bookmakers and regions are specified, bookmakers takes precendence. Bookmakers can be from any region. Every group of 10 bookmakers counts as 1 request. For example for a single market, specifying up to 10 bookmakers counts as 1 request. Specifying between 11 and 20 bookmakers counts as 2 requests |
try(toa_event_odds(sport_key = 'basketball_ncaab', event_id = '48db9c3293a52baab881d95d38f37a98', regions = 'us', markets = 'player_points', odds_format = 'decimal', date_format = 'iso'))
Sports for which The Odds API provides betting information for as a tibble:
col_name | types |
id | character |
sport_key | character |
sport_title | character |
commence_time | character |
home_team | character |
away_team | character |
bookmaker_key | character |
bookmaker | character |
last_update | character |
market_key | character |
outcomes_name | character |
outcomes_price | numeric |
outcomes_point | numeric |
Get your usage and remaining calls for your key from The Odds API
toa_requests()
toa_requests()
toa_requests()
Returns a tibble of The Odds API key usage with the following columns:
col_name | types |
requests_remaining | integer |
requests_used | integer |
Get the Sports for which the Odds API provides coverage
toa_sports(all_sports=TRUE)
toa_sports(all_sports = TRUE)
toa_sports(all_sports = TRUE)
all_sports |
(Logical required): If true, returns all sports and if false, returns only active sports. Defaults to true. |
Sports for which The Odds API provides betting information for as a tibble:
col_name | types |
key | character |
group | character |
title | character |
description | character |
active | logical |
has_outrights | logical |
try(toa_sports(all_sports = TRUE))
try(toa_sports(all_sports = TRUE))
A data set mapping Sports Events/League names to keys for end-user ease.
data(toa_sports_keys)
data(toa_sports_keys)
A data frame with 5 variables:
key - Sport key group - Sport group (non-league description) title - Sport title description - Sport description has_outrights - Whether the sport or event has outright victories.
Get the odds for the sports which the Odds API provides coverage
try(toa_sports_odds(sport_key = 'baseball_mlb', regions = 'us', markets = 'spreads', odds_format = 'decimal', date_format = 'iso'))
toa_sports_odds( sport_key, regions = "us", markets = "spreads", odds_format = "decimal", date_format = "iso" )
toa_sports_odds( sport_key, regions = "us", markets = "spreads", odds_format = "decimal", date_format = "iso" )
sport_key |
The |
regions |
The region to pull odds from. Options include:
|
markets |
The type of odds to return. Multiple can be specified if comma delimited. Options include:
|
odds_format |
The format in which to return odds. Options include:
|
date_format |
Date format. Options include:
|
Sports for which The Odds API provides betting information for as a tibble:
col_name | types |
id | character |
sport_key | character |
sport_title | character |
commence_time | character |
home_team | character |
away_team | character |
bookmaker_key | character |
bookmaker | character |
last_update | character |
market_key | character |
outcomes_name | character |
outcomes_price | numeric |
outcomes_point | numeric |
try(toa_sports_odds(sport_key = 'basketball_ncaab', regions = 'us', markets = 'spreads', odds_format = 'decimal', date_format = 'iso'))
try(toa_sports_odds(sport_key = 'basketball_ncaab', regions = 'us', markets = 'spreads', odds_format = 'decimal', date_format = 'iso'))
Get the odds history for the sports which the Odds API provides coverage
try(toa_sports_odds(sport_key = 'baseball_mlb', regions = 'us', markets = 'spreads', odds_format = 'decimal', date_format = 'iso'))
toa_sports_odds_history( sport_key, event_ids, date, regions = "us", markets = "spreads", odds_format = "decimal", date_format = "iso", bookmakers = NULL )
toa_sports_odds_history( sport_key, event_ids, date, regions = "us", markets = "spreads", odds_format = "decimal", date_format = "iso", bookmakers = NULL )
sport_key |
The |
event_ids |
The |
date |
The timestamp of the data snapshot to be returned, specified in ISO8601 format. The historical odds API will return the closest snapshot equal to or earlier than the provided date parameter Example : 2022-10-10T12:15:00Z |
regions |
The region to pull odds from. Options include:
|
markets |
The type of odds to return. Multiple can be specified if comma delimited. Options include:
|
odds_format |
The format in which to return odds. Options include:
|
date_format |
Date format. Options include:
|
bookmakers |
Comma-separated list of bookmakers to be returned. If both bookmakers and regions are specified, bookmakers takes precendence. Bookmakers can be from any region. Every group of 10 bookmakers counts as 1 request. For example for a single market, specifying up to 10 bookmakers counts as 1 request. Specifying between 11 and 20 bookmakers counts as 2 requests |
try(toa_sports_odds_history(sport_key = 'basketball_ncaab', event_ids = '48db9c3293a52baab881d95d38f37a98', date = '2023-03-18T12:15:00Z', regions = 'us', markets = 'spreads', odds_format = 'decimal', date_format = 'iso', bookmakers = NULL))
Sports for which The Odds API provides betting information for as a tibble:
col_name | types |
id | character |
sport_key | character |
sport_title | character |
commence_time | character |
home_team | character |
away_team | character |
bookmaker_key | character |
bookmaker | character |
last_update | character |
market_key | character |
outcomes_name | character |
outcomes_price | numeric |
outcomes_point | numeric |
Get the scores for the sports which the Odds API provides coverage
try(toa_sports_scores(sport_key = 'baseball_mlb', days_from = NULL, date_format = 'iso'))
toa_sports_scores(sport_key, days_from = 1, date_format = "iso")
toa_sports_scores(sport_key, days_from = 1, date_format = "iso")
sport_key |
(string, required): The |
days_from |
(integer, optional): Integer from 1 to 3. Defaults to 1. |
date_format |
(string, optional): Date format. Options include:
|
Sports scores which The Odds API provides scores information for as a tibble:
col_name | types |
id | character |
sport_key | character |
sport_title | character |
commence_time | character |
completed | logical |
home_team | character |
away_team | character |
scores | logical |
last_update | logical |
try(toa_sports_scores(sport_key = 'baseball_mlb', days_from = NULL, date_format = 'iso'))
try(toa_sports_scores(sport_key = 'baseball_mlb', days_from = NULL, date_format = 'iso'))