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")
#>             date              key  value   freq
#>           <Date>           <char>  <num> <char>
#>    1: 1999-01-04 D.USD.EUR.SP00.A 1.1789  daily
#>    2: 1999-01-05 D.USD.EUR.SP00.A 1.1790  daily
#>    3: 1999-01-06 D.USD.EUR.SP00.A 1.1743  daily
#>    4: 1999-01-07 D.USD.EUR.SP00.A 1.1632  daily
#>    5: 1999-01-08 D.USD.EUR.SP00.A 1.1659  daily
#>   ---                                          
#> 7189: 2026-11-02 D.USD.EUR.SP00.A 1.1216  daily
#> 7190: 2026-11-03 D.USD.EUR.SP00.A 1.1179  daily
#> 7191: 2026-11-04 D.USD.EUR.SP00.A 1.1267  daily
#> 7192: 2026-11-05 D.USD.EUR.SP00.A 1.1224  daily
#> 7193: 2026-11-06 D.USD.EUR.SP00.A 1.1165  daily
#>                                            title
#>                                           <char>
#>    1: US dollar/Euro ECB reference exchange rate
#>    2: US dollar/Euro ECB reference exchange rate
#>    3: US dollar/Euro ECB reference exchange rate
#>    4: US dollar/Euro ECB reference exchange rate
#>    5: US dollar/Euro ECB reference exchange rate
#>   ---                                           
#> 7189: US dollar/Euro ECB reference exchange rate
#> 7190: US dollar/Euro ECB reference exchange rate
#> 7191: US dollar/Euro ECB reference exchange rate
#> 7192: US dollar/Euro ECB reference exchange rate
#> 7193: US dollar/Euro ECB reference exchange rate
#>                                                         description currency
#>                                                              <char>   <char>
#>    1: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#>    2: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#>    3: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#>    4: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#>    5: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#>   ---                                                                       
#> 7189: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 7190: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 7191: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 7192: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 7193: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#>       currency_denom exr_type exr_suffix unit_index_base unit_mult time_format
#>               <char>   <char>     <char>          <char>    <char>      <char>
#>    1:            EUR     SP00          A        99Q1=100         0         P1D
#>    2:            EUR     SP00          A        99Q1=100         0         P1D
#>    3:            EUR     SP00          A        99Q1=100         0         P1D
#>    4:            EUR     SP00          A        99Q1=100         0         P1D
#>    5:            EUR     SP00          A        99Q1=100         0         P1D
#>   ---                                                                         
#> 7189:            EUR     SP00          A        99Q1=100         0         P1D
#> 7190:            EUR     SP00          A        99Q1=100         0         P1D
#> 7191:            EUR     SP00          A        99Q1=100         0         P1D
#> 7192:            EUR     SP00          A        99Q1=100         0         P1D
#> 7193:            EUR     SP00          A        99Q1=100         0         P1D
#>       collection   unit source_agency decimals
#>           <char> <char>        <char>   <char>
#>    1:          A    USD           4F0        4
#>    2:          A    USD           4F0        4
#>    3:          A    USD           4F0        4
#>    4:          A    USD           4F0        4
#>    5:          A    USD           4F0        4
#>   ---                                         
#> 7189:          A    USD           4F0        4
#> 7190:          A    USD           4F0        4
#> 7191:          A    USD           4F0        4
#> 7192:          A    USD           4F0        4
#> 7193:          A    USD           4F0        4

# 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
#>    ---                                            
#> 14382: 2026-11-02 D.USD.EUR.SP00.A   1.1216  daily
#> 14383: 2026-11-03 D.USD.EUR.SP00.A   1.1179  daily
#> 14384: 2026-11-04 D.USD.EUR.SP00.A   1.1267  daily
#> 14385: 2026-11-05 D.USD.EUR.SP00.A   1.1224  daily
#> 14386: 2026-11-06 D.USD.EUR.SP00.A   1.1165  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
#>    ---                                              
#> 14382:    US dollar/Euro ECB reference exchange rate
#> 14383:    US dollar/Euro ECB reference exchange rate
#> 14384:    US dollar/Euro ECB reference exchange rate
#> 14385:    US dollar/Euro ECB reference exchange rate
#> 14386:    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.)
#>    ---                                                                 
#> 14382:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14383:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14384:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14385:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 14386:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#>        currency currency_denom exr_type exr_suffix unit_index_base unit_mult
#>          <char>         <char>   <char>     <char>          <char>    <char>
#>     1:      JPY            EUR     SP00          A        99Q1=100         0
#>     2:      JPY            EUR     SP00          A        99Q1=100         0
#>     3:      JPY            EUR     SP00          A        99Q1=100         0
#>     4:      JPY            EUR     SP00          A        99Q1=100         0
#>     5:      JPY            EUR     SP00          A        99Q1=100         0
#>    ---                                                                      
#> 14382:      USD            EUR     SP00          A        99Q1=100         0
#> 14383:      USD            EUR     SP00          A        99Q1=100         0
#> 14384:      USD            EUR     SP00          A        99Q1=100         0
#> 14385:      USD            EUR     SP00          A        99Q1=100         0
#> 14386:      USD            EUR     SP00          A        99Q1=100         0
#>          unit time_format collection source_agency decimals
#>        <char>      <char>     <char>        <char>   <char>
#>     1:    JPY         P1D          A           4F0        2
#>     2:    JPY         P1D          A           4F0        2
#>     3:    JPY         P1D          A           4F0        2
#>     4:    JPY         P1D          A           4F0        2
#>     5:    JPY         P1D          A           4F0        2
#>    ---                                                     
#> 14382:    USD         P1D          A           4F0        4
#> 14383:    USD         P1D          A           4F0        4
#> 14384:    USD         P1D          A           4F0        4
#> 14385:    USD         P1D          A           4F0        4
#> 14386:    USD         P1D          A           4F0        4
# }