Package: tda-api
What istda-api?tda-apiis an unofficial wrapper around theTD 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 authenticationQuotes, fundamentals, and historical pricing dataOptions chainsStreaming quotes and order book depth dataTrades and trade managementAccount info and preferencesHow do I usetda-api?For a full description oftda-api’s functionality, check out thedocumentation. Meawhile, here’s
a quick getting started guide:Before you do anything, create an account and an application on theTD 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, installtda-api:pipinstalltda-apiYou’re good to go! To demonstrate, here’s how you can authenticate and fetch
daily historical price data for the past twenty years:fromtdaimportauth,clientimportjsontoken_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)exceptFileNotFoundError:fromseleniumimportwebdriverwithwebdriver.Chrome()asdriver: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)assertr.status_code==200,r.raise_for_status()print(json.dumps(r.json(),indent=4))Why should I usetda-api?tda-apiwas designed to provide a few important pieces of functionality: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-apihandles token fetch and refreshing for you.Minimal API Wrapping: Unlike some other API wrappers, which build in lots
of logic and validation,tda-apitakes 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 withtda-api,
only more easily.Why should Inotusetda-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 thepapermoneysimulated trading product.tda-apican
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 aDiscord server! You can join to
get help usingtda-apior just to chat with interesting people.Bug reports, suggestions, and patches are always welcome! Submit issueshereand pull requestshere.tda-apiis released under theMIT 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.