getpoly | R Documentation |
Download an OHLC time series of prices from Polygon.
getpoly(
symbol = "SPY",
startd = as.Date("1997-01-01"),
endd = Sys.Date(),
tspan = "day",
apikey
)
symbol |
The stock symbol (ticker). |
startd |
The start date (default is "1997-01-01"). |
endd |
The end date (default is |
tspan |
The data frequency, i.e. the time span for data aggregations (default is "day" for daily data). |
apikey |
The API key issued by Polygon. |
The function getpoly()
downloads historical prices from
Polygon, and returns an OHLC time series
of class xts.
Polygon is a provider of live and historical prices for stocks, options, foreign currencies, and cryptocurrencies.
The function getpoly()
sends a request for data to the
Polygon rest API, using the function
read_json()
from package
jsonlite.
The query requires an API key issued by Polygon.
The API key must be passed to the argument apikey
.
Polygon returns data in JSON format, which is then formatted into an OHLC time series of class xts.
The argument tspan
determines the data frequency, i.e. it's the time
span for data aggregations. The default is "day" for daily data. Other
possible values of tspan
are "minute", "hour", "week", and "month".
An OHLC time series of class xts.
## Not run:
# Polygon API key - user must obtain their own key
apikey <- "0Q2f7j8CwAbdY5M8VYt_8pwdP0V4TunxbvRVC_"
# Download SPY prices from Polygon
ohlc <- rutils::getpoly(symbol="SPY", apikey=apikey)
# Plot candlesticks of SPY OHLC prices
library(highcharter)
highcharter::highchart(type="stock") %>% hc_add_series(ohlc, type="candlestick")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.