knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
Robinhood is here to democratize access to the financial markets. This is an R package to help with that.
This package is made based on the unofficial documentation so it might have a few rough edges.
I have only implemented the parts of the API where authentication isn't needed, since I can't open an account. Please feel free to add the missing functionality.
rh_quote
)rh_historicals
)rh_markets
)rh_market_hours
)rh_instruments
)rh_instruments_info
)rh_instruments_split
)rh_instruments_search
)Let's see how it works. Load the package and set the symbols.
library(robinhoodr) library(quantmod) symbols <- c("MSFT", "FB")
Let's get some intraday data. The query below returns a list of length two with xts objects.
The function will make a request to the API for each individual symbol, soo if there are many symbols it can take a while.
hd <- rh_historicals(symbols = symbols, interval = "5minute", span = "day", bounds = "regular", keep_meta = FALSE, to_xts = TRUE) str(hd)
Use quantmod to plot the Microsoft data.
print(chart_Series(x = hd[["MSFT"]]))
You can't get more than a years worth of historical data. I don't know if Robinhood might change that. In the example below a list with data frames are returned.
hd_daily <- rh_historicals(symbols = symbols, interval = "day", span = "year", bounds = "regular", to_xts = FALSE) str(hd_daily)
You can decide to keep the meta data from the API request but only if the nested historical data is a data.frame.
hd_daily <- rh_historicals(symbols = symbols, interval = "day", span = "year", bounds = "regular", keep_meta = TRUE, to_xts = FALSE) str(hd_daily)
Get the latest quote.
str(rh_quote(symbols = symbols))
Get info on the markets. The last time I looked it up there were about 14 exchanges, so this must be the exchanges Robinhood use to execute the transactions.
# List markets str(rh_markets()) # Get specific market info str(rh_market_info("BATS")) # Get the market hours. str(rh_market_hours("BATS"))
Use rh_instruments to get a data.frame of all the available symbols. The API results are paginated, so it will a minute to download. You can also search and get fundamentals for a stock.
## Get a data.frame of all the instruments. str(rh_instruments()) # Seach for a specific keyword str(rh_instruments_search(keyword = "oil")) # Get fundamentals for a symbol str(rh_instruments_info(symbols = symbols))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.