Skip to main content

An unofficial wrapper around the TD Ameritrade HTTP API.

Project description

tda-api: A TD Ameritrade API Wrapper

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
  • Trades and trade management
  • Account info and preferences

How do I use tda-api?

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 client
import json

token_path = '/path/to/token.json'
api_key = 'MYAPIKEY@AMER.OAUTHAP'
redirect_uri = 'https://my.redirect-uri.com/'
try:
    c = client.client_from_token_file(token_path, api_key)
except FileNotFoundError:
    from selenium import webdriver
    with webdriver.Chrome() as driver:
        c = client.client_from_login_flow(
            driver, api_key, redirect_uri, token_path)

response = 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 resp.ok
print(json.dumps(resp.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.

What else?

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tda-api-0.0.2.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tda_api-0.0.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file tda-api-0.0.2.tar.gz.

File metadata

  • Download URL: tda-api-0.0.2.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for tda-api-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bba1be2af925beeb6200370f301423c527a886cc9597c27ec7bb31fd3f493766
MD5 6b291f7e2dedcf8efc0f2e8e08187f17
BLAKE2b-256 c75141b3136941f3f3a94c5f6b77612e8b7ef9f9bec5d592163ab3fe73c76602

See more details on using hashes here.

File details

Details for the file tda_api-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: tda_api-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for tda_api-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 651250ed8b426d254958d4d21182d83f288f573daf66616d377339bd7acc4701
MD5 0bb5e9428c4d89211960d03897794210
BLAKE2b-256 ef91dc75aa5349e5e065755d249e6d6bcdd99f40dff6a7a16d152b6aeb8306ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page