Fred Client
FRED (Federal Reserve Economic Data) API client.
A client for querying economic data from the Federal Reserve Economic Data (FRED) system. FRED is a database of hundreds of thousands of economic time series maintained by the Federal Reserve Bank of St. Louis.
Note: A FRED API key is required to use this client. You can obtain a free API key at https://fred.stlouisfed.org/docs/api/api_key.html
Usage example:
val fred = FredClient.create(apiKey = "your-api-key")
// Fetch GDP data
val gdp = fred.series("GDP")
// Fetch unemployment rate data with date range
val unrate = fred.series(
"UNRATE",
startDate = LocalDate.of(2020, 1, 1),
endDate = LocalDate.of(2023, 12, 31)
)
// Fetch only series metadata
val info = fred.seriesInfo("GDP")
println("Title: ${info.title}, Frequency: ${info.frequency}")
fred.close()Content copied to clipboard
Alternatively, use a use block for automatic resource cleanup:
FredClient.create("your-api-key").use { fred ->
val gdp = fred.series("GDP")
println(gdp.observations.size)
}Content copied to clipboard
Functions
Link copied to clipboard
suspend fun series(seriesId: String, startDate: LocalDate? = null, endDate: LocalDate? = null, frequency: DataFrequency? = null): FredSeries
Fetches FRED time series data.
Link copied to clipboard
Fetches FRED series metadata only.