Skip to content

Odds Type

Odds Type Class Documentation

Represents a specific type of betting odds (e.g., open, current, close).

This class parses and stores detailed betting values such as point spread, spread, and money line. It uses the BetValue class to wrap individual bet types.

Attributes:

Name Type Description
name str

The name/type of the odds entry (e.g., "open", "current", "close").

odds_type_json dict

Raw JSON containing the odds data.

espn_instance PYESPN

The ESPN API instance used for constructing related data.

favorite str or None

The identifier for the favored team in this odds set.

odds dict

Dictionary mapping odds types to BetValue instances. Keys include 'point_spread', 'spread', and 'money_line'.

Source code in pyespn/classes/betting.py
class OddsType:
    """
    Represents a specific type of betting odds (e.g., open, current, close).

    This class parses and stores detailed betting values such as point spread,
    spread, and money line. It uses the `BetValue` class to wrap individual bet types.

    Attributes:
        name (str): The name/type of the odds entry (e.g., "open", "current", "close").
        odds_type_json (dict): Raw JSON containing the odds data.
        espn_instance (PYESPN): The ESPN API instance used for constructing related data.
        favorite (str or None): The identifier for the favored team in this odds set.
        odds (dict): Dictionary mapping odds types to `BetValue` instances.
                     Keys include 'point_spread', 'spread', and 'money_line'.
    """

    def __init__(self, odds_name, odds_type_json, espn_instance):
        """
        Initializes an OddsType instance with the provided name and JSON data.

        Args:
            odds_name (str): A label for this odds set (e.g., "open", "current").
            odds_type_json (dict): JSON data containing detailed betting values.
            espn_instance (PYESPN): The parent ESPN API instance.
        """
        self.name = odds_name
        self.odds_type_json = odds_type_json
        self._espn_instance = espn_instance
        self.odds = {}
        self.favorite = self.odds_type_json.get('favorite')
        self._load_odds_type_data()

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

        Returns:
            str: A formatted string indicating the name of the odds type.
        """
        return f"<OddsType | {self.name}>"

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

    def _load_odds_type_data(self):
        """
        Parses the odds_type_json to populate the `odds` dictionary with BetValue instances.

        Extracts:
            - Point spread odds
            - Spread odds
            - Money line odds
        Each is stored as a `BetValue` under a corresponding key.
        """
        self.odds['point_spread'] = BetValue(bet_name='point_spread',
                                             bet_json=self.odds_type_json.get('pointSpread', {}),
                                             espn_instance=self._espn_instance)
        self.odds['spread'] = BetValue(bet_name='spread',
                                       bet_json=self.odds_type_json.get('spread', {}),
                                       espn_instance=self._espn_instance)
        self.odds['money_line'] = BetValue(bet_name='money_line',
                                           bet_json=self.odds_type_json.get('moneyLine', {}),
                                           espn_instance=self._espn_instance)

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

        Returns:
            dict: The odds type's raw JSON data.
        """
        return self.odds_type_json

espn_instance property

PYESPN: the espn client instance associated with the class

__init__(odds_name, odds_type_json, espn_instance)

Initializes an OddsType instance with the provided name and JSON data.

Parameters:

Name Type Description Default
odds_name str

A label for this odds set (e.g., "open", "current").

required
odds_type_json dict

JSON data containing detailed betting values.

required
espn_instance PYESPN

The parent ESPN API instance.

required
Source code in pyespn/classes/betting.py
def __init__(self, odds_name, odds_type_json, espn_instance):
    """
    Initializes an OddsType instance with the provided name and JSON data.

    Args:
        odds_name (str): A label for this odds set (e.g., "open", "current").
        odds_type_json (dict): JSON data containing detailed betting values.
        espn_instance (PYESPN): The parent ESPN API instance.
    """
    self.name = odds_name
    self.odds_type_json = odds_type_json
    self._espn_instance = espn_instance
    self.odds = {}
    self.favorite = self.odds_type_json.get('favorite')
    self._load_odds_type_data()

__repr__()

Returns a string representation of the OddsType instance.

Returns:

Name Type Description
str str

A formatted string indicating the name of the odds type.

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

    Returns:
        str: A formatted string indicating the name of the odds type.
    """
    return f"<OddsType | {self.name}>"

to_dict()

Converts the OddsType instance to its original JSON dictionary.

Returns:

Name Type Description
dict dict

The odds type's raw JSON data.

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

    Returns:
        dict: The odds type's raw JSON data.
    """
    return self.odds_type_json