A client that knows how to call the td-ameritrade Restful API written for nodejs and browser.
- Get access token and refresh token
- Get user account information
$ yarn add tdaclient
This setup is only good for testing the package. If you want to use it for your own application you will need to figure out how to pass to this client the required code, access token or refresh token. I will eventually add the documentation for using this package in your own application but for now you'll need to follow the instructions below.
- Run this command and open the output URL from the console.
For more info refer to this page
node generateAuthUrl.js
- Login and click allow.
- Go to this page to get the access token and
refresh token
- Fill in the form with the follow values:
- grant_type: authorization_code
- access_type: offline
- code: [the value that you receive from following step 1. Make sure it is decoded]
- client_id: [Your app consumer key]
- Note: make sure that this value is not url encoded. You can decode the value that you got from step 1 by
running this command in the javascript console
decodeURIComponent("MY_SECRET_CODE")
- Note: make sure that this value is not url encoded. You can decode the value that you got from step 1 by
running this command in the javascript console
- redirect_uri: [Your app redirect uri]
- Fill in the form with the follow values:
- Create a file in this directory (at the same level as this README.md) and name it
credentials.json
- Paste the response from that page to the file create in step 3. Also add the client_id and redirect_uri attributes at the end.
{ "access_token": "example-token", "refresh_token": "example-refresh-token", "scope": "PlaceTrades AccountAccess MoveMoney", "expires_in": 1800, // 30 minutes "refresh_token_expires_in": 7776000, // 90 days "token_type": "Bearer", "client_id": "example-client-id", "redirect_uri": "example-redirect-uri" }
- Now you can run the command
yarn test
and it will run the integration tests - The test will keep updating the access_token so you can keep running the tests. If you happen to not run the tests within 90 days, then you will have to manually login and get a new refesh_token and repeat step 4.
Refer to this page for more info on apis
tdaclient is MIT licensed.