Skip to contents

Retrieve time series data from the ECB SDMX Web Service.

Usage

ecb_data(
  flow,
  key = NULL,
  start_period = NULL,
  end_period = NULL,
  first_n = NULL,
  last_n = NULL,
  updated_after = NULL
)

Arguments

flow

(character(1))
Flow to query.

key

(NULL | character())
The series keys to query.

start_period

(NULL | character(1) | integer(1))
Start date of the data. Supported formats:

  • YYYY for annual data (e.g., 2019)

  • YYYY-S[1-2] for semi-annual data (e.g., "2019-S1")

  • YYYY-Q[1-4] for quarterly data (e.g., "2019-Q1")

  • YYYY-MM for monthly data (e.g., "2019-01")

  • YYYY-W[01-53] for weekly data (e.g., "2019-W01")

  • YYYY-MM-DD for daily and business data (e.g., "2019-01-01")

If NULL, no start date restriction is applied (data retrieved from the earliest available date). Default NULL.

end_period

(NULL | character(1) | integer(1))
End date of the data, in the same format as start_period. If NULL, no end date restriction is applied (data retrieved up to the most recent available date). Default NULL.

first_n

(NULL | numeric(1))
Number of observations to retrieve from the start of the series. If NULL, no restriction is applied. Default NULL.

last_n

(NULL | numeric(1))
Number of observations to retrieve from the end of the series. If NULL, no restriction is applied. Default NULL.

updated_after

(NULL | character(1) | Date(1) | POSIXct(1))
Retrieve only observations updated after the given timestamp (e.g., "2024-06-01T00:00:00"). Useful for incremental retrieval. If NULL, no restriction is applied. Default NULL.

Value

A data.table::data.table() with the requested data.

Examples

# \donttest{
# fetch US dollar/Euro exchange rate
ecb_data("EXR", "D.USD.EUR.SP00.A")
#> Error in req_perform(req_error(req_url_query(req_url_path_append(req_headers(base_request(base_url),     accept = accept), resource), ...), body = error_body)): HTTP 504 Gateway Timeout.
#> ℹ See docs at <https://data.ecb.europa.eu/help/api/status-codes>

# fetch data for multiple keys
ecb_data("EXR", c("D.USD", "JPY.EUR.SP00.A"))
#>              date              key    value   freq
#>            <Date>           <char>    <num> <char>
#>     1: 1999-01-04 D.JPY.EUR.SP00.A 133.7300  daily
#>     2: 1999-01-05 D.JPY.EUR.SP00.A 130.9600  daily
#>     3: 1999-01-06 D.JPY.EUR.SP00.A 131.4200  daily
#>     4: 1999-01-07 D.JPY.EUR.SP00.A 129.4300  daily
#>     5: 1999-01-08 D.JPY.EUR.SP00.A 130.0900  daily
#>    ---                                            
#> 14332: 2026-09-28 D.USD.EUR.SP00.A   1.1378  daily
#> 14333: 2026-09-29 D.USD.EUR.SP00.A   1.1355  daily
#> 14334: 2026-09-30 D.USD.EUR.SP00.A   1.1355  daily
#> 14335: 2026-10-01 D.USD.EUR.SP00.A   1.1298  daily
#> 14336: 2026-10-02 D.USD.EUR.SP00.A   1.1225  daily
#>                                                title
#>                                               <char>
#>     1: Japanese yen/Euro ECB reference exchange rate
#>     2: Japanese yen/Euro ECB reference exchange rate
#>     3: Japanese yen/Euro ECB reference exchange rate
#>     4: Japanese yen/Euro ECB reference exchange rate
#>     5: Japanese yen/Euro ECB reference exchange rate
#>    ---                                              
#> 14332:    US dollar/Euro ECB reference exchange rate
#> 14333:    US dollar/Euro ECB reference exchange rate
#> 14334:    US dollar/Euro ECB reference exchange rate
#> 14335:    US dollar/Euro ECB reference exchange rate
#> 14336:    US dollar/Euro ECB reference exchange rate
#>                                                             description
#>                                                                  <char>
#>     1: ECB reference exchange rate, Japanese yen/Euro, 2.15 pm (C.E.T.)
#>     2: ECB reference exchange rate, Japanese yen/Euro, 2.15 pm (C.E.T.)
#>     3: ECB reference exchange rate, Japanese yen/Euro, 2.15 pm (C.E.T.)
#>     4: ECB reference exchange rate, Japanese yen/Euro, 2.15 pm (C.E.T.)
#>     5: ECB reference exchange rate, Japanese yen/Euro, 2.15 pm (C.E.T.)
#>    ---                                                                 
#> 14332:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14333:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14334:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14335:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14336:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#>        currency currency_denom exr_type exr_suffix unit_index_base decimals
#>          <char>         <char>   <char>     <char>          <char>   <char>
#>     1:      JPY            EUR     SP00          A        99Q1=100        2
#>     2:      JPY            EUR     SP00          A        99Q1=100        2
#>     3:      JPY            EUR     SP00          A        99Q1=100        2
#>     4:      JPY            EUR     SP00          A        99Q1=100        2
#>     5:      JPY            EUR     SP00          A        99Q1=100        2
#>    ---                                                                     
#> 14332:      USD            EUR     SP00          A        99Q1=100        4
#> 14333:      USD            EUR     SP00          A        99Q1=100        4
#> 14334:      USD            EUR     SP00          A        99Q1=100        4
#> 14335:      USD            EUR     SP00          A        99Q1=100        4
#> 14336:      USD            EUR     SP00          A        99Q1=100        4
#>        source_agency unit_mult time_format collection   unit
#>               <char>    <char>      <char>     <char> <char>
#>     1:           4F0         0         P1D          A    JPY
#>     2:           4F0         0         P1D          A    JPY
#>     3:           4F0         0         P1D          A    JPY
#>     4:           4F0         0         P1D          A    JPY
#>     5:           4F0         0         P1D          A    JPY
#>    ---                                                      
#> 14332:           4F0         0         P1D          A    USD
#> 14333:           4F0         0         P1D          A    USD
#> 14334:           4F0         0         P1D          A    USD
#> 14335:           4F0         0         P1D          A    USD
#> 14336:           4F0         0         P1D          A    USD
# }