OpenBBTerminal icon indicating copy to clipboard operation
OpenBBTerminal copied to clipboard

[FR] Add TD Ameritrade to Broker List

Open raviolispy opened this issue 1 year ago • 11 comments

What's the problem of not having this feature? I'd like to be able to import a TD Ameritrade portfolio automatically like Ally Invest.

Describe the solution you would like A description of what you think would be the best solution for this. From user inputs, to an output.

Describe alternatives you've considered If there are other alternatives (worth considering) to your solution, list them here.

Additional information https://github.com/areed1192/td-ameritrade-api

raviolispy avatar Jul 23 '22 17:07 raviolispy

They have a get account/get accounts API call that should be able to support this: https://developer.tdameritrade.com/account-access/apis

aleksanderleyfman avatar Aug 10 '22 01:08 aleksanderleyfman

It is on our roadmap to provide these integrations (including many other brokers) so they can be directly imported inside the portfolio menu for now. We are also happy to provide guidance if you wish to design this yourself.

JerBouma avatar Aug 10 '22 07:08 JerBouma

Is there a template to follow?

aleksanderleyfman avatar Aug 10 '22 15:08 aleksanderleyfman

If you are looking to contribute via a Pull Request, you can do so by following these steps:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Install the pre-commit hooks by running: pre-commit install. Any time you commit a change, linters will be run automatically. On changes, you will have to re-commit.
  4. Commit your Changes (git commit -m 'Add some AmazingFeature')
  5. Push to your Branch (git push origin feature/AmazingFeature)
  6. Open a Pull Request

Keeping note of our guidelines: https://github.com/OpenBB-finance/OpenBBTerminal/blob/main/CONTRIBUTING.md

JerBouma avatar Aug 11 '22 06:08 JerBouma

I have actually had a look at this - the tricky part is that TD Ameritrade uses OAUTH 2.0 for their authentication.

It seems like the best/most popular TD Ameritrade python API is https://github.com/timkpaine/tdameritrade.

The TDA authentication flow requires users to create a developer account and developer app to get API keys, then use the API key to log in via browser and extract another token from the URL after they've granted their developer app access to their account. The API I linked above has the workflow automated as much as possible - you call an authenticate function with your API key, it opens your browser with selenium and gets and returns the token that way. In the terminal, we could have the user save the API key as an env var, run the auth function in the keys menu, and save the refresh token as a terminal config var.

The main issues I see are:

  • Users have to install the right selenium browser drivers (e.g. chromedriver)
  • Does controlling the browser with selenium work on WSL without installing chrome on WSL? I would check but not on WSL.
  • The API above has the user input() any key to let it know once they have finished logging in in the browser. I don't think input() works in the terminal so we'd have to submodule it and change the code to work with the terminal input methods or write an API from scratch.

I suggest we start by making a helper script that uses the API to download positions into a CSV that is readable by the terminal in a way that's not fully supported/in "beta" and then move it into a terminal command when we're ready.

Thoughts @JerBouma?

raviolispy avatar Aug 12 '22 23:08 raviolispy

In my opinion, it will require too many steps for the average user to get to work and we can not expect them to install some third party software (selenium) next to OpenBB. My suggestion would be that we allow support for loading in a CSV or Excel file containing the person's transactions that the user downloads directly from the TD Ameritrade website.

We are also in talks with Snaptrade (https://snaptrade.com/) which could be a neat integration at some point.

JerBouma avatar Aug 16 '22 11:08 JerBouma

@JerBouma The python library is already in the requirements.txt so we're good there but ok Ubuntu 22.04 I had to download a zip file of selenium web drivers for chrome and place them where it told me to for it to work. Not sure what the experience is like on WSL (the majority of users I'm guessing.

Good thought with providing support for importing CSVs from their website although iirc they only allow for downloading 1 year of transactions at a time.

Do either of those change things?

As a first step, providing support for importing the CSVs is a good first step so perhaps I'll start working on that.

raviolispy avatar Aug 16 '22 11:08 raviolispy

I think for now it is fine we provide support for the CSV even if it is limited. At a later stage we can extend this when there are more users interested. Would be awesome if you could work on that! :)

JerBouma avatar Aug 16 '22 13:08 JerBouma

Don't assign it to me just yet but I'll take a stab and if I get somewhere with it I'll put in a (draft) PR

raviolispy avatar Aug 17 '22 10:08 raviolispy

Feel free to ping me if you have any questions. I have my TD stuff setup so can check out.

jmaslek avatar Aug 17 '22 14:08 jmaslek

Can we also setup OpenBB to get ticker information such as intraday candles and such?

fivetwentysix avatar Jan 03 '23 03:01 fivetwentysix