market_data | R Documentation |
The bars API provides time-aggregated price and volume data for a single stock or multiple. The v2
(Polygon) API is only available for live accounts and accepts the from
, to
, timeframe
, multiplier
, and unadjusted
arguments.
market_data(
symbol,
v = 2,
timeframe = "day",
multiplier = 1,
from = NULL,
to = NULL,
after = NULL,
until = NULL,
limit = NULL,
full = FALSE,
unadjusted = FALSE
)
symbol |
|
v |
|
timeframe |
For the
For the
|
multiplier |
For the |
from |
(equivalent to |
to |
(equivalent to |
after |
|
until |
|
limit |
v1 & v2 |
full |
|
unadjusted |
polygon only |
adjustment |
Deprecated |
All values to from/after/to/until
will parse correctly if a numeric year, in YYYY-MM-DD
RFC 3339 format or (Datetime/POSIXct)
, YYYY-MM-DD HH:MM
ISO8601 format. Other formats will often work, but are not guaranteed to parse correctly. All Dates/Datetimes are forced to America/New York timezone (See force_tz
) in which the NYSE operates. This means that if now
is used to specify 3PM in the local timezone, it will be forced 3PM in the "America/New_York timezone. This eliminates needing to consistently account for timezone conversions when providing inputs. The polygon
API only accepts Dates in YYYY-MM-DD format, any arguments passed to start
or end
will be coerced to Date automatically if using polygon
. For the polygon
API, queries with timeframe
: 'year'
use 12/31
as an aggregate date for each year. Arguments passed to from
& to
will be coerced to their yearly round_date
and ceiling_date
respectively.
For a full overview of how the Polygon.io Aggregates endpoint behaves, check out https://polygon.io/blog/aggs-api-updates/.
tsymble
object if just one symbol is requested, otherwise a named list
of tsymble
objects for each ticker symbol.
A tsymble
is a tsibble
object with the following columns:
time
the time of the bar as POSIXct
in yyyy-mm-dd for timeframe = day, and yyyy-mm-dd hh:mm:ss for timeframes < day
open
(numeric)
open price
high
(numeric)
high price
low
(numeric)
low price
close
(numeric)
close price
volume
(numeric)
volume (in millions)
vw *polygon only*
(numeric)
the volume weighted average price
n *polygon only*
(numeric)
Number of items in aggregate window
Each tsymble
has a "query" attribute with the "query" data as a list
for each of the calls required to return it and a "symbol" attribute with the ticker symbol for the data. These attributes are easily accessed via get_query
and get_sym
respectively.
## Not run:
# Getting data for the last week from the v1 API:
market_data(symbol = c("INTC","MSFT"), v = 1, from = Sys.Date() - lubridate::weeks(1))
# Getting price data with specific date ranges and timeframes with limit on the number of bars returned
market_data(symbol = c("INTC","MSFT"), from = "2019-03-20", to = "2019-04-01", multiplier = 15, timeframe = "min", limit = 175, v = 1)
# Get the last trade for a symbol (or multiple):
market_data("TWTR", timeframe = "lt")
# or the last quote for multiple symbols:
market_data(c("TWTR","AAPL","BYND"), timeframe = "lq")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.