Skip to content

Minimal workflow used to automate getting your personal credentials for td-ameritrade api access. Contains scripts for deploying to a raspberry-pi server. This will save the access token to a file on the host machine.

License

Notifications You must be signed in to change notification settings

jatkz/tda-authentication-service

Repository files navigation

tda-authentication-service

Set up in order to automate getting your personal credentials for the td-ameritrade api access. Contains scripts for deploying to a raspberry-pi server. This will only expose the temporary access token to the machine the script is hosted on.

There are two steps involved in getting access to td ameritrade's api. First get the refresh token through the Oauth script. Note the refresh token expires in 90 days. The second script uses the refresh token to get an access token which expires in 30 minutes.

Setting up

In order to install dependencies you can use pipenv: pip install pipenv

After successful installation: pipenv install

Then activate the shell whenever you would like to use: pipenv shell

Uploading to PI Server

Here is below code to copy all files needed to run this on a raspberry pi

# source your .env
# Host name should follow {user}@{ipaddress}:{path}
scp -r ./reauth ./check_refresh_tokens.py "$SSH_HOST"
scp "$TDA_REFRESH_TOKEN_PATH" "$SSH_HOST"

SSH into PI and run following commands to install dependencies and contab scheduling:

pip install requests;
pip install datetime;

sudo nano /etc/crontab;

Inside the crontab enter cron expression following this pattern:

*/20 8-22 * * 1-5 <user> python ~/home/<user>/check_refresh_tokens.py > /home/<user>/cron.log 2>&1

The following ENV variables are required and you can add them to /etc/profile

export CLIENT_ID=<[email protected]>
export TDA_REFRESH_TOKEN_PATH="/home/../refresj_token.json"
export TDA_REFRESH_STATUS_PATH="/home/../refresh_status"
export TDA_ACCESS_TOKEN_PATH="/home/../access_token.json"

Then follow up with

sudo reboot

About

Minimal workflow used to automate getting your personal credentials for td-ameritrade api access. Contains scripts for deploying to a raspberry-pi server. This will save the access token to a file on the host machine.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages