Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localhost API for TD Ameritrade

I was creating an API for TD Ameritrade (my first time creating or dealing with APIs) and I needed to put in my own call back URL. I know that callback URL is where the API sends information to and i heard that I can just use my localhost API. I scoured the internet and I dont know how that would work and I was wondering if i can just use http://localhost?

Sorry if I seem like a noob because I am

like image 860
John Rawls Avatar asked Oct 02 '19 06:10

John Rawls


1 Answers

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.

like image 132
user6534901 Avatar answered Oct 23 '22 17:10

user6534901