TD Ameritrades API uses Oauth2
Create an Application with TD Ameritrade. You'll have to create a separate TD Developer account: https://developer.tdameritrade.com/user/me/apps
Set the required fields when creating the application
http://localhost)Once the App is created and has been approved (usually instant), note the Consumer Key. It will be needed later.
Generate your TD Ameritrade Auth URL
Example URL
<https://auth.tdameritrade.com/auth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost&client_id=CONSUMER_KEY%40AMER.OAUTHAP>
A couple important things to note from this URL.
http://localhost, no changes need to be made.Get Auth Code using generated auth url
Paste the URL into your browser and login.
After you login, it will redirect you to your the specified redirect url. Copy the code from the url (everything after ?code=)
Example URL: https://localhost/?code=AVPe1iYC%2F.....sL
Continue the manual way on the next step, or if familiar with cURL, use the following curl command and skip to step 5. (update command to contain your code and consumer key)
curl -X POST --header "Content-Type: application/x-www-form-urlencoded" -d "grant_type=authorization_code&refresh_token=&access_type=offline&code=MY_URL_ENCODED_CODE&client_id=MY_CONSUMER_KEY%40AMER.OAUTHAP&redirect_uri=http%3A%2F%2Flocalhost" "<https://api.tdameritrade.com/v1/oauth2/token>"
Decode the URL encoded auth code
Get Refresh Token using decoded code
authorization_codeoffline[email protected]http://localhostTest Refresh Token
refresh_tokenMY_REFRESH_TOKEN[email protected]