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.
- Make an account at TD developers, this is different from your TD trading account
- Make an App, make sure to use "http://localhost" as your Callback URL
- 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) - Profit,
using TDAmeritradeand start off by runningTD_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_auth — FunctionTD_auth()
run authentication procedure
- already authenticated -> do nothing
- access token expired && has refresh token -> refresh access token
- refresh token expired -> get refresh token
- no CONSUMER_KEY -> error
TDAmeritrade.get_movers — Functionget_movers(idx_symbol::T,
dire::T="up",
chg::T="percent") where T<:AbstractStringGet 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")TDAmeritrade.price_history — Functionprice_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())price_history(ticker, freq, peri)
see TD API for default and compatible frequency vs. tickers
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
TDAmeritrade.get_quotes — Functionget_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"])TDAmeritrade.market_hours — Functionmarket_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))