Skip to content

wakproductions/tdameritrade-api-ruby

Repository files navigation

TD Ameritrade API gem for Ruby

This is a gem for connecting to the OAuth/JSON-based TD Ameritrade Developers API released in 2018. Go to https://developer.tdameritrade.com/ for the official documentation and to create your OAuth application.

For a gem that allows you to connect to the older version of the TDAmeritrade API, go to https://github.com/wakproductions/tdameritrade_api

Installation

In your Gemfile

gem 'tdameritrade-api-ruby', git: 'https://github.com/wakproductions/tdameritrade-api-ruby.git'

Authenticating

Currently this gem is designed for private app authorization. Read this guide for a general overview of signing in your private app: https://developer.tdameritrade.com/content/simple-auth-local-apps

The TD Ameritrade API now uses OAuth for authentication. For an introduction to the OAuth flow, I recommend reading this tutorial.

I plan on writing more detailed instructions in the file /doc/authentication.md

See my video Stonks on Rails Episode #2 - Connecting to TD Ameritrade via OAuth for a more detailed walkthrough of the OAuth authentication process.

Basic Usage

client = TDAmeritrade::Client.new(
  client_id: 'MYCLIENTID@AMER.OAUTHAP', 
  redirect_uri: 'http://my-redirect-url', 
  refresh_token: 'b6w31RJvP/Cz3MVghpx8S5dzeYVcHygEQHKWYQuI98NGpsMb1j...'
)

client.get_instrument_fundamentals('TWTR')
#=> {"TWTR"=>
      {"fundamental"=>
        {"symbol"=>"TWTR",
         "high52"=>47.79,
         "low52"=>20.12,
         "dividendAmount"=>0.0,
         "dividendYield"=>0.0,
         "peRatio"=>17.93788,
         "pegRatio"=>0.039026,
         "pbRatio"=>3.85707,
         ...

Current State of Functionality

The official API is documented here. This gem currently implements the following functionality. If you would like to expand its functionality, then please submit a pull request.

  • Accounts and Trading
  • Authentication
  • Instruments
  • Market Hours
  • Movers
  • Option Chains
  • Price History
  • Real-time Quotes
  • Transaction History
  • User Info and Preferences
  • Watchlist
    • Get Watchlists
    • Replace Watchlist
    • Delete Watchlist
    • Update Watchlist

Contributions

If you would like to make a contribution, please submit a pull request to the original branch. Feel free to email me Winston Kotzan at wak@wakproductions.com with any feature requests, bug reports, or feedback.

Wish List

  • Test Coverage in RSpec

Support

Please open an issue on Github if you have any problems or questions.

Release Notes

See CHANGELOG.md

About

A gem to make it easier to use the TD Ameritrade OAuth-based API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages