westonplatter / fast_arrow

(no longer maintained) A simple yet robust (stock+options) API client for Robinhood
MIT License
127 stars 37 forks source link

Fix 400 error on mfa authentication #90

Open k3an3 opened 5 years ago

k3an3 commented 5 years ago

The web API uses device_token as one of the fields during authentication. Looking at the issues for this and other similar API clients, people have been generating these randomly but it can also be done by the standard uuid library.

Without this change, I get this error calling Client.authenticate(): requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.robinhood.com/oauth2/token/

Second, the API also takes a nonzero parameter when fetching all options positions. Thought it was nice to include this since you don't get as much garbage data this way. Could even make this the default option if so inclined.

westonplatter commented 5 years ago

Thanks @k3an3 for the PR.

What kind of garbage data is excluded?

k3an3 commented 5 years ago

If you don't include nonzero=True, the positions returned includes (all?) historic options positions where the quantity == 0. So if I run it the default way, I get my current open positions (which is only a few entries), and then basically every single other position I've ever had. It seems slower to pull all of this data, and I don't think it is necessary unless you are specifically trying to go back and look at all of your historic options. This fix just saves you from filtering by positions with quantity != 0

wardnath commented 5 years ago

I've found that I need to include X-ROBINHOOD-CHALLENGE-RESPONSE-ID to the headers to resolve the 400 issue.

see: https://github.com/Jamonek/Robinhood/issues/176#issuecomment-487379320

westonplatter commented 5 years ago

@k3an3 @wardnath I moved authentication operations into a new library, fast_arrow_auth. I used your code changes to help figure out how handle the device token there (THANKS!!). What I'm thinking is make update this PR to only contain the nonzero logic.

westonplatter commented 5 years ago

@k3an3 I pull in your option position changes into https://github.com/westonplatter/fast_arrow/pull/97 and resolved the merge conflicts there. I'll wait a couple of days in case you had thoughts or feedback on how I adjusted the code changes.

Thanks a ton for your help on removing garbage data from the options position code.

westonplatter commented 5 years ago

@k3an3 I went ahead and merged #97 with your option position API changes.