Skip to content

av module

Module with AVData.


AVData class

AVData(
    wrapper,
    data,
    single_key=True,
    classes=None,
    level_name=None,
    fetch_kwargs=None,
    returned_kwargs=None,
    last_index=None,
    delisted=None,
    tz_localize=None,
    tz_convert=None,
    missing_index=None,
    missing_columns=None,
    **kwargs
)

Data class for fetching from Alpha Vantage.

See https://www.alphavantage.co/documentation/ for API.

Apart of using https://github.com/RomelTorres/alpha_vantage package, this class can also parse the API documentation with AVData.parse_api_meta() using BeautifulSoup4 and build the API query based on this metadata (pass use_parser=True).

This approach is the most flexible we can get since we can instantly react to Alpha Vantage's changes in the API. If the data provider changes its API documentation, you can always adapt the parsing procedure by overriding AVData.parse_api_meta().

If parser still fails, you can disable parsing entirely and specify all information manually by setting function and disabling match_params

See AVData.fetch_symbol() for arguments.

Usage

  • Set up the API key globally (optional):
>>> from vectorbtpro import *

>>> vbt.AVData.set_custom_settings(
...     apikey="YOUR_KEY"
... )
  • Pull data:
>>> data = vbt.AVData.pull(
...     "GOOGL",
...     timeframe="1 day",
... )

>>> data = vbt.AVData.pull(
...     "BTC_USD",
...     timeframe="30 minutes",  # premium?
...     category="digital-currency",
...     outputsize="full"
... )

>>> data = vbt.AVData.pull(
...     "REAL_GDP",
...     category="economic-indicators"
... )

>>> data = vbt.AVData.pull(
...     "IBM",
...     category="technical-indicators",
...     function="STOCHRSI",
...     params=dict(fastkperiod=14)
... )

Superclasses

Inherited members


fetch_symbol class method

AVData.fetch_symbol(
    symbol,
    use_parser=None,
    apikey=None,
    api_meta=None,
    category=None,
    function=None,
    timeframe=None,
    tz=None,
    adjusted=None,
    extended=None,
    slice=None,
    series_type=None,
    time_period=None,
    outputsize=None,
    match_params=None,
    params=None,
    read_csv_kwargs=None,
    silence_warnings=None
)

Fetch a symbol from Alpha Vantage.

If use_parser is False, or None and alpha_vantage is installed, uses the package. Otherwise, parses the API documentation and pulls data directly.

See https://www.alphavantage.co/documentation/ for API endpoints and their parameters.

Note

Supports the CSV format only.

Args

symbol : str

Symbol.

May combine symbol/from_currency and market/to_currency using an underscore.

use_parser : bool
Whether to use the parser instead of the alpha_vantage package.
apikey : str
API key.
api_meta : dict

API meta.

If None, will use AVData.parse_api_meta() if function is not provided or match_params is True.

category : str or AlphaVantage

API category of your choice.

Used if function is not provided or match_params is True.

Supported are:

  • alpha_vantage.alphavantage.AlphaVantage instance, class, or class name
  • "time-series-data" or "time-series"
  • "fundamental-data" or "fundamentals"
  • "foreign-exchange", "forex", or "fx"
  • "digital-currency", "cryptocurrencies", "cryptocurrency", or "crypto"
  • "commodities"
  • "economic-indicators"
  • "technical-indicators" or "indicators"
function : str or callable

API function of your choice.

If None, will try to resolve it based on other arguments, such as timeframe, adjusted, and extended. Required for technical indicators, economic indicators, and fundamental data.

See the keys in sub-dictionaries returned by AVData.parse_api_meta().

timeframe : str

Timeframe.

Allows human-readable strings such as "15 minutes".

For time series, forex, and crypto, looks for interval type in the function's name. Defaults to "60min" if extended, otherwise to "daily".

tz : any

Timezone.

See to_timezone().

adjusted : bool
Whether to return time series adjusted by historical split and dividend events.
extended : bool
Whether to return historical intraday time series for the trailing 2 years.
slice : str
Slice of the trailing 2 years.
series_type : str
The desired price type in the time series.
time_period : int
Number of data points used to calculate each window value.
outputsize : str

Output size.

Supported are

  • "compact" that returns only the latest 100 data points
  • "full" that returns the full-length time series
match_params : bool

Whether to match parameters with the ones required by the endpoint.

Otherwise, uses only (resolved) function, apikey, datatype="csv", and params.

params
Additional keyword arguments passed as key/value pairs in the URL.
read_csv_kwargs : dict
Keyword arguments passed to pd.read_csv.
silence_warnings : bool
Whether to silence all warnings.

For defaults, see custom.av in data.


list_symbols class method

AVData.list_symbols(
    keywords,
    apikey=None,
    sort=True
)

List all symbols.


parse_api_meta class method

AVData.parse_api_meta(
    cls
)

Parse API metadata from the documentation at https://www.alphavantage.co/documentation

Cached class method. To avoid re-parsing the same metadata in different runtimes, save it manually.