Skip to content

Commit

Permalink
Merge pull request robinhood-unofficial#82 from jasonleehodges/popula…
Browse files Browse the repository at this point in the history
…rity

Popularity
  • Loading branch information
Jamonek authored Apr 2, 2018
2 parents eacdaaf + 4f4e174 commit 43a0738
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Robinhood/Robinhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Robinhood:
"watchlists": "https://api.robinhood.com/watchlists/",
"news": "https://api.robinhood.com/midlands/news/",
"fundamentals": "https://api.robinhood.com/fundamentals/",
"tags": "https://api.robinhood.com/midlands/tags/tag/"
}

session = None
Expand Down Expand Up @@ -610,6 +611,36 @@ def get_url(self, url):
"""

return self.session.get(url, timeout=15).json()

def get_popularity(self, stock=''):
"""Get the number of robinhood users who own the given stock
Args:
stock (str): stock ticker
Returns:
(int): number of users who own the stock
"""
stock_instrument = self.get_url(self.quote_data(stock)["instrument"])["id"]
return self.get_url("{base}{instrument}/popularity/".format(base=self.endpoints['instruments'], instrument=stock_instrument))["num_open_positions"]

def get_tickers_by_tag(self, tag=None):
"""Get a list of instruments belonging to a tag
Args: tag - a string that equals one of the following:
* top-movers
* etf
* 100-most-popular
* mutual-fund
* finance
* cap-weighted
* investment-trust-or-fund
Returns:
(List): a list of Ticker strings
"""
instrument_list = self.get_url("{base}{_tag}/".format(base=self.endpoints['tags'], _tag=tag))["instruments"]
return [self.get_url(instrument)["symbol"] for instrument in instrument_list]


###########################################################################
Expand Down

0 comments on commit 43a0738

Please sign in to comment.