The following section contains 3 simple examples in different programming languages to make use of the API.
The python package bcchapi contains classes and methods to make use of the BDE API. This facilitates data extraction for developers and analysts who wish to automate and standardize their processes. The main results of the available functions are delivered in a Pandas DataFrame object, although there are other possibilities according to the user's needs.
The package can be installed via pip from PyPI:
pip install bcchapi
Bcchapi provides the object Siete, wich allows the creation of statistical tables and searching for avilable series. When creating a new instance, the user must include his credentials or a file that contains them in the first two lines.
import bcchapi
# Including credentials explicitly
siete = bcchapi.Siete("user@example.com", "password")
# Or by calling a file
siete = bcchapi.Siete(file="credentials.txt")
If the user does not know the code of the time series to be retrieved,
the buscar()
method allows the search of a string within all
series names and returns their code and metadata in a pandas DataFrame.
siete.buscar("antofagasta", english=True)
# seriesId frequencyCode spanishTitle ...
# 0 F034.BESAN.IND.BCCH.2020.0.D DAILY Región de Antofagasta; Boletas electrónicas em... ...
# 1 F034.BESOAN.IND.BCCH.2020.0.D DAILY Región de Antofagasta; Boletas electrónicas em... ...
# 2 F022.CCPEAN.STO.Z.Z.Z.M MONTHLY Número de cuentas corrientes de personas natur... ...
# ... ... ... ... ...
# 167 F035.PIB.V12.R.CLP.2018.COM.Z.Z.02.0.A ANNUAL PIB Comercio, Región de Antofagasta, contribuc... ...
# 168 F035.PIB.V12.R.CLP.2018.RH.Z.Z.02.0.A ANNUAL PIB Restaurantes y hoteles, Región de Antofaga... ...
# 169 F035.PIB.V12.R.CLP.2018.Z.Z.Z.02.0.A ANNUAL PIB Región de Antofagasta, contribución porcen... ...
After finding the time series, the cuadro()
method can create
table similar to the ones found on the statistical data base:
siete.cuadro(
series=["F032.IMC.IND.Z.Z.EP18.Z.Z.0.M", "G073.IPC.IND.2018.M"],
nombres = ["imacec", "ipc"],
desde="2010-01-01",
hasta="2020-12-01",
variacion=12,
frecuencia="A",
observado={"imacec":"mean", "ipc":"last"}
)
# imacec ipc
# 2010-12-31 NaN NaN
# 2011-12-31 0.062239 0.044377
# 2012-12-31 0.061553 0.014870
# 2013-12-31 0.033085 0.030144
# 2014-12-31 0.017926 0.046464
# 2015-12-31 0.021519 0.043785
# 2016-12-31 0.017530 0.027087
# 2017-12-31 0.013577 0.022696
# 2018-12-31 0.039900 0.025632
# 2019-12-31 0.007431 0.030013
# 2020-12-31 -0.061452 0.029729
To retrieve time series data using R, use the following code. Example is for Monetary policy rate:
library("rjson")
url <- "https://si3.bcentral.cl/SieteRestWS/SieteRestWS.ashx?user=user@example.com&pass=yourPassword&firstdate=2015-01-01&lastdate=2021-01-31×eries=F022.TPM.TIN.D001.NO.Z.D&function=GetSeries"
json_data <- rjson::fromJSON(file = url)123456789
df_data <- as.data.frame(do.call(rbind, lapply(json_data$Series$Obs, as.vector)))
head(df_data)
# indexDateString value statusCode
# 1 02-01-2015 3 OK
# 2 03-01-2015 NeuN ND
# 3 04-01-2015 NeuN ND
# 4 05-01-2015 3 OK
# 5 06-01-2015 3 OK
# 6 07-01-2015 3 OK
Use the following example code to retrieve available monthly time series using SearchSeries
:
library("rjson")
url <- "https://si3.bcentral.cl/SieteRestWS/SieteRestWS.ashx?user=user@example.com&pass=yourPassword&frequency=MONTHLY&function=SearchSeries"
json_data <- rjson::fromJSON(file=url)
df_data <- as.data.frame(do.call(rbind, lapply(json_data$SeriesInfos, as.vector)))
head(df_data)
# seriesId frequencyCode
# 1 G073.IPCAV.V12.2018.M MONTHLY
# 2 G073.IPCAV.VAR.2018.M MONTHLY
# 3 G073.IPCBSV.V12.2018.M MONTHLY
# 4 G073.IPCBSV.VAR.2018.M MONTHLY
# 5 G073.IPCEN.V12.2018.M MONTHLY
# 6 G073.IPCEN.VAR.2018.M MONTHLY
# spanishTitle
# 1 IPC Alimentos volátiles, variación mismo periodo año anterior
# 2 IPC Alimentos volátiles, variación mensual
# 3 IPC Bienes sin volátiles, variación mismo periodo año anterior
# 4 IPC Bienes sin volátiles, variación mensual
# 5 IPC Energía volátiles, variación mismo periodo año anterior
# 6 IPC Energía volátiles, variación mensual
# englishTitle firstObservation
# 1 CPI Volatile Food, year to year percent changes 01-04-1990
# 2 CPI Volatile Food, monthly change 01-05-1989
# 3 CPI Goods without volatiles, year to year percent changes 01-04-1990
# 4 CPI Goods without volatiles, monthly change 01-05-1989
# 5 CPI Volatile Energy, year to year percent changes 01-04-1990
# 6 CPI Volatile Energy, monthly change 01-05-1989
# lastObservation updatedAt createdAt
# 1 01-06-2021 08-07-2021 08-07-2021
# 2 01-06-2021 08-07-2021 08-07-2021
# 3 01-06-2021 08-07-2021 08-07-2021
# 4 01-06-2021 08-07-2021 08-07-2021
# 5 01-06-2021 08-07-2021 08-07-2021
# 6 01-06-2021 08-07-2021 08-07-2021
The WSDL definition, developers technical handbook and sample application that verifies the connection to Web Services and its operating mode available here.