Skip to contents

Retrieve time series data from the Banco de México Sistema de Información Económica (SIE) API.

Usage

banxico_data(
  series,
  start_date = NULL,
  end_date = NULL,
  api_key = banxico_key()
)

Arguments

series

(character())
One or more SIE series codes to query (e.g., "SF43718" for the FIX peso/US dollar exchange rate). Series codes can be found on the SIE website.

start_date

(NULL | Date(1) | character(1))
Start date of the data (e.g., "2024-01-01"). Must be paired with end_date. If both are NULL, the full history is returned. Default NULL.

end_date

(NULL | Date(1) | character(1))
End date of the data, in the same format as start_date. Must be paired with start_date. If both are NULL, the full history is returned. Default NULL.

api_key

(character(1))
The SIE API token. Defaults to the BANXICO_KEY environment variable.

Value

A data.table::data.table() with columns date, key, and value.

Details

The SIE API requires a free access token. Request one at https://www.banxico.org.mx/SieAPIRest/service/v1/token and supply it via the api_key argument or the BANXICO_KEY environment variable.

Supply both start_date and end_date to restrict the period, or neither to return the complete history of each series. Supplying only one is an error.

Examples

if (FALSE) { # curl::has_internet() && nzchar(Sys.getenv("BANXICO_KEY"))
# \donttest{
# fetch the FIX peso/US dollar exchange rate
banxico_data("SF43718", start_date = "2024-01-01", end_date = "2024-01-31")

# fetch multiple series at once
banxico_data(c("SF43718", "SF60653"), start_date = "2024-01-01", end_date = "2024-01-31")
# }
}