anilshanbhag / RobinhoodShell

A command line shell for trading stocks using Robinhood
MIT License
411 stars 94 forks source link

Store access_token into json file and reuse later #23

Closed klepsydra closed 5 years ago

klepsydra commented 5 years ago

Following our discussions in #22 and https://github.com/anilshanbhag/RobinhoodShell/commit/b9ec538890e7e2c760fa9c28c1eb45ac9d716081#commitcomment-33584861

we have a functioning solution for automation again. However, it generates tons of email. For every single invocation of shell.py, even to do no more than lookup my account balances--which I might do many times per day--it goes through time-delaying stages of generating yet another verification code, followed by a second mail "We’re emailing to confirm your recent login to Robinhood."

I was thinking, again in Robinhood/Robinhood.py, maybe around the lines

                #gets access token for final response to stay logged in
                res3 = self.session.post(endpoints.login(), data=payload, timeout=15)
                res3.raise_for_status()
                data = res3.json()

                if 'access_token' in data.keys() and 'refresh_token' in data.keys():
                    self.auth_token = data['access_token']
                    self.refresh_token = data['refresh_token']
                    self.headers['Authorization'] = 'Bearer ' + self.auth_token

                    # How about export this into a file, and reuse later?
                    # Serialize this access_token, and deserialize it next run, instead of going thru login hack

                    return True

I might try to hack it up, but it won't be pretty; I tend to resort to subshells and languages I'm more familiar with.

anilshanbhag commented 5 years ago

I have done this in my private copy. I am still trying to figure out how to refresh the token. https://github.com/Jamonek/Robinhood/issues/180

anilshanbhag commented 5 years ago

The changes are in the save branch. It doesn't refresh the token

anilshanbhag commented 5 years ago

I have fixed the issue :)