Title: Comprehensive R Wrapper for 'Alphavantage Financial Data' API
Version: 0.3.2
Description: Download 'Alphavantage financial data' https://www.alphavantage.co/documentation/ to reduced 'data.table' objects. Includes support functions to extract and simplify complex data returned from API calls.
License: GPL (≥ 3)
Encoding: UTF-8
Depends: R (≥ 4.1.0)
Imports: dplyr (≥ 1.0.0), data.table, glue (≥ 1.1.1), httr (≥ 1.2.1), jsonlite (≥ 1.5), purrr (≥ 1.0), readr (≥ 1.1.1), stringr (≥ 1.2.0), timeDate (≥ 4000.0), lubridate (≥ 1.0.0), utils (≥ 4.0.0), tidyr (≥ 0.6.3)
Suggests: testthat, knitr, rmarkdown
RoxygenNote: 7.3.3
VignetteBuilder: knitr
URL: https://github.com/derekholmes0/alphavantagepf
BugReports: https://github.com/derekholmes0/alphavantagepf/issues
NeedsCompilation: no
Packaged: 2026-01-19 13:33:02 UTC; DFH
Author: Derek Holmes [aut, cre, cph], Matt Dancho [ctb]
Maintainer: Derek Holmes <derek@derekholmes.com>
Repository: CRAN
Date/Publication: 2026-01-22 21:40:02 UTC

alphavantagepf: A lightweight R interface to the Alpha Vantage API

Description

An R interface to the Alpha Vantage API which emphasizes normalized data nd data.table conventions

Details

The alphavantagepf package provides a lightweight interface to the Alpha Vantage API. Alpha Vantage is a free source for financial data that in many cases is more accurate than Yahoo Finance and Google Finance. Get a free API KEY at https://www.alphavantage.co. Then use the R interface functions av_api_key("YOUR_KEY") to set the API key and the av_get_pf() function to get financial data.


Set the Alpha Vantage API Key

Description

av_api_key() sets Alphavantage API key and entitlement code

Usage

av_api_key(api_key, entitlement = NULL)

Arguments

api_key

A character string with your Alpha Vantage API Key.

entitlement

A character string with your Alpha Vantage entitlement status. If not "delayed" or "realtime" entitlement not added to API string.

Details

The Alpha Vantage API key must be set prior to using av_get_pf(). You can obtain an API key at the Alpha Vantage Website.

Value

Invisibly returns two item list with API key and entitlement string once set). Use print method to view.

See Also

av_get_pf()

Examples

## Not run: 
av_api_key("YOUR_API_KEY",entitlement="delayed")
av_get_pf("IBM", "TIME_SERIES_INTRADAY")

## End(Not run)


Extract data from Alpha Vantage returned data

Description

av_extract_df() pulls out nested data.frames from mixed data returned by av_get_pf() av_extract_fx() returns a simplified FX quote in data.table formfrom av_get_pf() calls. av_extract_analytics() returns melted data.table from calls to av_get_pf("ANALYTICS_FIXED_WINDOW") or av_get_pf("ANALYTICS_SLIDING_WINDOW")

Usage

av_extract_df(indta, grepstring = "", melt = FALSE)

av_extract_fx(indta)

av_extract_analytics(indta, separate_vars = FALSE)

Arguments

indta

A data.table as returned by av_get()

grepstring

select which variable (data item) to unnest in data.table returned from av_get_pf

melt

Return data in melted/normalized form

separate_vars

(default : FALSE) separate out multiple levels of variable names into new keys

Details

av_get_pf() frequently returns a nested data.table, or a structure with nested data.frames. These are utilities functions to extract, filter and summarize returned values.

Value

Extracted data.tables for nested data returned from av_get_pf(), If grepstring is not specified, first nested table is returned. av_extract_fx() returns a shortened data.table with FX quotes.

See Also

av_get_pf(), av_grep_opts()

Examples

## Not run: 
av_get_pf("","MARKET_STATUS")  |> av_extract_df()
av_get_pf("","TOP_GAINERS_LOSERS") |> av_extract_df("top_losers")
av_get_pf("USD/BRL","CURRENCY_EXCHANGE_RATE") |> av_extract_fx()
av_get_pf(c("ORCL","IBM"),"ANALYTICS_FIXED_WINDOW") |> av_extract_analytics(separate_vars=TRUE)

## End(Not run)


Extract data from Alpha Vantage retuned data

Description

Extract data from Alpha Vantage retuned data

Usage

av_funhelp(av_fun_grep = "", verbose = TRUE)

Arguments

av_fun_grep

A Alpha Vantage function name or portions of one. For a list of parameters, visit the Alpha Vantage API documentation.

verbose

(Default: TRUE) Prints the help string

Details

Returns defaults and parameter lists for Alphavantage functions

Value

Help Text and default parameters.

See Also

av_get_pf()

Examples

av_funhelp("GLOBAL_QUOTE")


Get financial data from the Alpha Vantage API

Description

Interface to alphavantage API.

Usage

av_get_pf(
  symbol,
  av_fun,
  symbolvarnm = "symbol",
  dfonerror = TRUE,
  melted = "default",
  verbose = FALSE,
  ...
)

Arguments

symbol

A character string of an appropriate stock, fund, or currency See parameter "symbol" in Alpha Vantage API documentation.

av_fun

A character string matching an appropriate Alpha Vantage "function". See parameter "function" in Alpha Vantage API documentation.

symbolvarnm

(default: symbol) Variable name which has the symbol requested. Set to a blank string if not wanted.

dfonerror

(default: TRUE) Return an empty data.table when any error occurs

melted

(default: "default") String specifying when to melt, "default" is chosen by the package, "TRUE|always" always melt, "FALSE|never" never melts

verbose

(default: FALSE) Print debug information helpful for errors. Also copies full url to clipboard.

...

Additional parameters or overrides passed to the Alpha Vantage API. For a list of parameters, visit the Alpha Vantage API documentation.

Details

The av_fun argument replaces the API parameter “function” because function is a reserved name in R. All other arguments match the Alpha Vantage API parameters.

There is no need to specify the apikey, datatype, outputsize or entitlement parameters as arguments to av_get_pf(). Before using, you must set the API key using av_api_key("YOUR_API_KEY"). outputsize defaults to "full" unless overridden with "compact in ...."

Required parameters other than symbol must be passed as named arguments via ....

Optional parameters have defaults which can be obtained by calling av_funhelp() and overridden via ....

There is no need to specify the datatype parameter as an argument to av_get_pf(). The function will return a data.table.

ForEx "FROM/TO" symbol details. FOREX symbols in the av_get_pf() function are supplied in "FROM/TO" format, which are then parsed in the Alpha Vantage API into from_currency and to_currency API parameters. Usage example: av_get_pf("USD/BRL", "FX_DAILY")

Value

Returns a data.table with results dependent on the function called. Mixed data is returned as a melted data.table, possibly with nested data.frames. Time series are returned as data.tables.

See Also

av_api_key(), av_extract_df(), av_extract_fx(), av_grep_opts(),av_funhelp()

Examples

## Not run: 
av_api_key("YOUR_API_KEY")
av_api_key("YOUR_API_KEY","delayed") # if you have such access

# example code

# ---- 1.0 SINGLE NAME EQUITY SUMMARY INFORMATION AND SEARCH ----

av_get_pf("IBM","OVERVIEW") |> str()

av_get_pf("EWZ","ETF_PROFILE")
av_get_pf("EWZ","ETF_PROFILE") |> av_extract_df("holdings")

av_get_pf("","SYMBOL_SEARCH",keywords="COMMERCE")

# ---- 2.0 MARKET QUOTES  ----

av_get_pf("IBM","GLOBAL_QUOTE")

av_get_pf("USD/BRL","CURRENCY_EXCHANGE_RATE") |> av_extract_fx()

av_get_pf(c("ORCL","IBM","EWZ","ARGT"),"REALTIME_BULK_QUOTES",melt=FALSE)
# Note you need advanced permissioning for REALTIME_BULK_QUOTES

# ---- 3.0 SINGLE NAME HISTORICAL DATA  ----

av_get_pf("IBM","TIME_SERIES_DAILY")

av_get_pf("IBM","TIME_SERIES_INTRADAY")

# ---- 4.0 MARKET PRICING DATA  ----

av_get_pf("","MARKET_STATUS")  |> av_extract_df()

av_get_pf("","TOP_GAINERS_LOSERS") |> av_extract_df("top_losers")

av_get_pf("","TREASURY_YIELD",maturity='7year')

 # ---- 4.0 SINGLE NAME NON-PRICING DATA  ----

av_get_pf("IBM","DIVIDENDS")

av_get_pf("IBM","EARNINGS")  |> av_extract_df("quarter",melt=TRUE)

av_get_pf("IBM","NEWS_SENTIMENT") |> av_extract_df("feed")

av_get_pf("IBM","EARNINGS_CALL_TRANSCRIPT",quarter="2024Q3")  |> av_extract_df("transcript")
 # Note that quarter is a required parameter, not specifying will throw an error

 # ---- 5.0 SINGLE NAME OPTION PRICING DATA  ----

av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2)

# ---- 6.0 TECHNICAL INDICATORS  ----

av_funhelp("SMA")  # Shows parameters and defaults chosen by this package.
av_get_pf("IBM","SMA",time_period=20)

# ---- 7.0 WINDOW ANALYTICS  ----

av_get_pf(c("ORCL","IBM","EWZ","ARGT"),"ANALYTICS_FIXED_WINDOW",verbose=TRUE) |>
            av_extract_analytics(separate_vars=TRUE)

## End(Not run)


Extract data from Alpha Vantage returned data

Description

Extract data from Alpha Vantage returned data

Usage

av_grep_opts(
  indta,
  grepstring = "F,M,call",
  mindays = 3,
  startdt = Sys.Date(),
  deltarange = c(0.1, 0.55)
)

Arguments

indta

A data.table as returned by av_get_pf()

grepstring

(default ⁠F,M,call⁠) Three item string to select maturities and option types from indta. Each item is an abbreviated code for what to select.

  • How far out to go: F for first contract (e.g. front week), B for second/back contract, anything else for all contracts.

  • Maturity Schedule: M for monthly contracts, Q for quarterly contract, anythign else for weekly contracts.

  • Option Type: call, put, or all

mindays

(default 3). Minimum number of days to expiration to be passed through from startdt

startdt

(default Sys.Date()). Date from which expirations will be considered.

deltarange

(default c(0.1,0.55)) Two number list with minimum and maximum absolute valued deltas to pass through.

Details

av_get_pf() returns a large list of options. This function helps to narrow down the list by maturity and moneyness.

Value

A reduced set of options obtained from av_get_pf() using Alphavantage HISTORICAL_OPTIONS function.

See Also

av_get_pf()

Examples

## Not run: 
av_get_pf("IBM","HISTORICAL_OPTIONS") |> av_grep_opts("F,M,put",mindays=2)

## End(Not run)


Extract data from Alpha Vantage retuned data

Description

Extract data from Alpha Vantage retuned data

Usage

av_make_funcmap()

Details

Creates a data.table with API signatures and default values for Alphavantage API calls

Value

function map dat.table, also written to data directory

See Also

av_get_pf()

Examples

## Not run: 
av_make_funcmap()

## End(Not run)

mirror server hosted at Truenetwork, Russian Federation.