Giter Club home page Giter Club logo

tda-api's Introduction

tda-api: A TD Ameritrade API Wrapper

image

image

image

image

image

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.pickle'
api_key = '[email protected]'
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?

Unfortunately, the TD Ameritrade API does not seem to expose any endpoints around the papermoney <https://tickertape.tdameritrade.com/tools/papermoney -stock-market-simulator-16834>__ simulated trading product. tda-api can only be used to perform real trades using a TD Ameritrade account.

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.

tda-api's People

Contributors

alexgolec avatar dustydecapod avatar wolframarnold avatar jsruaagxhi avatar morgan-griffiths avatar nicmcd avatar sargun avatar h00shi avatar thomas-schweich avatar bobsknees avatar earth-c137 avatar sie2 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.