def quote_data(self, stock=""): """Fetch stock quote. Args: stock (str or dict): stock ticker symbol or stock instrument Returns: (:obj:`dict`): JSON contents from `quotes` endpoint """ if isinstance(stock, dict): if "symbol" in stock.keys(): url = str(endpoints.quotes()) + stock["symbol"] + "/" elif isinstance(stock, str): url = str(endpoints.quotes()) + stock + "/" else: raise InvalidTickerSymbol() # Check for validity of symbol try: data = self.get(url) except requests.exceptions.HTTPError: raise 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: data = self.get(url) except requests.exceptions.HTTPError: raise InvalidTickerSymbol() return data["results"]