Skip to main content
https://img.shields.io/discord/720378361880248621.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2 https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dalexgolec%26type%3Dpatrons&style=flat https://readthedocs.org/projects/tda-api/badge/?version=latest https://github.com/alexgolec/tda-api/workflows/tests/badge.svg https://badge.fury.io/py/tda-api.svg http://codecov.io/github/alexgolec/tda-api/coverage.svg?branch=master

What is tda-api?

tda-api is an unofficial wrapper around the TD Ameritrade APIs. It strives to be as thin and unopinionated as possible, offering an elegant programmatic interface over each endpoint. Notable functionality includes:

  • Login and authentication

  • Quotes, fundamentals, and historical pricing data

  • Options chains

  • Streaming quotes and order book depth data

  • Trades and trade management

  • Account info and preferences

How do I use tda-api?

For a full description of tda-api’s functionality, check out the documentation. Meawhile, here’s a quick getting started guide:

Before you do anything, create an account and an application on the TD Ameritrade developer website. You’ll receive an API key, also known as a Client Id, which you can pass to this wrapper. You’ll also want to take note of your callback URI, as the login flow requires it.

Next, install tda-api:

pip install tda-api

You’re good to go! To demonstrate, here’s how you can authenticate and fetch daily historical price data for the past twenty years:

from tda import auth, client
import json

token_path = '/path/to/token.json'
api_key = 'YOUR_API_KEY@AMER.OAUTHAP'
redirect_uri = 'https://your.redirecturi.com'
try:
    c = auth.client_from_token_file(token_path, api_key)
except FileNotFoundError:
    from selenium import webdriver
    with webdriver.Chrome() as driver:
        c = auth.client_from_login_flow(
            driver, api_key, redirect_uri, token_path)

r = c.get_price_history('AAPL',
        period_type=client.Client.PriceHistory.PeriodType.YEAR,
        period=client.Client.PriceHistory.Period.TWENTY_YEARS,
        frequency_type=client.Client.PriceHistory.FrequencyType.DAILY,
        frequency=client.Client.PriceHistory.Frequency.DAILY)
assert r.status_code == 200, r.raise_for_status()
print(json.dumps(r.json(), indent=4))

Why should I use tda-api?

tda-api was designed to provide a few important pieces of functionality:

  1. Safe Authentication: TD Ameritrade’s API supports OAuth authentication, but too many people online end up rolling their own implementation of the OAuth callback flow. This is both unnecessarily complex and dangerous. tda-api handles token fetch and refreshing for you.

  2. Minimal API Wrapping: Unlike some other API wrappers, which build in lots of logic and validation, tda-api takes raw values and returns raw responses, allowing you to interpret the complex API responses as you see fit. Anything you can do with raw HTTP requests you can do with tda-api, only more easily.

Why should I not use tda-api?

As excellent as TD Ameritrade’s API is, there are a few popular features it does not offer:

  • Unfortunately, the TD Ameritrade API does not seem to expose any endpoints around the papermoney simulated trading product. tda-api can only be used to perform real trades using a TD Ameritrade account. Note: trades made through the API appear in thinkorswim and vice versa.

  • The API only supports trading in equities, mutual funds, ETFs, and options (both simple contracts and complex composite positions). Futures and futures options trading is not supported. Some data is provided for futures, but not for futures options.

  • Historical options pricing data is not available.

What else?

We have a Discord server! You can join to get help using tda-api or just to chat with interesting people.

Bug reports, suggestions, and patches are always welcome! Submit issues here and pull requests here.

tda-api is released under the MIT license.

Disclaimer: tda-api is an unofficial API wrapper. It is in no way endorsed by or affiliated with TD Ameritrade or any associated organization. Make sure to read and understand the terms of service of the underlying API before using this package. This authors accept no responsibility for any damage that might stem from use of this package. See the LICENSE file for more details.

Release files for tda-api 1.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tda-api 1.6.0
File Size Uploaded
tda-api-1.6.0.tar.gz 88.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tda-api 1.6.0
File Interpreter ABI Platform
tda_api-1.6.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 183.5 kB

Release files / tda-api-1.6.0.tar.gz

Download URL tda-api-1.6.0.tar.gz
Size 88.1 kB
Tags Source
SHA-256 checksum
How to use checksums
27541a57787dcefc1a161dae4a121c254dafe650b92ecebfb4f288282afaeab9
BLAKE2b-256 checksum
How to use checksums
a15595532c5e85e6610fb901c94452a392a3cbd8b3044cbaac9f1b501fef6fbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / tda_api-1.6.0-py2.py3-none-any.whl

Download URL tda_api-1.6.0-py2.py3-none-any.whl
Size 95.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bdde2f7b7768adf31b8a28e549ac122e9a909c05f817fb8b3b6bb3945baa67ce
BLAKE2b-256 checksum
How to use checksums
2f2a6926ca2e96c8ad703e6fe683fbc66a032cbeaddb4761d2f4f86f5dd4359c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

1.6.0 This release

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page