Skip to content

Commit

Permalink
merge endpoints with options
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonleehodges committed Apr 4, 2018
2 parents 3531a5e + 095c477 commit ac518c8
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Robinhood/Robinhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#Application-specific imports
from . import exceptions as RH_exception
from . import endpoints


class Bounds(Enum):
Expand Down Expand Up @@ -624,12 +625,12 @@ def get_popularity(self, stock=''):
(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"]
return self.get_url(endpoints.instruments(stock_instrument, "popularity"))["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:
Args: tag - Tags may include but are not limited to:
* top-movers
* etf
* 100-most-popular
Expand All @@ -641,7 +642,7 @@ def get_tickers_by_tag(self, tag=None):
Returns:
(List): a list of Ticker strings
"""
instrument_list = self.get_url("{base}{_tag}/".format(base=self.endpoints['tags'], _tag=tag))["instruments"]
instrument_list = self.get_url(endpoints.tags(tag))["instruments"]
return [self.get_url(instrument)["symbol"] for instrument in instrument_list]

###########################################################################
Expand Down
84 changes: 84 additions & 0 deletions Robinhood/endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
def login():
return "https://api.robinhood.com/api-token-auth/"

def logout():
return "https://api.robinhood.com/api-token-logout/"

def investment_profile():
return "https://api.robinhood.com/user/investment_profile/"

def accounts():
return "https://api.robinhood.com/accounts/"

def ach(option):
'''
Combination of 3 ACH endpoints. Options include:
* iav
* relationships
* transfers
'''
return "https://api.robinhood.com/ach/iav/auth/" if option == "iav" else "https://api.robinhood.com/ach/{_option}/".format(_option=option)

def applications():
return "https://api.robinhood.com/applications/"

def dividends():
return "https://api.robinhood.com/dividends/"

def edocuments():
return "https://api.robinhood.com/documents/"

def instruments(instrumentId=None, option=None):
'''
Return information about a specific instrument by providing its instrument id.
Add extra options for additional information such as "popularity"
'''
return "https://api.robinhood.com/instruments/{id}/".format(id=instrumentId) + "{_option}/".format(_option=option) if option else ""

def margin_upgrades():
return "https://api.robinhood.com/margin/upgrades/"

def markets():
return "https://api.robinhood.com/markets/"

def notifications():
return "https://api.robinhood.com/notifications/"

def orders():
return "https://api.robinhood.com/orders/"

def password_reset():
return "https://api.robinhood.com/password_reset/request/"

def portfolios():
return "https://api.robinhood.com/portfolios/"

def positions():
return "https://api.robinhood.com/positions/"

def quotes():
return "https://api.robinhood.com/quotes/"

def historicals():
return "https://api.robinhood.com/quotes/historicals/"

def document_requests():
return "https://api.robinhood.com/upload/document_requests/"

def user():
return "https://api.robinhood.com/user/"

def watchlists():
return "https://api.robinhood.com/watchlists/"

def news():
return "https://api.robinhood.com/midlands/news/"

def fundamentals():
return "https://api.robinhood.com/fundamentals/"

def tags(tag=None):
'''
Returns endpoint with tag concatenated.
'''
return "https://api.robinhood.com/midlands/tags/tag/{_tag}/".format(_tag=tag)

0 comments on commit ac518c8

Please sign in to comment.