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
)

Arguments

flow

(character(1))
Flow to query.

key

(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.

Value

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

See also

Examples

# \donttest{
# fetch US dollar/Euro exchange rate
ecb_data("EXR", "D.USD.EUR.SP00.A")
#>             date              key  value   freq          title
#>           <Date>           <char>  <num> <char>         <char>
#>    1: 1999-01-04 D.USD.EUR.SP00.A 1.1789  daily US dollar/Euro
#>    2: 1999-01-05 D.USD.EUR.SP00.A 1.1790  daily US dollar/Euro
#>    3: 1999-01-06 D.USD.EUR.SP00.A 1.1743  daily US dollar/Euro
#>    4: 1999-01-07 D.USD.EUR.SP00.A 1.1632  daily US dollar/Euro
#>    5: 1999-01-08 D.USD.EUR.SP00.A 1.1659  daily US dollar/Euro
#>   ---                                                         
#> 6896: 2025-09-09 D.USD.EUR.SP00.A 1.1744  daily US dollar/Euro
#> 6897: 2025-09-10 D.USD.EUR.SP00.A 1.1707  daily US dollar/Euro
#> 6898: 2025-09-11 D.USD.EUR.SP00.A 1.1685  daily US dollar/Euro
#> 6899: 2025-09-12 D.USD.EUR.SP00.A 1.1718  daily US dollar/Euro
#> 6900: 2025-09-15 D.USD.EUR.SP00.A 1.1766  daily US dollar/Euro
#>                                                         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
#>   ---                                                                       
#> 6896: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 6897: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 6898: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 6899: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#> 6900: ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)      USD
#>       currency_denom exr_type exr_suffix unit_mult unit_index_base time_format
#>               <char>   <char>     <char>    <char>          <char>      <char>
#>    1:            EUR     SP00          A         0        99Q1=100         P1D
#>    2:            EUR     SP00          A         0        99Q1=100         P1D
#>    3:            EUR     SP00          A         0        99Q1=100         P1D
#>    4:            EUR     SP00          A         0        99Q1=100         P1D
#>    5:            EUR     SP00          A         0        99Q1=100         P1D
#>   ---                                                                         
#> 6896:            EUR     SP00          A         0        99Q1=100         P1D
#> 6897:            EUR     SP00          A         0        99Q1=100         P1D
#> 6898:            EUR     SP00          A         0        99Q1=100         P1D
#> 6899:            EUR     SP00          A         0        99Q1=100         P1D
#> 6900:            EUR     SP00          A         0        99Q1=100         P1D
#>       collection source_agency   unit decimals
#>           <char>        <char> <char>   <char>
#>    1:          A           4F0    USD        4
#>    2:          A           4F0    USD        4
#>    3:          A           4F0    USD        4
#>    4:          A           4F0    USD        4
#>    5:          A           4F0    USD        4
#>   ---                                         
#> 6896:          A           4F0    USD        4
#> 6897:          A           4F0    USD        4
#> 6898:          A           4F0    USD        4
#> 6899:          A           4F0    USD        4
#> 6900:          A           4F0    USD        4
# fetch data for multiple keys
ecb_data("EXR", c("D.USD", "JPY.EUR.SP00.A"))
#>              date              key    value   freq             title
#>            <Date>           <char>    <num> <char>            <char>
#>     1: 1999-01-04 D.JPY.EUR.SP00.A 133.7300  daily Japanese yen/Euro
#>     2: 1999-01-05 D.JPY.EUR.SP00.A 130.9600  daily Japanese yen/Euro
#>     3: 1999-01-06 D.JPY.EUR.SP00.A 131.4200  daily Japanese yen/Euro
#>     4: 1999-01-07 D.JPY.EUR.SP00.A 129.4300  daily Japanese yen/Euro
#>     5: 1999-01-08 D.JPY.EUR.SP00.A 130.0900  daily Japanese yen/Euro
#>    ---                                                              
#> 13796: 2025-09-09 D.USD.EUR.SP00.A   1.1744  daily    US dollar/Euro
#> 13797: 2025-09-10 D.USD.EUR.SP00.A   1.1707  daily    US dollar/Euro
#> 13798: 2025-09-11 D.USD.EUR.SP00.A   1.1685  daily    US dollar/Euro
#> 13799: 2025-09-12 D.USD.EUR.SP00.A   1.1718  daily    US dollar/Euro
#> 13800: 2025-09-15 D.USD.EUR.SP00.A   1.1766  daily    US dollar/Euro
#>                                                             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.)
#>    ---                                                                 
#> 13796:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 13797:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 13798:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 13799:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#> 13800:    ECB reference exchange rate, US dollar/Euro, 2.15 pm (C.E.T.)
#>        currency currency_denom exr_type exr_suffix time_format   unit
#>          <char>         <char>   <char>     <char>      <char> <char>
#>     1:      JPY            EUR     SP00          A         P1D    JPY
#>     2:      JPY            EUR     SP00          A         P1D    JPY
#>     3:      JPY            EUR     SP00          A         P1D    JPY
#>     4:      JPY            EUR     SP00          A         P1D    JPY
#>     5:      JPY            EUR     SP00          A         P1D    JPY
#>    ---                                                               
#> 13796:      USD            EUR     SP00          A         P1D    USD
#> 13797:      USD            EUR     SP00          A         P1D    USD
#> 13798:      USD            EUR     SP00          A         P1D    USD
#> 13799:      USD            EUR     SP00          A         P1D    USD
#> 13800:      USD            EUR     SP00          A         P1D    USD
#>        unit_index_base unit_mult collection decimals source_agency
#>                 <char>    <char>     <char>   <char>        <char>
#>     1:        99Q1=100         0          A        2           4F0
#>     2:        99Q1=100         0          A        2           4F0
#>     3:        99Q1=100         0          A        2           4F0
#>     4:        99Q1=100         0          A        2           4F0
#>     5:        99Q1=100         0          A        2           4F0
#>    ---                                                            
#> 13796:        99Q1=100         0          A        4           4F0
#> 13797:        99Q1=100         0          A        4           4F0
#> 13798:        99Q1=100         0          A        4           4F0
#> 13799:        99Q1=100         0          A        4           4F0
#> 13800:        99Q1=100         0          A        4           4F0
# }