tastyware / tastytrade

An unofficial, sync/async Python SDK for Tastytrade!
https://tastyworks-api.rtfd.io
MIT License
127 stars 43 forks source link

Improvements for installation and login #70

Closed gregbsmith closed 1 year ago

gregbsmith commented 1 year ago

I was unable to successfully install the module with pip install tastytrade. Several attributes of the tastytrade module simply did not appear. I made changes by importing these missing attributes in the tastytrade/init.py. I also had to change the way the typing library was incorporated, because built-in type objects like list and dict are not subscriptable; def fun(self) -> list[str]: is illegal; typing.List[str] must be used instead.

The previous version of the Session constructor also did not allow for the use of a remember token. The documentation incorrectly stated that it did. In reality, if a remember token was provided, the request still sent the remember token as the password, which was incorrect. I changed the Session constructor to allow for either login method. If I'm not mistaken, there are currently no calls to the Session constructor that exist in the code, so this shouldn't be a problem.

Graeme22 commented 1 year ago

Hi! Sounds like you're using an older version of Python. What's the output of python --version?

Graeme22 commented 1 year ago

So far I haven't attempted to support older versions of Python, but I'd like to support them, you're on 3.5 or 3.6 I think.

As for the remember token, were you able to successfully login with one? I've never gotten it to work!

gregbsmith commented 1 year ago

Hi Graeme!

I'm using Python 3.8.10.

Also, I am able to log in with a remember token and no password. I think the important thing is passing the remember token with the "remember-token" key, and not just as "password".

gregbsmith commented 1 year ago

I actually stumbled upon peter-oroszvari's tastytrade-api, before this one, but it looks like he stopped maintaining it before or shortly after he contributed to this one. But here on lines 24 and 33 he successfully logs in with the remember token: https://github.com/peter-oroszvari/tastytrade-api/blob/main/tastytrade_api/authentication.py

Graeme22 commented 1 year ago

I'm using Python 3.8.10.

I did some googling and it looks like using the lowercase types is only available in 3.9+... So I definitely welcome these changes! I'm surprised you're the first person that came across this.

Also, I am able to log in with a remember token and no password. I think the important thing is passing the remember token with the "remember-token" key, and not just as "password".

Great! I'd been wondering about that, it was documented incorrectly in the API I believe and I never messed around with it long enough to figure it out.

gregbsmith commented 1 year ago

I really hope they just officially support a Python SDK at some point soon. Unless I'm missing something, I can either generate code for the requests in Postman (ie do the task of this project from scratch myself), I can use a 3rd party package like this (which lacks guarantees), or I can use that absolute titan of financial modeling and data science languages for which they so generously officially support an API: javascript.

I feel like for a business that makes money off of the volume of orders that they get through their platform, they should be falling over themselves to eliminate all barriers to entry for me to trade an imprudent amount in the easiest programming language known to man.

Graeme22 commented 1 year ago

I really hope they just officially support a Python SDK at some point soon. Unless I'm missing something, I can either generate code for the requests in Postman (ie do the task of this project from scratch myself), I can use a 3rd party package like this (which lacks guarantees), or I can use that absolute titan of financial modeling and data science languages for which they so generously officially support an API: javascript.

Community supported will likely be higher quality at the end of the day, though I'm not sure what guarantees you're looking for, obviously that can't be provided. I think Peter's API is basically what you're describing, this one goes a bit beyond that in that it also tries to make common tasks simpler/more intuitive, you don't have to actually jump through all the hoops of working with raw JSON data.

I feel like for a business that makes money off of the volume of orders that they get through their platform, they should be falling over themselves to eliminate all barriers to entry for me to trade an imprudent amount in the easiest programming language known to man.

Yeah but the API took about 5 years longer than promised so clearly they've got other priorities :(

Graeme22 commented 1 year ago

Looks like the tests are failing, can you run isort on the tastytrade directory?

gregbsmith commented 1 year ago

Looks like the tests are failing, can you run isort on the tastytrade directory?

Just did. Do you need me to create another pull request?

Community supported will likely be higher quality at the end of the day, though I'm not sure what guarantees you're looking for, obviously that can't be provided. I think Peter's API is basically what you're describing, this one goes a bit beyond that in that it also tries to make common tasks simpler/more intuitive, you don't have to actually jump through all the hoops of working with raw JSON data.

Yeah but the API took about 5 years longer than promised so clearly they've got other priorities :(

Good points, hadn't really considered these.

Also have you seen this? It's not mentioned in the API documentation, but the repository belongs to the official tastytrade Github account that also owns their official javascript API. https://github.com/tastytrade/tastytrade-sdk-python

Graeme22 commented 1 year ago

Just did. Do you need me to create another pull request?

Nope! I'll merge when I get the chance, thanks for the contribution!

Also have you seen this? It's not mentioned in the API documentation, but the repository belongs to the official tastytrade Github account that also owns their official javascript API. https://github.com/tastytrade/tastytrade-sdk-python

I hadn't! Looks like they are making an official Python SDK then. I guess time will tell how good it is...

Graeme22 commented 1 year ago

Looks like you're still failing a couple tests. You can run them locally with make test before committing to make sure you're good.

gregbsmith commented 1 year ago

The tests that I'm still failing have to do with the import statements in __init__.py. But without these, the module ends up actually containing none of the objects/attributes that are listed in the documentation. Is there another way to make sure they are included?

Graeme22 commented 1 year ago

Don't worry about it! I'll clean up the rest, it's pretty minor stuff