{"id":18005608,"url":"https://github.com/areed1192/td-ameritrade-python-api","last_synced_at":"2025-10-26T02:42:25.195Z","repository":{"id":38961889,"uuid":"220016766","full_name":"areed1192/td-ameritrade-python-api","owner":"areed1192","description":"Unofficial Python API client library for TD Ameritrade. This library allows for easy access of the Standard API and allows users to build data pipelines for the Streaming API.","archived":false,"fork":false,"pushed_at":"2023-05-23T00:14:50.000Z","size":2094,"stargazers_count":681,"open_issues_count":48,"forks_count":250,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-03-31T22:26:44.130Z","etag":null,"topics":["api-client","authentication-workflow","consumer","finance","option-chains","price-history","python","td-ameritrade","td-ameritrade-client","td-api","td-library","td-login"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/areed1192.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["areed1192"],"patreon":"sigmacoding","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-11-06T14:33:06.000Z","updated_at":"2025-02-20T23:55:19.000Z","dependencies_parsed_at":"2024-06-18T18:35:40.468Z","dependency_job_id":"e90844a3-6d1a-415d-94fe-a4a16e16f263","html_url":"https://github.com/areed1192/td-ameritrade-python-api","commit_stats":{"total_commits":158,"total_committers":12,"mean_commits":"13.166666666666666","dds":0.2215189873417721,"last_synced_commit":"c01b2e6f37c8da5ff67a56bb806be2e4ab2c910c"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Ftd-ameritrade-python-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Ftd-ameritrade-python-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Ftd-ameritrade-python-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/areed1192%2Ftd-ameritrade-python-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/areed1192","download_url":"https://codeload.github.com/areed1192/td-ameritrade-python-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744335,"owners_count":20988783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","authentication-workflow","consumer","finance","option-chains","price-history","python","td-ameritrade","td-ameritrade-client","td-api","td-library","td-login"],"created_at":"2024-10-30T00:20:46.733Z","updated_at":"2025-10-26T02:42:25.089Z","avatar_url":"https://github.com/areed1192.png","language":"Python","readme":"# UPDATE\n\nThis repo will soon be updated to include the new \u003chttps://github.com/areed1192/td-ameritrade-api\u003e\nlibrary. The master branch will be overwritten and the old code will need to be updated\nto reflect the new changes. If you would like to start rewriting your old code, please\nrefer to the new branch merge-new-repo or go the link above.\n\n## Unofficial TD Ameritrade Python API Library\n\n## Table of Contents\n\n- [Overview](#overview)\n- [What's in the API](#whats-in-the-api)\n- [Requirements](#requirements)\n- [API Key \u0026 Credentials](#api-key-and-credentials)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Features](#features)\n- [Documentation \u0026 Resources](#documentation-and-resources)\n- [Support These Projects](#support-these-projects)\n- [Authentication Workflow](#authentication-workflow)\n\n## Overview\n\nCurrent Version: **0.3.5**\n\nThe unofficial Python API client library for TD Ameritrade allows individuals with\nTD Ameritrade accounts to manage trades, pull historical and real-time data, manage\ntheir accounts, create and modify orders all using the Python programming language.\n\nTo learn more about the TD Ameritrade API, please refer to\nthe [official documentation](https://developer.tdameritrade.com/apis).\n\n## What's in the API\n\n- Authentication - access tokens, refresh tokens, request authentication.\n- Accounts \u0026 Trading\n- Market Hours\n- Instruments\n- Movers\n- Option Chains\n- Price History\n- Quotes\n- Transaction History\n- User Info \u0026 Preferences\n- Watchlist\n\n## Requirements\n\nThe following requirements must be met to use this API:\n\n- A TD Ameritrade account, you'll need your account password and account number to use the API.\n- A TD Ameritrade Developer Account\n- A TD Ameritrade Developer API Key\n- A Consumer ID\n- A Redirect URI, sometimes called Redirect URL\n- Python 3.7 or later.\n\n## API Key and Credentials\n\nEach TD Ameritrade API request requires a TD Ameritrade Developer API Key, a consumer ID,\nan account password, an account number, and a redirect URI. API Keys, consumer IDs, and\nredirect URIs are generated from the TD Ameritrade developer portal. To set up and create\nyour TD Ameritrade developer account, please refer to\nthe [official documentation](https://developer.tdameritrade.com/content/phase-1-authentication-update-xml-based-api).\n\nAdditionally, to authenticate yourself using this library, you will need to provide your\naccount number and password for your main TD Ameritrade account.\n\n**Important:** Your account number, an account password, consumer ID, and API key should\nbe kept secret.\n\n## Installation\n\nThe project can be found at PyPI, if you'd like to view the project please use\nthis [link](https://pypi.org/project/td-ameritrade-python-api/).\n\n```bash\npip install td-ameritrade-python-api\n```\n\nTo upgrade the library run the following command:\n\n```bash\npip install --upgrade td-ameritrade-python-api\n```\n\n## Usage\n\nThis example demonstrates how to login to the API and demonstrates sending a request\nusing the `get_quotes` endpoint, using your API key.\n\n**Credentials:**\nPlease note, that the `credentials_path` is a file path that will house the credentials\nlike your refresh token and access token. You must specify the `credentials_path` argument\nyourself so that you are aware of where the tokens will be stored. For example, if you\nspecify the `credentials_path` as `C:\\Users\\Public\\Credentials\\td_state.json` it would\nstore your tokens in a JSON file located in a folder called Credentials located under\nthe Users profile.\n\n```python\n# Import the client\nfrom td.client import TDClient\n\n# Create a new session, credentials path is required.\nTDSession = TDClient(\n    client_id='\u003cCLIENT_ID\u003e',\n    redirect_uri='\u003cREDIRECT_URI\u003e',\n    credentials_path='\u003cPATH_TO_CREDENTIALS_FILE\u003e'\n)\n\n# Login to the session\nTDSession.login()\n\n# Grab real-time quotes for 'MSFT' (Microsoft)\nmsft_quotes = TDSession.get_quotes(instruments=['MSFT'])\n\n# Grab real-time quotes for 'AMZN' (Amazon) and 'SQ' (Square)\nmultiple_quotes = TDSession.get_quotes(instruments=['AMZN','SQ'])\n```\n\n## Features\n\n### Authentication Workflow Support\n\nAutomatically will handle the authentication workflow for new users, returning users, and users\nwith expired tokens (refresh token or access token).\n\n### Request Validation\n\nFor certain requests, in a limited fashion, it will help validate your request when possible.\nFor example, when using the `get_movers` endpoint, it will automatically validate that the\nmarket you're requesting data from is one of the valid options.\n\n### Customized Objects for Watchlists, Orders, and Option Chains\n\nRequests for saved orders, regular orders, watchlists, and option chains can be a challenging\nprocess that has multiple opportunities to make mistakes. This library has built-in objects\nthat will allow you to quickly build your request and then validate certain portions of your\nrequest when possible.\n\n### Library Requirements\n\nThe following requirements must be met before being able to use the TD Ameritrade Python API library.\n\n- You must have a TD Ameritrade Account.\n- You must have a TD Ameritrade Developer Account. Please go to following [folder](https://github.com/areed1192/td-ameritrade-python-api/tree/master/samples/resources)\n  for instructions on how to create a Developer account.\n\n## Documentation and Resources\n\n### Official API Documentation\n\n- [Getting Started](https://developer.tdameritrade.com/content/phase-1-authentication-update-xml-based-api)\n- [Endpoints](https://developer.tdameritrade.com/apis)\n- [Guides](https://developer.tdameritrade.com/guides)\n- [Samples - Price History](https://developer.tdameritrade.com/content/price-history-samples)\n- [Samples - Place Order](https://developer.tdameritrade.com/content/place-order-samples)\n\n### Unofficial Documentation\n\n- [TD Ameritrade API - YouTube](https://www.youtube.com/playlist?list=PLcFcktZ0wnNnKvxFkJ5B7pvGaGa81Ny-6)\n\n## Support these Projects\n\n**Patreon:**\nHelp support this project and future projects by donating to my [Patreon Page](https://www.patreon.com/sigmacoding).\nI'm always looking to add more content for individuals like yourself, unfortuantely some of the APIs I would require\nme to pay monthly fees.\n\n**YouTube:**\nIf you'd like to watch more of my content, feel free to visit my YouTube channel [Sigma Coding](https://www.youtube.com/c/SigmaCoding).\n\n**Hire Me:**\nIf you have a project, you think I can help you with feel free to reach out at [coding.sigma@gmail.com](mailto:coding.sigma@gmail.com?subject=[GitHub]%20Project%20Proposal) or fill out the [contract request form](https://forms.office.com/Pages/ResponsePage.aspx?id=ZwOBErInsUGliXx0Yo2VfcCSWZSwW25Es3vPV2veU0pUMUs5MUc2STkzSzVQMFNDVlI5NjJVNjREUi4u)\n\n## Authentication Workflow\n\n**Step 1 - Start the Script:**\n\nWhile in Visual Studio Code, right click anywhere in the code editor while in the file that contains your code.\nThe following dropdown will appear:\n\n![Terminal Dropdown](https://raw.githubusercontent.com/areed1192/td-ameritrade-python-api/master/samples/instructions/photos/terminal_dropdown.jpg \"Terminal Dropdown\")\n\nFrom the dropdown, click `Run Python file in Terminal`, this will start the python script.\n\n**Step 2 - Go to Redirect URL:**\n\nThe TD Library will automatically generate the redirect URL that will navigate you to the TD website for for\nyou authentication. You can either copy the link and paste it into a browser manually or if you're using Visual\nStudio Code you can press `CTRL + Click` to have Visual Studio Code navigate you to the URL immeditately.\n\n![Redirect URI](https://raw.githubusercontent.com/areed1192/td-ameritrade-python-api/master/samples/instructions/photos/redirect_uri.jpg \"Redirect URI\")\n\n**Step 3 - Login to the TD API:**\n\nOnce you've arrived at the login screen, you'll need to provide your credentials to authenticate the session.\nPlease provide your Account Username and Account Password in the userform and then press enter. As a reminder\nthese, are the same username/password combination you use to login to your regular TD Account.\n\n![\"TD Login](https://raw.githubusercontent.com/areed1192/td-ameritrade-python-api/master/samples/instructions/photos/td_login.jpg \"TD Login\")\n\n**Step 4 - Accept the Terms:**\n\nAccept the Terms of the API by clicking `Allow`, this will redirect you.\n\n![TD Terms](https://raw.githubusercontent.com/areed1192/td-ameritrade-python-api/master/samples/instructions/photos/td_terms.jpg \"TD Terms\")\n\n**Step 5 - Copy the Authorization Code:**\n\nAfter accepting the terms, you'll be taken to the URL that you provided as your `redirect URI`. However, at\nthe end of that URL will be `authorization code`. To complete the authentication workflow, copy the URL as\nit appears below. Don't worry if the numbers don't match, as you will have a different code.\n\n![Auth Code](https://raw.githubusercontent.com/areed1192/td-ameritrade-python-api/master/samples/instructions/photos/auth_code.jpg \"Auth Code\")\n\n**Step 6 - Paste the Authorization Code in the Terminal:**\n\nTake the URL and copy it into the Terminal, after you have pasted it, press `Enter`. The authentication workflow\nwill complete and the script will start running. At this stage, we are exchanging your authorization code for\nan access token. That access token is valid only for 30 minutes. However, a refresh token is also stored that\nwill refresh your access token when it expires.\n\n![Paste URL](https://raw.githubusercontent.com/areed1192/td-ameritrade-python-api/master/samples/instructions/photos/paste_url.jpg \"Paste URL\")\n\nAfter, that the script should run. Additionally, if you go to the location you specified in the `credentials_path`\narugment you will now see `td_state.json` file. This file contains all the info used during a session. Please\nDO NOT DELETE THIS FILE OR ELSE YOU WILL NEED TO GO THROUGH THE STEPS ABOVE.\n","funding_links":["https://github.com/sponsors/areed1192","https://patreon.com/sigmacoding","https://www.patreon.com/sigmacoding"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fareed1192%2Ftd-ameritrade-python-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fareed1192%2Ftd-ameritrade-python-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fareed1192%2Ftd-ameritrade-python-api/lists"}