Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Betting Tools APIs. #5

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,89 @@ data = dg.live_predictions.live_hole_stats(tour='kft')
```


---

# Betting

### Outright Odds

Returns the most recent win, top 5, top 10, top 20, make/miss cut, and
first round leader odds offered at 11 sportsbooks alongside the corresponding
predictions from the DG model.

<details>
<summary>API Endpoint Info</summary>


**Endpoint:** `/betting-tools/outrights`
**Method:** GET
**Formats:** JSON

| Param | Type | Ex |
|---------|------|--------------------------------------------------------------|
| tour | (str, optional) | pga (default), euro, opp (opposite field PGA TOUR event), kft, alt |
| market | (str, required) | Specifies the match-up market. Supports values: win, top_5, top_10, top_20, mc, make_cut, frl |
| odds_format | (str, optional) | Specifies the odds format. Supports values: percent, american, decimal (default), fraction |

</details>

```python
data = dg.betting.outright_odds(market='win')
data = dg.betting.outright_odds(market='top_5', tour='euro')
```


### Matchup Odds


Returns the most recent tournament match-up, round match-up, and 3-ball odds offered at 8
sportsbooks alongside the corresponding prediction from our model.

<details>
<summary>API Endpoint Info</summary>


**Endpoint:** `/betting-tools/matchups`
**Method:** GET
**Formats:** JSON

| Param | Type | Ex |
|---------|------|--------------------------------------------------------------|
| tour | (str, optional) | pga (default), euro, opp (opposite field PGA TOUR event), kft, alt |
| market | (str, required) | Specifies the match-up market. Supports values: tournament_matchups, round_matchups, 3_balls |
| odds_format | (str, optional) | Specifies the odds format. Supports values: percent, american, decimal (default), fraction |

</details>

```python
data = dg.betting.matchup_odds(market='tournament_matchups')
data = dg.betting.matchup_odds(market='3_balls', tour='euro')
```

### Matchup Odds - All Pairings


Returns Data Golf matchup / 3-ball odds for every pairing in the next round of
current PGA Tour and European Tour events.

<details>
<summary>API Endpoint Info</summary>


**Endpoint:** `/betting-tools/matchups-all-pairings`
**Method:** GET
**Formats:** JSON

| Param | Type | Ex |
|---------|------|--------------------------------------------------------------|
| tour | (str, optional) | pga (default), euro, opp (opposite field PGA TOUR event), kft, alt |
| odds_format | (str, optional) | Specifies the odds format. Supports values: percent, american, decimal (default), fraction |

</details>

```python
data = dg.betting.matchup_odds_all_pairings(tour='pga')
data = dg.betting.matchup_odds_all_pairings(tour='euro', odds_format='american')
```


69 changes: 69 additions & 0 deletions data_golf/api/betting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Betting:
def __init__(self, client):
self._client = client
self._path = "/betting-tools"

def outright_odds(
self,
market: str,
tour: str = "pga",
odds_format: str = "decimal",
f_format: str = "json",
) -> dict:
"""
Returns the most recent win, top 5, top 10, top 20, make/miss cut, and
first round leader odds offered at 11 sportsbooks alongside the corresponding
predictions from the DG model.
:param market: (str, required). Specifies the match-up market. Supports values: win, top_5, top_10,
top_20, mc, make_cut, frl
:param tour: (str, optional). pga (default), euro, kft, opp (opposite field PGA TOUR event), alt
:param odds_format: (str, optional) Specifies the odds format. Supports values: percent, american, decimal
(default), fraction
:param f_format: (str, optional) json (default)
:return: dict
"""
query_p = {"tour": tour, "odds_format": odds_format, "market": market}

return self._client.get(
resource=f"{self._path}/outrights", params=query_p, format=f_format
)

def matchup_odds(
self,
market: str,
tour: str = "pga",
odds_format: str = "decimal",
f_format: str = "json",
) -> dict:
"""
Returns the most recent tournament match-up, round match-up, and 3-ball odds offered at 8
sportsbooks alongside the corresponding prediction from our model.
:param market: (str, required). Specifies the match-up market. Supports values: tournament_matchups,
round_matchups, 3_balls
:param tour: (str, optional). pga (default), euro, kft, opp (opposite field PGA TOUR event), alt
:param odds_format: (str, optional) Specifies the odds format. Supports values: percent, american, decimal (default), fraction
:param f_format: (str, optional) json (default)
:return:
"""
query_p = {"tour": tour, "odds_format": odds_format, "market": market}
return self._client.get(
resource=f"{self._path}/matchups", params=query_p, format=f_format
)

def matchup_odds_all_pairings(
self, tour: str = "pga", odds_format: str = "decimal", f_format: str = "json"
) -> dict:
"""
Returns Data Golf matchup / 3-ball odds for every pairing in the next round of
current PGA Tour and European Tour events.
:param tour: (str, optional). pga (default), euro, opp, alt
:param odds_format: (str, optional) Specifies the odds format. Supports values: percent, american, decimal (default), fraction
:param f_format: (str, optional) json (default)
:return:
"""
query_p = {"tour": tour, "odds_format": odds_format}
return self._client.get(
resource=f"{self._path}/matchups-all-pairings",
params=query_p,
format=f_format,
)
32 changes: 32 additions & 0 deletions data_golf/api/historical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import List


class Historical:
def __init__(self, client):
self._client = client
self._path = "/historical-raw-data"

def events(self, f_format: str = "json") -> List[dict]:
"""
Returns a list of all events in the Data Golf database.
:param f_format: (str, optional) json (default)
:return: dict
"""
return self._client.get(resource=f"{self._path}/event-list", format=f_format)

def rounds(self, tour: str, event: str, year: str, f_format: str = "json"):
"""
Returns round-level scoring, traditional stats, strokes-gained, and tee time data across 22 global tours.
:param tour: (str, required) Specifies the tour. Hover over tour
codes in table https://datagolf.com/raw-data-archive to see full tour names.
pga, euro, kft, cha, jpn, anz, alp, champ, kor, ngl, bet, chn, afr, pgt, pgti,
atvt, atgt, sam, ept, can, liv, mex
:param event: (str, required) IDs can be found via Historical.events
:param year: (str, required)
:param f_format: (str, optional) json (default)
:return:
"""
query_p = {"tour": tour, "event": event, "year": year}
return self._client.get(
resource=f"{self._path}/rounds", params=query_p, format=f_format
)
8 changes: 4 additions & 4 deletions data_golf/api/live_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ def live_in_play(
dead_heat: bool = False,
odds_format: str = "percent",
f_format: str = "json",
):
) -> dict:
"""
Returns live (updating at 5 minute intervals) finish probabilities for ongoing PGA and European Tour tournaments.
:param tour: pga (default), euro, opp (opposite field PGA TOUR event), kft, alt
:param dead_heat: False (default), True
:param odds_format: percent (default), american, decimal, fraction
:param f_format: Defaults to JSON.
:return:
:return: dict
"""
query_p = {
"odds_format": odds_format,
Expand All @@ -34,7 +34,7 @@ def live_tournament_stats(
round: str = None,
display: str = "value",
f_format: str = "json",
):
) -> dict:
"""
Returns live strokes-gained and traditional stats for every player during
PGA Tour tournaments
Expand All @@ -44,7 +44,7 @@ def live_tournament_stats(
:param round: Specifies the round: Accepts: (event_avg, 1, 2, 3, 4)
:param display: Specifies how stats are displayed. Accepts values: value (default), rank
:param f_format:
:return:
:return: dict
"""
query_p = {
"display": display,
Expand Down
2 changes: 2 additions & 0 deletions data_golf/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from data_golf.api.betting import Betting
from data_golf.api.prediction import Prediction
from data_golf.config import DGConfig
from data_golf.http_client import HttpClient
Expand Down Expand Up @@ -28,6 +29,7 @@ def __init__(
self.general = General(self._http_client)
self.predictions = Prediction(self._http_client)
self.live_predictions = LivePrediction(self._http_client)
self.betting = Betting(self._http_client)

def _validate_api_key(self, api_key: str) -> None:
"""
Expand Down
Loading
Loading