Skip to content

Game Odds

Odds Class Documentation

Represents the overall betting odds for a specific game/event.

This class handles parsing and organizing odds data from various providers, including standardized ones (like ESPN BET) and custom formats (like Bet365). It creates instances of Odds, OddsBet365, and BetValue to model the odds for home and away teams.

Attributes:

Name Type Description
odds_json dict

Raw JSON data containing odds information.

espn_instance PYESPN

The ESPN API instance used for team lookups and related methods.

event_instance Event

The parent event associated with these odds.

provider str

Name of the odds provider.

over_under float or None

The total points line for the game.

details str or None

Any extra details provided with the odds.

spread float or None

The point spread for the game.

over_odds float or None

Odds associated with the over.

under_odds float or None

Odds associated with the under.

money_line_winner str or None

The team favored in the moneyline bet.

spread_winner str or None

The team favored against the spread.

home_team_odds Odds or OddsBet365

Odds object for the home team.

away_team_odds Odds or OddsBet365

Odds object for the away team.

open BetValue

Opening odds.

current BetValue

Current odds.

close BetValue

Closing odds (if available for provider).

Source code in pyespn/classes/betting.py
class GameOdds:
    """
    Represents the overall betting odds for a specific game/event.

    This class handles parsing and organizing odds data from various providers, including
    standardized ones (like ESPN BET) and custom formats (like Bet365). It creates instances
    of `Odds`, `OddsBet365`, and `BetValue` to model the odds for home and away teams.

    Attributes:
        odds_json (dict): Raw JSON data containing odds information.
        espn_instance (PYESPN): The ESPN API instance used for team lookups and related methods.
        event_instance (Event): The parent event associated with these odds.
        provider (str): Name of the odds provider.
        over_under (float or None): The total points line for the game.
        details (str or None): Any extra details provided with the odds.
        spread (float or None): The point spread for the game.
        over_odds (float or None): Odds associated with the over.
        under_odds (float or None): Odds associated with the under.
        money_line_winner (str or None): The team favored in the moneyline bet.
        spread_winner (str or None): The team favored against the spread.
        home_team_odds (Odds or OddsBet365): Odds object for the home team.
        away_team_odds (Odds or OddsBet365): Odds object for the away team.
        open (BetValue, optional): Opening odds.
        current (BetValue, optional): Current odds.
        close (BetValue, optional): Closing odds (if available for provider).
    """

    def __init__(self, odds_json, espn_instance, event_instance):
        """
        Initializes a GameOdds instance with raw odds data.

        Args:
            odds_json (dict): The JSON data representing odds for the event.
            espn_instance (PYESPN): The ESPN API interface for additional data lookups.
            event_instance (Event): The associated Event instance.
        """

        self.odds_json = odds_json
        self._espn_instance = espn_instance
        self.event_instance = event_instance
        self._load_odds_data()

    @property
    def espn_instance(self):
        """
            PYESPN: the espn client instance associated with the class
        """
        return self._espn_instance

    def __repr__(self) -> str:
        """
        Returns a string representation of the GameOdds instance.

        Returns:
            str: A formatted string showing the odds provider name.
        """
        return f"<GameOdds | {self.provider}>"

    def _load_odds_data(self):
        """
        Parses and loads odds data from the input JSON.

        Handles both standardized providers (like ESPN BET) and
        provider-specific formats (like Bet 365). Assigns odds for
        home and away teams and loads line details such as over/under,
        spread, moneyline, and BetValue objects for open/current/close odds.
        """
        self.provider = self.odds_json.get('provider', {}).get('name', 'unknown')
        self.over_under = self.odds_json.get('overUnder')
        self.details = self.odds_json.get('details')
        self.spread = self.odds_json.get('spread')
        self.over_odds = self.odds_json.get('overOdds')
        self.under_odds = self.odds_json.get('underOdds')
        self.money_line_winner = self.odds_json.get('moneylineWinner')
        self.spread_winner = self.odds_json.get("spreadWinner")

        if self.provider not in STANDARDIZED_BETTING_PROVIDERS:
            if self.provider == 'Bet 365':
                away_dicts = {}
                home_dicts = {}
                other_dicts = {}
                home_team = self._espn_instance.get_team_by_id(get_team_id(self.odds_json.get('bettingOdds', {}).get('homeTeam', {}).get('$ref')))
                away_team = self._espn_instance.get_team_by_id(get_team_id(self.odds_json.get('bettingOdds', {}).get('awayTeam', {}).get('$ref')))

                for key, value in self.odds_json.get('bettingOdds', {}).get('teamOdds', {}).items():
                    if 'home' in str(key).lower():
                        home_dicts.setdefault(key, value)
                    elif 'away' in str(key).lower():
                        away_dicts.setdefault(key, value)
                    else:
                        other_dicts.setdefault(key,value)
                self.away_team_odds = OddsBet365(odds_json=away_dicts,
                                                 espn_instance=self._espn_instance,
                                                 event_instance=self.event_instance,
                                                 gameodds_instance=self,
                                                 team=away_team)
                self.home_team_odds = OddsBet365(odds_json=home_dicts,
                                                 espn_instance=self._espn_instance,
                                                 event_instance=self.event_instance,
                                                 gameodds_instance=self,
                                                 team=home_team)
                #print('bet 365 not fully integrated yet')
            else:
                print(f'the provider is {self.provider}')
        else:
            if self.provider == 'ESPN Bet - Live Odds':
                pass
            self.away_team_odds = Odds(odds_json=self.odds_json.get('awayTeamOdds'),
                                       espn_instance=self._espn_instance,
                                       event_instance=self.event_instance,
                                       gameodds_instance=self)
            self.home_team_odds = Odds(odds_json=self.odds_json.get('homeTeamOdds'),
                                       espn_instance=self._espn_instance,
                                       event_instance=self.event_instance,
                                       gameodds_instance=self)
            self.open = BetValue(bet_name='open',
                                 bet_json=self.odds_json.get('open'),
                                 espn_instance=self._espn_instance)
            self.current = BetValue(bet_name='current',
                                    bet_json=self.odds_json.get('current'),
                                    espn_instance=self._espn_instance)
            if self.provider == 'ESPN BET':
                self.close = BetValue(bet_name='close',
                                      bet_json=self.odds_json.get('close'),
                                      espn_instance=self._espn_instance)

    def to_dict(self) -> dict:
        """
        Converts the GameOdds instance to its original JSON dictionary.

        Returns:
            dict: The game odds's raw JSON data.
        """
        return self.odds_json

espn_instance property

PYESPN: the espn client instance associated with the class

__init__(odds_json, espn_instance, event_instance)

Initializes a GameOdds instance with raw odds data.

Parameters:

Name Type Description Default
odds_json dict

The JSON data representing odds for the event.

required
espn_instance PYESPN

The ESPN API interface for additional data lookups.

required
event_instance Event

The associated Event instance.

required
Source code in pyespn/classes/betting.py
def __init__(self, odds_json, espn_instance, event_instance):
    """
    Initializes a GameOdds instance with raw odds data.

    Args:
        odds_json (dict): The JSON data representing odds for the event.
        espn_instance (PYESPN): The ESPN API interface for additional data lookups.
        event_instance (Event): The associated Event instance.
    """

    self.odds_json = odds_json
    self._espn_instance = espn_instance
    self.event_instance = event_instance
    self._load_odds_data()

__repr__()

Returns a string representation of the GameOdds instance.

Returns:

Name Type Description
str str

A formatted string showing the odds provider name.

Source code in pyespn/classes/betting.py
def __repr__(self) -> str:
    """
    Returns a string representation of the GameOdds instance.

    Returns:
        str: A formatted string showing the odds provider name.
    """
    return f"<GameOdds | {self.provider}>"

to_dict()

Converts the GameOdds instance to its original JSON dictionary.

Returns:

Name Type Description
dict dict

The game odds's raw JSON data.

Source code in pyespn/classes/betting.py
def to_dict(self) -> dict:
    """
    Converts the GameOdds instance to its original JSON dictionary.

    Returns:
        dict: The game odds's raw JSON data.
    """
    return self.odds_json