GithubHelp home page GithubHelp logo

tdlink's Introduction

GitHub license

tdlink

Python Library for TDAmeritrade API

All the dates and times are in UTC.

Authentication

NOTE: Please make sure you obtain a code or refresh token from TDAmeritrade before using this library.

Follow these steps to get a code:

  1. Go to TDAmeritrade developer: https://developer.tdameritrade.com/
  2. Login and go to "My Apps"
  3. Create an app. Use http://localhost as the callback url.
  4. Go to this url: https://auth.tdameritrade.com/auth?response_type=code&redirect_uri=http://localhost&client_id=[YourAppName]@AMER.OAUTHAP
  5. Enter your TD credentials and give premission
  6. Once you login, you will be redirected to a url of this form https://localhost/?code=[code]
  7. Copy the [code] part. Add it as a parameter to the TDAmeritrade class.
  8. The TDAmeritrade class should now work!

NOTE: The code you obtain is only valid for a limited period of time. If expired, follow steps again to get a new code.

Installation

From PyPI

pip install tdlink

From Source

pip install --upgrade git+git://github.com/ysriram1/tdlink

Examples

Connect to the API

from tdlink import TDlink

td = TDlink(app_key='TRADING123',
                redirect_uri='http://localhost',
                code='3V7m...', # follow instructions to get the code
                return_raw_response=False # will return formatted df if False, else returns HTTP response
                )

Get the refresh and access tokens

td.refresh_token # returns refresh token

td.access_token # returns the access token

Note: You can save the refresh token for creating a future session instead of using a code.

Get Data from API

Current Quote

td.get_current_quote(symbol='QQQ',
          to_return=['askPrice', 'bidPrice', 'totalVolume'])
quote

NOTE: Use this also for prices of options.

Historical Data

td.get_historical_prices(symbol='QQQ',
                    period_type='day', # 'day'
                    period=2, # day: 1, 2, 3, 4, 5, 10* month: 1*, 2, 3, 6 year: 1*, 2, 3, 5, 10, 15, 20 ytd: 1*
                    frequency_type='minute', # day: minute* month: daily, weekly* year: daily, weekly, monthly* ytd: daily, weekly*
                    frequency=5, # minute: 1*, 5, 10, 15, 30 daily: 1* weekly: 1* monthly: 1*
                    start_date='06/03/2019', # mm/dd/yyyy
                    start_time=None, # hh:mm:ss
                    end_date='06/04/2019',
                    end_time=None,
                    extended_hours=True,
                    return_df=True # if False, returns a dictionary instead
                    )
Historical Data

Options Chain

td.get_options_chain(symbol='QQQ', # symbol of underlying security
                    strike=None, # mention a specific strike
                    from_date='01/01/2020', # only expirations after this date (mm/dd/yyyy)
                    from_time=None,
                    to_date='01/30/2020', # only expirations before this date
                    to_time=None,
                    expiry_month='ALL', # option expiry month ALL or JAN
                    kind='OTM', # ITM, NTM, OTM, SAK (Strikes Above Market), ALL etc.
                    include_quotes=False, # if FALSE only returns the option names (use get_current_quote() to get value)
                    contract_type='CALL', # CALL, PUT
                    strikes=5, # number of strikes above or below at-the-money price
                    strategy='SINGLE',
                    return_df=True # if False, returns a dictionary instead
                    )
Options Chain

Top Movers of an Index

td.get_movers_for_index(symbol = 'DJI', # has to be an index DJI, SPX.X  etc
                        direction = None, # 'up' or 'down'. if None, returns both
                        change = None # 'value' or 'percent'. if None, defaults to percentage
                        )
Top Movers

Support

Please email me at [email protected] if you have any questions, suggestions, or ideas for improvement.

tdlink's People

Contributors

ysriram1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  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.