Code Monkey home page Code Monkey logo

tdameritrade_api's Introduction

TD Ameritrade API gem for Ruby

Build Status Code Climate

This is a gem for connecting to the TD Ameritrade API.

Installation

Add this line to your application's Gemfile:

gem 'tdameritrade_api', :git=>'https://github.com/wakproductions/tdameritrade_api.git'

Important Note

This is in the very early stages of development. It has very limited functionality in comparison to the entirety of the API. See the /vendor/docs folder for more details on the overall API.

Setup

To use this, you need to have 3 environment variables set:

TDAMERITRADE_SOURCE_KEY - this is given to you by TD Ameritrade
TDAMERITRADE_USER_ID    - your username to connect to TD Ameritrade
TDAMERITRADE_PASSWORD   - your account password for TD Ameritrade

Basic Usage

To connect to the TD Ameritrade API using this gem, create an instance of TDAmeritradeApi::Client and then call the methods you need.

c = TDAmeritradeApi::Client.new
c.login
#=> true

c.get_price_history('MSFT', intervaltype: :minute, intervalduration: 15, periodtype: :day, period: 10)
#=> [{:open=>41.75, :high=>41.87, :low=>41.71, :close=>41.85, :volume=>17955.3, :timestamp=>2014-07-07
   09:30:00 -0400, :interval=>:day}, {:open=>41.85, :high=>41.92, :low=>41.84, :close=>41.9,
   :volume=>7380.78, :timestamp=>2014-07-07 09:45:00 -0400, :interval=>:day},...  a long hash array of
   the price candles]

Currently Supported Methods

The only API features really supported right now are the ability to capture real time quotes, price history, and streaming of Level 1 quotes.

login
get_price_history   # retrieves historical data
get_quote           # gets realtime snapshots of quotes

Streaming

c = TDAmeritradeApi::Client.new
c.login
streamer = c.create_streamer
streamer.run(symbols: symbols, request_fields: [:volume, :last, :symbol, :quotetime, :tradetime]) do |data|
   # Process the stream data here - this block gets called for every new chunk of data received from TDA
   # See what's in the data hash to get the requested information streaming in about the stock
end

The streamer also has the ability to read and write from a hard disk file for testing:

# This output_file attribute will cause the stream to be saved into a file as its being processed
streamer.output_file = '/Users/wkotzan/Development/gem-development/tda_stream_daemon/cache/stream20150205.binary'

# Run this code to read a stream from a presaved file
input_file = '~/stream20150213-should-have-WUBA-1010am.binary'
streamer = TDAmeritradeApi::Streamer::Streamer.new(read_from_file: input_file)

Watchlists (see lib/watchlist.rb for accepted parameters)

get_watchlists
create_watchlist
edit_watchlist

Balances and Positions (see lib/balances_and_positions.rb for accepted parameters)

get_balances_and_positions

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 [email protected] with any feature requests, bug reports, or feedback.

Release Notes

See CHANGELOG.md

tdameritrade_api's People

Contributors

dharb avatar naren8642 avatar wakproductions avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tdameritrade_api's Issues

Account status, balances

Hi Winston @wakproductions ,

Preferring Ruby, I will attempt to add things like account status/balances/positions/orders etc. and eventually trading, in my fork. Unless there is already some duplicated effort?

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.