robinhood-unofficial / pyrh

Python Framework to make trades with the unofficial Robinhood API
https://pyrh.readthedocs.io/en/latest/
MIT License
1.78k stars 603 forks source link

Added Watchlists #273

Closed cjbarker closed 3 years ago

cjbarker commented 3 years ago

Checklist

Related Issue

Added support of watchlists API via feature request https://github.com/robinhood-unofficial/pyrh/issues/225

Description

robinhood.get_watchlists()

thevickypedia commented 3 years ago

I'm not sure which code base you used to create this PR, I just noticed that adding the function get_watchlists() in robhinhood.py itself was enough to print my watchlist.

cjbarker commented 3 years ago

@thevickypedia unless you merged in this PR no such function for get_wasthlists() existed previously. See commits and diff in pyrh/robinhood.py https://github.com/robinhood-unofficial/pyrh/pull/273/commits/5827df712279094381b7057cb0b7916c239e7f6b#diff-8462d24f9eac71f99f37d53f03c8e8c7

thevickypedia commented 3 years ago

@cjbarker yes I did, from the master branch all it requires is the below in robinhood.py and thats it, it works :)

def get_watchlists(self):
        api_url = "https://api.robinhood.com"
        url = api_url + "/watchlists/"
        result = []
        watchlist = self.get_url(url)
        if watchlist and 'results' in watchlist:
            data = self.get_url(watchlist["results"][0]["url"])
            for item in data["results"]:
                result.append(self.get_url(item['instrument']))

        return result