There isn’t very good documentation out there on how to connect and use TD Ameritrade’s APIs. In this blog, I’ll be connecting to TD Ameritrade’s APIs with Python to automatically pull order history transactions and store it into a local MySQL database.
All my code is posted on my Github repo for reference. Please feel free to follow my instructional guide below and contact me for improvements or help.
Non-Brogrammers
. I’m a mechanical engineer by discipline so a lot of this stuff wasn’t intuitive to me at first. I believe this guide will serve as a tool for beginner programmers, like me, in getting started.
One of the first steps is to create a TDA developer account. Once created, you’ll be able to create an “app.” This app will generate a consumer key in order to connect to their API’s. Below are the steps to get your consumer key:
Navigate to “My Apps” in the navigation bar and click on “Add a new App”
Name_of_your_choice
[http://localhost/test](http://localhost/test)
Once the new app is created, a consumer key is generated. We’ll need that later.
You can also go ahead and browse around the various API’s TD Ameritrade offers.
Fig 1: Generating a consumer key from TDA Developer app
Before we can use some of the API’s we’ll need to verify our accounts by providing an authentication token. The security on these API’s use OAuth 2.0, which means getting the auth token will be very difficult and painful (not necessarily a bad thing; it just means it’s secure).
The only way to retrieve the auth token is to first get an auth code. As far as I know, the only way to get the auth code is by visiting a TDA web address and logging in. (Note: these tokens and codes are only temporarily active so you will need to retrieve them frequently).
In the next few steps, as seen in GIF 1, we’ll be automating the retrieval of the auth code and then use the TDA API to retrieve the auth token.
#trading #api #python #trading-journals #td-ameritrade