def quote_data(self, stock=''): """Fetch stock quote Args: stock (str): stock ticker, prompt if blank Returns: (:obj:`dict`): JSON contents from `quotes` endpoint """ url = None if stock.find(',') == -1: url = str(endpoints.quotes()) + str(stock) + "/" else: url = str(endpoints.quotes()) + "?symbols=" + str(stock) #Check for validity of symbol try: req = self.session.get(url, timeout=15) req.raise_for_status() data = req.json() except requests.exceptions.HTTPError: raise RH_exception.InvalidTickerSymbol() return data
def quotes_data(self, stocks): """Fetch quote for multiple stocks, in one single Robinhood API call Args: stocks (list<str>): stock tickers Returns: (:obj:`list` of :obj:`dict`): List of JSON contents from `quotes` endpoint, in the same order of input args. If any ticker is invalid, a None will occur at that position. """ url = str(endpoints.quotes()) + "?symbols=" + ",".join(stocks) try: req = self.session.get(url, timeout=15) req.raise_for_status() data = req.json() except requests.exceptions.HTTPError: raise RH_exception.InvalidTickerSymbol() return data["results"]