Script to generate token.pickle for TDA algo trading

The whole process pissed me off so much that I want to share a my script to get the pickle file. Maybe read and tried 8 things from forum posts 4 years ago; I almost went insane because I've never really dealt with non-user friendly OAUTH stuff (robin-stocks was what I was using before this until I learned how bad the fills were). This will save the api newbies like ~5hrs of documentation and forum reading because of how TDA does the complicated redirect thing for platform apps.

from urllib.request import urlopen
import atexit
import datetime
import dateutil
import sys
import tda
API_KEY = "your key here"
TOKEN_PATH = 'token.pickle'
def make_webdriver():
# Import selenium here because it's slow to import
from selenium import webdriver
driver = webdriver.Chrome()
atexit.register(lambda: driver.quit())
return driver
client = tda.auth.easy_client(

Submitted August 28, 2020 at 10:59AM by getpuh

One thought on “Script to generate token.pickle for TDA algo trading”

  1. Hi, I am trying to get the script to work but I am getting an error: “from selenium import webdriver” IndentationError: expected an indented block” . Thank you for your help.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s