Skip to contents

Downloads and caches financial market datasets from B3 (Brazilian Stock Exchange) based on predefined templates. Handles file downloading and caching.

Usage

download_marketdata(template, do_cache = FALSE, ...)

Arguments

template

character string specifying the template name

do_cache

logical; if TRUE forces a new download even if cached file exists (default: FALSE)

...

additional arguments passed to template-specific download functions

Value

Returns a meta object containing the downloaded file's metadata:

  • template - Name of the template used

  • download_checksum - Unique hash code for the download

  • download_args - Arguments passed via ...

  • downloaded - Path to the downloaded file

  • created - Timestamp of file creation

A meta object containing the downloaded file's metadata. This meta object is used with the read_marketdata function to read the downloaded file.

Details

The function follows this workflow:

  1. Checks if requested data exists in cache

  2. Downloads data if needed (based on template specifications)

  3. Manages file compression and storage

  4. Maintains metadata for tracking and verification

Files are organized in the rb3.cachedir as follows:

  • Metadata: JSON files in 'meta/' directory, named by download_checksum

  • Data: Gzipped files in 'raw/' directory, named by file's checksum

Templates are YAML documents that define:

  • Download parameters and methods

  • Data reading instructions

  • Dataset structure (columns, types)

Templates can be found using list_templates() and retrieved with template_retrieve().

See also

read_marketdata, rb3.cachedir

Examples

if (FALSE) { # \dontrun{
# Download daily market data
meta <- download_marketdata("b3-cotahist-daily", 
                            refdate = as.Date("2024-04-05"))
read_marketdata(meta)

# Download reference rates
meta <- download_marketdata("b3-reference-rates",
                            refdate = as.Date("2024-04-05"),
                            curve_name = "PRE")
read_marketdata(meta)
} # }