Localhost API for TD Ameritrade

Solution 1:

In short, yes.

Follow the excellent directions at https://www.reddit.com/r/algotrading/comments/c81vzq/td_ameritrade_api_access_2019_guide/. (Even with them, I spent excessive time on trial and error!)

Since stackoverflow has a limit of 8 links in a response, and the localhost text string looks like a link, I’m showing it with the colon replaced by a semicolon, i.e., http;//localhost to reduce the link count. Sorry.

I used the Chrome browser after first trying Brave, which did not work for, possibly because of my option selections.

Go to https://developer.tdameritrade.com/user/me/apps

Add a new app using http;//localhost (delete existing app if there is one). Copy the resulting consumer key text string (AKA client_id or OAuth User ID).

Go to https://developer.tdameritrade.com/content/simple-auth-local-apps, follow instructions. Note: leading/trailing blanks were inserted by MSWord due to copy/paste of the auth code, which had to be manually deleted after wasting excessive time identifying the problem. The address string looks like:

https://auth.tdameritrade.com/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost&client_id=ConsumerKeyTextString%40AMER.OAUTHAP

This returns a page stating the server refused to connect, but the address bar now contains a VeryLongStringOfCharacters in the address bar: https;//localhost/?code= VeryLongStringOfCharacters

Copy the contents of the address bar, go to https://www.urldecoder.org/, decode the above, and extract the text after “code=”. This is your refresh_token

Go to: https://developer.tdameritrade.com/authentication/apis/post/token-0, fill out the fields with

grant_type=authorization_code
refresh_token=<<blank>>
access_type=offline
code=RefreshTokenTextString
[email protected]
redirect_uri=http;//localhost

Press SEND.

If the resulting page starts with HTTP/1.1 200 OK, you have succeeded.