TDAmeritrade.jl

Documentation for TDAmeritrade.jl

Getting started

  • To best use this package, for example, real-time quotes of stocks, you have to have a TD Ameritrade trading account.
  1. Make an account at TD developers, this is different from your TD trading account
  2. Make an App, make sure to use "http://localhost" as your Callback URL
  3. Add the Consumer Key of your application to ENV["JL_TD_CONSUMER_KEY"] (you can also add to your environment variable via ~/.bashrc or ~/.zshrc)
  4. Profit, using TDAmeritrade and start off by running TD_auth() and follow the instruction.

A file will be created at ~/.JL_TD_TOKENS_CACHE after first run to save the REFRESH_TOKEN.

APIs

TDAmeritrade.TD_authFunction

TD_auth()

run authentication procedure

  1. already authenticated -> do nothing
  2. access token expired && has refresh token -> refresh access token
  3. refresh token expired -> get refresh token
  4. no CONSUMER_KEY -> error
source
TDAmeritrade.get_moversFunction
get_movers(idx_symbol::T,
           dire::T="up",
           chg::T="percent") where T<:AbstractString

Get top 10 (up or down) movers of an idx: https://developer.tdameritrade.com/movers/apis/get/marketdata/{index}/movers

Arguments

dire = "up" or "down" chg = "value" or "percent"

Examples

get_movers(raw"$DJI")
get_movers("$DJI", "up", "value")
source
TDAmeritrade.price_historyFunction
price_history(ticker; kwargs...)

Get price history of a given ticker, everything but ticker have default value specified by TD api: https://developer.tdameritrade.com/price-history/apis/get/marketdata/{symbol}/pricehistory

Optional kwargs:

periodType period frequencyType frequency endDate startDate needExtendedHoursData

Examples

using Dates

price_history("GE", Minute(1), Day(1)) #a tick = a day for the past day
price_history("GE", Day(1), Year(2)) #a tick = a day for the past 2 years
price_history("AAPL", Day(1), now()-Day(1), now())
source

price_history(ticker, freq, peri)

see TD API for default and compatible frequency vs. tickers

source

price_history(ticker, freq, start::DateTime=now()-Day(1), stop::DateTime=now())

get the price history with interval ticks from start to stop

valid frequency: minute: 1*, 5, 10, 15, 30

source
TDAmeritrade.get_quotesFunction
get_quotes(ticker)
get_quotes(ticker::Array)

Get quote of a symbol: https://developer.tdameritrade.com/quotes/apis/get/marketdata/{symbol}/quotes

ticker can be a single String or an Array or multiple Strings

Examples

get_quotes("GE")
get_quotes(["BA","GE"])
source
TDAmeritrade.market_hoursFunction
market_hours(market::AbstractString, date=today())
market_hours(market::Array, date=today())

Get hours of a market in the future: https://developer.tdameritrade.com/market-hours/apis/get/marketdata/%7Bmarket%7D/hours

Get hours of multiple markets: https://developer.tdameritrade.com/market-hours/apis/get/marketdata/hours

market can be a single String or an Array or multiple Strings

Examples

market_hours("OPTION", "2020-08-08")
market_hours(["OPTION", "FUTURE", "EQUITY"], today() + Day(1))
source