README.md

robinhoodQF

source("functions.R") ### to be replaced with library(robinhoodQF)

Login

With Robinhood's recent modicification to their public API, accessing data now requires authorization headers and tokens that need to be generated using existing account credentials. The access_robinhood uses account credentials to create the required authorization headers and tokens; however, account credentials are removed from the system memory immediately after all required authorization is created.

access_robinhood(username="username", password="password")

Altenatively, if you are using RStudio, you could have the username and password never be stored in plain text, by using a GUI prompt to enter them.

# access_robinhood(rstudioapi::showPrompt(title = "Username", message = "Username", default = ""),
#                  rstudioapi::askForPassword(prompt = 'Password: '))

The access_robinhood function will create a list called robinhoodUser, containing two R6 classes that underly most global methods in the robinhoodQF package. The robindhoodQF package is designed so that you will never need to directly interact with this list or its contents.

Historical Data

The robinhoodQF package allows you to download the last year of daily data, as well as the last week of 5 minute tick data, from the Robinhood API for a list of shorthand ticker symbols:

library(formattable)
source("stock_formattable.R")
mySymbols <- c("AAPL","AMZN")
dailyData <- robinhood_daily_historicals(symbols=mySymbols)
intradayData <- robinhood_intraday_historicals(symbols=mySymbols)
dailyData$AAPL%>%head()%>%as.data.frame()%>%make_stock_formattable()
open high low close volume 2018-02-22 $ 171.80 $ 173.95 $ 171.71 $ 172.50 30991940 2018-02-23 $ 173.67 $ 175.65 $ 173.54 $ 175.50 33812360 2018-02-26 $ 176.35 $ 179.39 $ 176.21 $ 178.97 38162174 2018-02-27 $ 179.10 $ 180.48 $ 178.16 $ 178.39 38928125 2018-02-28 $ 179.26 $ 180.62 $ 178.05 $ 178.12 37782138 2018-03-01 $ 178.54 $ 179.78 $ 172.66 $ 175.00 48801970
dailyData$AMZN%>%head()%>%as.data.frame()%>%make_stock_formattable()
open high low close volume 2018-02-22 $ 1,495.36 $ 1,502.54 $ 1,475.76 $ 1,485.34 4858063 2018-02-23 $ 1,495.34 $ 1,500.00 $ 1,486.50 $ 1,500.00 4418103 2018-02-26 $ 1,509.20 $ 1,522.84 $ 1,507.00 $ 1,521.95 4954988 2018-02-27 $ 1,524.50 $ 1,526.78 $ 1,507.21 $ 1,511.98 4808776 2018-02-28 $ 1,519.51 $ 1,528.70 $ 1,512.00 $ 1,512.45 4515023 2018-03-01 $ 1,513.60 $ 1,518.49 $ 1,465.00 $ 1,493.45 6835230
intradayData$AAPL%>%head()%>%as.data.frame()%>%make_stock_formattable()
open high low close volume 2019-02-15 14:30:00 $ 171.22 $ 171.70 $ 171.00 $ 171.13 2412697 2019-02-15 14:35:00 $ 171.13 $ 171.23 $ 170.49 $ 171.06 273892 2019-02-15 14:40:00 $ 171.08 $ 171.08 $ 170.34 $ 170.37 230501 2019-02-15 14:45:00 $ 170.40 $ 170.85 $ 170.13 $ 170.22 279939 2019-02-15 14:50:00 $ 170.19 $ 170.20 $ 169.76 $ 169.92 363468 2019-02-15 14:55:00 $ 169.92 $ 170.56 $ 169.91 $ 170.46 223322
intradayData$AMZN%>%head()%>%as.data.frame()%>%make_stock_formattable()
open high low close volume 2019-02-15 14:30:00 $ 1,627.09 $ 1,628.91 $ 1,621.51 $ 1,622.34 233071 2019-02-15 14:35:00 $ 1,621.62 $ 1,622.55 $ 1,615.00 $ 1,620.22 46206 2019-02-15 14:40:00 $ 1,620.20 $ 1,620.20 $ 1,613.99 $ 1,614.54 41530 2019-02-15 14:45:00 $ 1,615.33 $ 1,620.49 $ 1,614.21 $ 1,615.54 32880 2019-02-15 14:50:00 $ 1,615.59 $ 1,615.59 $ 1,612.00 $ 1,612.68 31449 2019-02-15 14:55:00 $ 1,612.49 $ 1,615.59 $ 1,611.69 $ 1,612.26 27608

Charting

The robinhoodQF package allows you to build interactive plotly charts for visualizing price series and plotting technical indicators.

myChart <- create_chart(tickerSymbol="AAPL", ohlcvData=dailyData$AAPL)
myChart$create_plot("candlestick")

## plot just closing prices
p1<-myChart$pricePlot
tmpFile1 <- tempfile(fileext = ".png")
export(p1, file = tmpFile1)

## plot closing prices with volume
p2<-myChart$volumeCombinedPlot
tmpFile2 <- tempfile(fileext = ".png")
export(p2, file = tmpFile2)

Account Information

library(DT)
get_watchlist_tickers()
##  [1] "TQQQ" "LOGC" "MGTX" "AVRO" "ORTX" "SPXS" "VIXY" "VXX"  "TSRO" "QQQ" 
## [11] "ALL"  "MXIM" "SPY"  "CELG" "MRO"  "AAL"  "DLTR" "JPM"  "BK"   "GOOG"
## [21] "MA"   "PGR"  "ATHX" "CHK"  "TWOU" "C"    "BA"   "CRM"  "FLO"  "WMT" 
## [31] "ARKR" "IZRL" "ARKQ" "ARKG" "ARKW" "ARKK" "APPN" "SGH"  "WDC"  "OLED"
## [41] "OKTA" "DBX"  "KEM"  "NVDA" "MOMO" "ICHR" "ABT"  "NFLX" "HIMX" "LRCX"
## [51] "BZUN" "FB"   "YY"   "ABBV" "AAOI" "VZ"   "SMI"  "SODA" "BAC"  "TSM" 
## [61] "SNAP" "SQ"   "TXN"  "AMD"  "ACLS" "INTC" "ASX"  "MCHP" "MU"   "ON"  
## [71] "AMAT" "CSCO" "AKAM" "MLNX" "QCOM" "AGNC" "AAPL" "F"    "OCSL" "KO"
holdings<-get_equity_holdings()
holdings$table%>%as.data.frame()%>%datatable()

holdings$tickers
##  [1] "XBI"  "CZZ"  "IEMG" "SQQQ" "XLF"  "AMZN" "MSFT" "BABA" "V"    "NTNX"
robinhoodUser$account$positionsTable%>%as.data.frame()%>%datatable()

robinhoodUser$account$optionsPositionsTable%>%as.data.frame()%>%datatable()

robinhoodUser$account$portfolioEquity
## NULL


QuantumFuse/robinhoodQF documentation built on Sept. 27, 2019, 1:57 p.m.