def get_odds(self, sport_id, leagues_ids, oddsFormat="Decimal"): req = URL(self.odds_v1.format(sport_id, leagues_ids, oddsFormat)) since = self.last_since_id.get('last_odds') if since: req['since'] = since response = self.http.get(req.request_uri, headers=self.auth_headers) data = self.read_json(response) odds_list = [] if not data: return odds_list try: for (_, ev) in self.get_event_pairs(data, "leagues"): event = Event(**ev) period = self.get_full_game_period(event) if not period: continue period = self.modify_odds_moneyline(period) # ignore special odds if not all([period.spreads, period.moneyline, period.totals]): continue document = Odds.get_document(event.id, datetime.utcnow(), period.spreads, period.moneyline, period.totals) odds_list.append(document) except KeyError: raise Exception("Error occured during processing odds." + " Pinnacle response: {}".format(data)) except TypeError: self.logger.error("Invalid Event: {}".format(ev)) # save since ID self.last_since_id['last_odds'] = data['last'] return odds_list
def get_event_odds(self, markets: List[BetfairMarket]): """ Recieve list of books for a single event and return odds object """ moneyline, spreads, totals = None, None, None event_id = markets[0].catalogue.event.id for m in markets: if m.catalogue.market_name == self.SPREAD_MARKET: spreads = self.parse_spreads(m.book) elif m.catalogue.market_name == self.TOTALS_MARKET: totals = self.parse_totals(m.book) elif m.catalogue.market_name == self.MONEYLINE_MARKET: moneyline = self.parse_moneyline(m.book) return Odds.get_document(event_id, datetime.utcnow(), spreads, moneyline, totals)