knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Alphavantagepf interfaces the Alphavantage API to R in a way most compatible with normalized data stores. It returns data in data.table format, which is really
the best choice for financial time series analysis.
library(alphavantagepf)
There is one main function to call to access all of the API functionality provided by Alphavantage.
av_api_key("YOUR_API_KEY") print(av_api_key())
To find parameters and defaults provided by the alphavantagepf package, use av_funhelp()
av_funhelp("SERIES_INTRADAY")
Required parameters are listed with "R" and optional parameters (and any default provided by this package) are listed with "O"
Once the API key has been set, use the function av_get_pf() which requires at minimum two arguments, a symbol (put first to facilitate usage in pipes) and an Alphavantage "function" av_fun.
The resulting output will be a data.table that depends on the type of data requested. (Note that data is returned in a data.table, which can be cast as tibbles as necessary.)
The output will always include the symbol requested or the name of the av_fun used if a symbol isn't relevent. If that variable isn't wanted (e.g. when called within a grouping function group_by(symbol) |> do({}) then set symbolvarnm="".
Most other data will be a long-form (melted) datatable with at least the following columns:
symbol will either be the symbol requested or the value of av_fun if a symbol isn't relevant.
variable which is the name of the data item
value_str, value_num and/or value_df which will contain strings (converted to numeric if possible) or (in the case of value_df) a nested data.frame.
ltype is the inferred data-type, helpful for selecting the correct columns.
av_get_pf("IBM","TIME_SERIES_INTRADAY") |> head() symbol timestamp open high low close volume <char> <IDat> <num> <num> <num> <num> <int> 1: IBM 1999-11-01 98.5 98.8 96.4 96.8 9551800 2: IBM 1999-11-02 96.8 96.8 93.7 94.8 11105400
av_get_pf("","TOP_GAINERS_LOSERS") Key: <variable> symbol variable ltype value_df value_str value_num <char> <char> <char> <list> <char> <num> 1: TOP_GAINERS_LOSERS last_updated numeric [NULL] 2026-01-05 16:15:59 US/Eastern 2026 2: TOP_GAINERS_LOSERS metadata character [NULL] Top gainers, losers, and most actively t NA 3: TOP_GAINERS_LOSERS most_actively_traded list <data.frame[20x5]> NULL NA 4: TOP_GAINERS_LOSERS top_gainers list <data.frame[20x5]> NULL NA 5: TOP_GAINERS_LOSERS top_losers list <data.frame[20x5]> NULL NA
av_extract_dfExtracting the nested data.frames can be a tedious task, so the helper function av_extract_df() can be used to filter for the correct variable and extract the data.frame
av_get_pf("","TOP_GAINERS_LOSERS") |> av_extract_df("top_losers") Key: <variable> symbol variable ltype value_df value_str value_num <char> <char> <char> <list> <char> <num> 1: TOP_GAINERS_LOSERS last_updated numeric [NULL] 2026-01-05 16:15:59 US/Eastern 2026 2: TOP_GAINERS_LOSERS metadata character [NULL] Top gainers, losers, and most actively t NA 3: TOP_GAINERS_LOSERS most_actively_traded list <data.frame[20x5]> NULL NA 4: TOP_GAINERS_LOSERS top_gainers list <data.frame[20x5]> NULL NA 5: TOP_GAINERS_LOSERS top_losers list <data.frame[20x5]> NULL NA
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.