fred

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 10 Imported by: 0

README

go-fred

Go
FRED

Go Reference Go Report Card Go CI

Go client for the FRED API. Stdlib only — zero dependencies.

Install

go get github.com/shanehull/go-fred

Quick Start

package main

import (
    "context"
    "fmt"
    "time"

    "github.com/shanehull/go-fred"
)

func main() {
    client, _ := fred.New() // uses $FRED_API_KEY

    obs, _ := client.GetSeriesObservations(context.Background(), "DGS20",
        fred.WithObservationStart(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
        fred.WithObservationSortOrder(fred.SortDesc),
    )
    for _, o := range obs {
        if !o.IsNA {
            fmt.Printf("%s  %.2f%%\n", o.Date.Format("2006-01-02"), o.Value)
        }
    }
}

API Key

Get a free key at fred.stlouisfed.org/docs/api/api_key.html.

// Environment variable (recommended)
client, _ := fred.New()

// Explicit option (overrides env)
client, _ := fred.New(fred.WithAPIKey("your-key"))

Usage

Observations
obs, err := client.GetSeriesObservations(ctx, "DGS20",
    fred.WithObservationStart(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
    fred.WithObservationSortOrder(fred.SortDesc),
    fred.WithUnits("lin"),
    fred.WithFrequency("m"),
)
Vintage Data
// All releases (every revision)
all, _ := client.GetSeriesAllReleases(ctx, "DGS20",
    fred.WithRealtimeStart(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)),
)

// First published value for each date
first, _ := client.GetSeriesFirstRelease(ctx, "DGS20")

// As known on a specific date
asof, _ := client.GetSeriesAsOf(ctx, "DGS20", time.Date(2023, 6, 1, 0, 0, 0, 0, time.UTC))
// Search auto-paginates. Set limit=0 for all results.
results, _ := client.SearchSeries(ctx, "real GDP",
    fred.WithLimit(50),
    fred.WithOrderBy(fred.OrderByPopularity),
)

// Filter by release or category
series, _ := client.GetReleaseSeries(ctx, 53, fred.WithLimit(100))
series, _ := client.GetCategorySeries(ctx, 1, fred.WithLimit(100))
Categories, Releases, Sources, Tags
cat, _  := client.GetCategory(ctx, 1)
children, _ := client.GetCategoryChildren(ctx, 0)
rel, _  := client.GetRelease(ctx, 53)
src, _  := client.GetSource(ctx, 1)
tags, _ := client.GetTags(ctx, fred.WithTagLimit(20))
GeoFRED
group, _ := client.GetSeriesGroup(ctx, "SMU56000000500000001A")
data, _  := client.GetSeriesData(ctx, "WIPCPI",
    fred.WithMapDate("2012-01-01"),
)
regional, _ := client.GetRegionalData(ctx,
    fred.WithSeriesGroup("882"),
    fred.WithRegionType("state"),
    fred.WithRegionalDate("2013-01-01"),
    fred.WithMapUnits("Dollars"),
    fred.WithSeason("NSA"),
    fred.WithRegionalFrequency("a"),
)
Error Handling
obs, err := client.GetSeriesObservations(ctx, "INVALID")
var apiErr fred.APIError
if errors.As(err, &apiErr) {
    fmt.Printf("FRED API error %d: %s\n", apiErr.Code, apiErr.Message)
}

API Coverage

Domain Methods
Series GetSeriesInfo, GetSeriesObservations, GetSeriesCategories, GetSeriesRelease, GetSeriesTags, GetSeriesUpdates, GetSeriesVintageDates, SearchSeries, SearchSeriesTags, SearchSeriesRelatedTags
Vintage GetSeriesAllReleases, GetSeriesFirstRelease, GetSeriesAsOf
Categories GetCategory, GetCategoryChildren, GetCategoryRelated, GetCategorySeries, GetCategoryTags, GetCategoryRelatedTags
Releases GetReleases, GetReleasesDates, GetRelease, GetReleaseDates, GetReleaseSeries, GetReleaseSources, GetReleaseTags, GetReleaseRelatedTags, GetReleaseTables
Sources GetSources, GetSource, GetSourceReleases
Tags GetTags, GetRelatedTags, GetTagsSeries
GeoFRED GetSeriesGroup, GetSeriesData, GetRegionalData

Examples

See examples/ for runnable programs:

  • observations — fetch and display series data
  • search — search for series
  • vintage — compare first vs latest release values

Documentation

Overview

Package fred provides a client for the Federal Reserve Economic Data (FRED) API.

It covers all 34 FRED API endpoints. Zero dependencies beyond Go stdlib.

Usage:

client, err := fred.New(fred.WithAPIKey("your-key"))
if err != nil {
    log.Fatal(err)
}
obs, err := client.GetSeriesObservations(ctx, "DGS20")

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError = internal.APIError

APIError represents a FRED API error response.

type Category

type Category struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	ParentID int    `json:"parent_id"`
	Notes    string `json:"notes,omitempty"`
}

Category represents a FRED category.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a FRED API client. Must be constructed via New. Safe for concurrent use by multiple goroutines.

API key resolution order:

  1. WithAPIKey("...")
  2. $FRED_API_KEY environment variable

func New

func New(opts ...ClientOption) (*Client, error)

New creates a new FRED API client.

func (*Client) GetCategory

func (c *Client) GetCategory(ctx context.Context, id int) (*Category, error)

GetCategory returns information about a FRED category. Endpoint: GET /fred/category?category_id={id}

func (*Client) GetCategoryChildren

func (c *Client) GetCategoryChildren(ctx context.Context, id int) ([]Category, error)

GetCategoryChildren returns the child categories for a given FRED category. Endpoint: GET /fred/category/children?category_id={id}

func (*Client) GetCategoryRelated

func (c *Client) GetCategoryRelated(ctx context.Context, id int) ([]Category, error)

GetCategoryRelated returns related categories for a given FRED category. Endpoint: GET /fred/category/related?category_id={id}

func (*Client) GetCategoryRelatedTags

func (c *Client) GetCategoryRelatedTags(ctx context.Context, id int, tagNames []string, opts ...TagOption) ([]Tag, error)

GetCategoryRelatedTags returns related tags for a FRED category. Endpoint: GET /fred/category/related_tags?category_id={id}&tag_names={tags}

func (*Client) GetCategorySeries

func (c *Client) GetCategorySeries(ctx context.Context, categoryID int, opts ...SearchOption) ([]SearchResult, error)

GetCategorySeries returns series belonging to a category. Auto-paginates. Limit 0 = unlimited. Default limit = 0. Endpoint: GET /fred/category/series?category_id={id}

func (*Client) GetCategoryTags

func (c *Client) GetCategoryTags(ctx context.Context, id int, opts ...TagOption) ([]Tag, error)

GetCategoryTags returns the tags for a FRED category. Endpoint: GET /fred/category/tags?category_id={id}

func (*Client) GetRegionalData

func (c *Client) GetRegionalData(ctx context.Context, opts ...RegionalDataOption) (*MapData, error)

GetRegionalData returns GeoFRED regional data for a series group and region type. Endpoint: GET /geofred/regional/data

func (*Client) GetRelatedTags

func (c *Client) GetRelatedTags(ctx context.Context, tagNames []string, opts ...TagOption) ([]Tag, error)

GetRelatedTags returns related tags for given tag names. Endpoint: GET /fred/related_tags?tag_names={tags}

func (*Client) GetRelease

func (c *Client) GetRelease(ctx context.Context, id int) (*Release, error)

GetRelease returns information about a FRED release. Endpoint: GET /fred/release?release_id={id}

func (*Client) GetReleaseDates

func (c *Client) GetReleaseDates(ctx context.Context, id int, opts ...ReleaseDateOption) ([]ReleaseDate, error)

GetReleaseDates returns release dates for a specific FRED release. Endpoint: GET /fred/release/dates?release_id={id}

func (*Client) GetReleaseRelatedTags

func (c *Client) GetReleaseRelatedTags(ctx context.Context, id int, tagNames []string, opts ...TagOption) ([]Tag, error)

GetReleaseRelatedTags returns related tags for a FRED release. Endpoint: GET /fred/release/related_tags?release_id={id}&tag_names={tags}

func (*Client) GetReleaseSeries

func (c *Client) GetReleaseSeries(ctx context.Context, releaseID int, opts ...SearchOption) ([]SearchResult, error)

GetReleaseSeries returns series belonging to a release. Auto-paginates. Limit 0 = unlimited. Default limit = 0. Endpoint: GET /fred/release/series?release_id={id}

func (*Client) GetReleaseSources

func (c *Client) GetReleaseSources(ctx context.Context, id int) ([]Source, error)

GetReleaseSources returns the sources for a FRED release. Endpoint: GET /fred/release/sources?release_id={id}

func (*Client) GetReleaseTables

func (c *Client) GetReleaseTables(ctx context.Context, id int, opts ...TableOption) ([]ReleaseTableElement, error)

GetReleaseTables returns the release table for a FRED release. Endpoint: GET /fred/release/tables?release_id={id}

func (*Client) GetReleaseTags

func (c *Client) GetReleaseTags(ctx context.Context, id int, opts ...TagOption) ([]Tag, error)

GetReleaseTags returns the tags for a FRED release. Endpoint: GET /fred/release/tags?release_id={id}

func (*Client) GetReleases

func (c *Client) GetReleases(ctx context.Context, opts ...ReleaseListOption) ([]Release, error)

GetReleases returns all FRED releases. Endpoint: GET /fred/releases

func (*Client) GetReleasesDates

func (c *Client) GetReleasesDates(ctx context.Context, opts ...ReleaseDateOption) ([]ReleaseDate, error)

GetReleasesDates returns release dates for all FRED releases. Endpoint: GET /fred/releases/dates

func (*Client) GetSeriesAllReleases

func (c *Client) GetSeriesAllReleases(ctx context.Context, seriesID string, opts ...ObservationOption) ([]Observation, error)

GetSeriesAllReleases returns all observations including every revision. Defaults realtime_start="1776-07-04", realtime_end="9999-12-31" unless overridden by ObservationOption. Uses the same endpoint as GetSeriesObservations.

func (*Client) GetSeriesAsOf

func (c *Client) GetSeriesAsOf(ctx context.Context, seriesID string, asOf time.Time, opts ...ObservationOption) ([]Observation, error)

GetSeriesAsOf returns data as known on a specific date. Calls GetSeriesObservations with realtime_end=asOf.

func (*Client) GetSeriesCategories

func (c *Client) GetSeriesCategories(ctx context.Context, seriesID string) ([]Category, error)

GetSeriesCategories returns categories for a FRED series. Endpoint: GET /fred/series/categories?series_id={id}

func (*Client) GetSeriesData

func (c *Client) GetSeriesData(ctx context.Context, seriesID string, opts ...MapDataOption) (*MapData, error)

GetSeriesData returns GeoFRED series data for regional maps. Endpoint: GET /geofred/series/data?series_id={id}

func (*Client) GetSeriesFirstRelease

func (c *Client) GetSeriesFirstRelease(ctx context.Context, seriesID string, opts ...ObservationOption) ([]Observation, error)

GetSeriesFirstRelease returns the first published value for each date. Calls GetSeriesAllReleases and groups by Date, picking the earliest RealtimeStart for each Date.

func (*Client) GetSeriesGroup

func (c *Client) GetSeriesGroup(ctx context.Context, seriesID string) (*SeriesGroup, error)

GetSeriesGroup returns the GeoFRED series group metadata for a series. Endpoint: GET /geofred/series/group?series_id={id}

func (*Client) GetSeriesInfo

func (c *Client) GetSeriesInfo(ctx context.Context, seriesID string) (*Series, error)

GetSeriesInfo returns metadata for a FRED series. Endpoint: GET /fred/series?series_id={id}

func (*Client) GetSeriesObservations

func (c *Client) GetSeriesObservations(ctx context.Context, seriesID string, opts ...ObservationOption) ([]Observation, error)

GetSeriesObservations returns data values for a series. Endpoint: GET /fred/series/observations?series_id={id} Does not auto-paginate — FRED returns up to 100,000 observations per request.

Example
client, _ := fred.New(fred.WithAPIKey("your-key"))
obs, _ := client.GetSeriesObservations(context.Background(), "DGS20",
	fred.WithObservationStart(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
)
for _, o := range obs {
	if !o.IsNA {
		fmt.Printf("%s: %.2f\n", o.Date.Format("2006-01-02"), o.Value)
	}
}

func (*Client) GetSeriesRelease

func (c *Client) GetSeriesRelease(ctx context.Context, seriesID string) (*Release, error)

GetSeriesRelease returns the release for a FRED series. Endpoint: GET /fred/series/release?series_id={id}

func (*Client) GetSeriesTags

func (c *Client) GetSeriesTags(ctx context.Context, seriesID string, opts ...TagOption) ([]Tag, error)

GetSeriesTags returns the tags for a FRED series. Endpoint: GET /fred/series/tags?series_id={id}

func (*Client) GetSeriesUpdates

func (c *Client) GetSeriesUpdates(ctx context.Context, opts ...UpdateOption) ([]SearchResult, error)

GetSeriesUpdates returns series that were recently updated. Endpoint: GET /fred/series/updates

func (*Client) GetSeriesVintageDates

func (c *Client) GetSeriesVintageDates(ctx context.Context, seriesID string, opts ...ObservationOption) ([]time.Time, error)

GetSeriesVintageDates returns all vintage dates for a series. Endpoint: GET /fred/series/vintagedates?series_id={id}

func (*Client) GetSource

func (c *Client) GetSource(ctx context.Context, id int) (*Source, error)

GetSource returns information about a FRED data source. Endpoint: GET /fred/source?source_id={id}

func (*Client) GetSourceReleases

func (c *Client) GetSourceReleases(ctx context.Context, id int, opts ...ReleaseListOption) ([]Release, error)

GetSourceReleases returns the releases for a FRED data source. Endpoint: GET /fred/source/releases?source_id={id}

func (*Client) GetSources

func (c *Client) GetSources(ctx context.Context, opts ...SourceOption) ([]Source, error)

GetSources returns all FRED data sources. Endpoint: GET /fred/sources

func (*Client) GetTags

func (c *Client) GetTags(ctx context.Context, opts ...TagOption) ([]Tag, error)

GetTags returns all FRED tags. Endpoint: GET /fred/tags

func (*Client) GetTagsSeries

func (c *Client) GetTagsSeries(ctx context.Context, tagNames []string, opts ...SearchOption) ([]SearchResult, error)

GetTagsSeries returns series matching given tag names. Endpoint: GET /fred/tags/series?tag_names={tags}

func (*Client) SearchSeries

func (c *Client) SearchSeries(ctx context.Context, text string, opts ...SearchOption) ([]SearchResult, error)

SearchSeries searches for series by keywords. Auto-paginates. Limit 0 = unlimited. Default limit = 1000. Endpoint: GET /fred/series/search?search_text={text}

Example
client, _ := fred.New(fred.WithAPIKey("your-key"))
results, _ := client.SearchSeries(context.Background(), "GDP",
	fred.WithLimit(5),
	fred.WithSortOrder(fred.SortDesc),
)
for _, r := range results {
	fmt.Printf("%s: %s\n", r.ID, r.Title)
}

func (*Client) SearchSeriesRelatedTags

func (c *Client) SearchSeriesRelatedTags(ctx context.Context, text string, tagNames []string, opts ...TagOption) ([]Tag, error)

SearchSeriesRelatedTags searches for related tags by series search text and tag names. Endpoint: GET /fred/series/search/related_tags?series_search_text={text}&tag_names={tags}

func (*Client) SearchSeriesTags

func (c *Client) SearchSeriesTags(ctx context.Context, text string, opts ...TagOption) ([]Tag, error)

SearchSeriesTags searches for tags by series search text. Endpoint: GET /fred/series/search/tags?series_search_text={text}

type ClientOption

type ClientOption func(*Client) error

ClientOption configures a Client.

func WithAPIKey

func WithAPIKey(key string) ClientOption

WithAPIKey sets the FRED API key.

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets a custom base URL (useful for testing).

func WithHTTPClient

func WithHTTPClient(hc *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client (useful for testing with httptest).

type MapData

type MapData struct {
	Title       string `json:"title"`
	Region      string `json:"region"`
	Seasonality string `json:"seasonality"`
	Units       string `json:"units"`
	Frequency   string `json:"frequency"`
	Date        string `json:"date"`
	Data        []MapDataEntry
}

MapData wraps GeoFRED series/regional data responses.

type MapDataEntry

type MapDataEntry struct {
	Region   string `json:"region"`
	Code     string `json:"code"`
	Value    string `json:"value"`
	SeriesID string `json:"series_id"`
}

MapDataEntry represents a single region's data point in GeoFRED.

func (*MapDataEntry) UnmarshalJSON

func (m *MapDataEntry) UnmarshalJSON(data []byte) error

UnmarshalJSON handles both numeric and string value representations from FRED.

type MapDataOption

type MapDataOption func(*mapDataParams)

MapDataOption configures GeoFRED series data calls.

func WithMapDate

func WithMapDate(d string) MapDataOption

WithMapDate sets the date for map data (FRED: date).

func WithMapStartDate

func WithMapStartDate(d string) MapDataOption

WithMapStartDate sets the start date for map data range (FRED: start_date).

type Observation

type Observation struct {
	Date          time.Time
	Value         float64
	RealtimeStart time.Time
	RealtimeEnd   time.Time
	IsNA          bool
}

Observation represents a single FRED data observation.

type ObservationOption

type ObservationOption func(*obsParams)

ObservationOption configures a call to GetSeriesObservations or related vintage methods.

func WithAggregationMethod

func WithAggregationMethod(m string) ObservationOption

WithAggregationMethod sets the frequency aggregation method (FRED: aggregation_method). Values: avg, sum, eop.

func WithFrequency

func WithFrequency(f string) ObservationOption

WithFrequency sets the data frequency aggregation (FRED: frequency). Values: d, w, bw, m, q, sa, a, wef, weth, wew, wetu, wem, wesu, wesa, bwew, bwem.

func WithObservationEnd

func WithObservationEnd(t time.Time) ObservationOption

WithObservationEnd sets the end of the observation period (FRED: observation_end).

func WithObservationLimit

func WithObservationLimit(n int) ObservationOption

WithObservationLimit sets the maximum number of observations to return (FRED: limit).

func WithObservationOffset

func WithObservationOffset(n int) ObservationOption

WithObservationOffset sets the offset for paginated observation requests (FRED: offset).

func WithObservationSortOrder

func WithObservationSortOrder(o SortOrder) ObservationOption

WithObservationSortOrder sets the sort order for observations (FRED: sort_order).

func WithObservationStart

func WithObservationStart(t time.Time) ObservationOption

WithObservationStart sets the start of the observation period (FRED: observation_start).

func WithOutputType

func WithOutputType(t int) ObservationOption

WithOutputType sets the output type (FRED: output_type). Values: 1-4.

func WithRealtimeEnd

func WithRealtimeEnd(t time.Time) ObservationOption

WithRealtimeEnd sets the end of the real-time period (FRED: realtime_end).

func WithRealtimeStart

func WithRealtimeStart(t time.Time) ObservationOption

WithRealtimeStart sets the start of the real-time period (FRED: realtime_start).

func WithUnits

func WithUnits(u string) ObservationOption

WithUnits sets the data value transformation (FRED: units). Values: lin, chg, ch1, pch, pc1, pca, cch, cca, log.

func WithVintageDates

func WithVintageDates(dates ...string) ObservationOption

WithVintageDates sets vintage dates to request (FRED: vintage_dates).

type OrderBy

type OrderBy string

OrderBy specifies the field to sort search results by.

const (
	OrderBySearchRank         OrderBy = "search_rank"
	OrderBySeriesID           OrderBy = "series_id"
	OrderByTitle              OrderBy = "title"
	OrderByUnits              OrderBy = "units"
	OrderByFrequency          OrderBy = "frequency"
	OrderBySeasonalAdjustment OrderBy = "seasonal_adjustment"
	OrderByRealtimeStart      OrderBy = "realtime_start"
	OrderByRealtimeEnd        OrderBy = "realtime_end"
	OrderByLastUpdated        OrderBy = "last_updated"
	OrderByObservationStart   OrderBy = "observation_start"
	OrderByObservationEnd     OrderBy = "observation_end"
	OrderByPopularity         OrderBy = "popularity"
)

type RegionalDataOption

type RegionalDataOption func(*regionalDataParams)

RegionalDataOption configures GeoFRED regional data calls.

func WithMapUnits

func WithMapUnits(u string) RegionalDataOption

WithMapUnits sets the units for map data (FRED: units).

func WithRegionType

func WithRegionType(t string) RegionalDataOption

WithRegionType sets the region type (FRED: region_type). Values: bea, msa, frb, necta, state, country, county, censusregion.

func WithRegionalDate

func WithRegionalDate(d string) RegionalDataOption

WithRegionalDate sets the date for regional data (FRED: date).

func WithRegionalFrequency

func WithRegionalFrequency(f string) RegionalDataOption

WithRegionalFrequency sets the frequency aggregation (FRED: frequency).

func WithSeason

func WithSeason(s string) RegionalDataOption

WithSeason sets the seasonality adjustment (FRED: season). Values: SA, NSA, SSA, SAAR, NSAAR.

func WithSeriesGroup

func WithSeriesGroup(g string) RegionalDataOption

WithSeriesGroup sets the series group ID (FRED: series_group). Required.

func WithTransformation

func WithTransformation(t string) RegionalDataOption

WithTransformation sets the data transformation (FRED: transformation). Values: lin, chg, ch1, pch, pc1, pca, cch, cca, log.

type Release

type Release struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	PressRelease bool   `json:"press_release"`
	Link         string `json:"link,omitempty"`
	Notes        string `json:"notes,omitempty"`
}

Release represents a FRED release.

type ReleaseDate

type ReleaseDate struct {
	ReleaseID   int    `json:"release_id"`
	ReleaseName string `json:"release_name,omitempty"`
	Date        string `json:"date"`
}

ReleaseDate represents a release date entry.

type ReleaseDateOption

type ReleaseDateOption func(*releaseDateParams)

ReleaseDateOption configures release date calls.

func WithIncludeNoData

func WithIncludeNoData(b bool) ReleaseDateOption

WithIncludeNoData includes releases with no data (FRED: include_release_dates_with_no_data).

func WithReleaseDateLimit

func WithReleaseDateLimit(n int) ReleaseDateOption

WithReleaseDateLimit sets the maximum number of release dates (FRED: limit).

func WithReleaseDateSortOrder

func WithReleaseDateSortOrder(o SortOrder) ReleaseDateOption

WithReleaseDateSortOrder sets the sort order for release dates (FRED: sort_order).

type ReleaseListOption

type ReleaseListOption func(*releaseListParams)

ReleaseListOption configures release listing calls.

func WithReleaseLimit

func WithReleaseLimit(n int) ReleaseListOption

WithReleaseLimit sets the maximum number of releases to return (FRED: limit).

func WithReleaseSortOrder

func WithReleaseSortOrder(o SortOrder) ReleaseListOption

WithReleaseSortOrder sets the sort order for release results (FRED: sort_order).

type ReleaseTableElement

type ReleaseTableElement struct {
	ElementID int                   `json:"element_id"`
	ReleaseID int                   `json:"release_id"`
	SeriesID  string                `json:"series_id,omitempty"`
	ParentID  int                   `json:"parent_id"`
	Line      string                `json:"line"`
	Type      string                `json:"type"`
	Name      string                `json:"name"`
	Level     int                   `json:"-"` // computed from string
	LevelRaw  string                `json:"level"`
	Children  []ReleaseTableElement `json:"children,omitempty"`
}

ReleaseTableElement represents an element in a release table.

type SearchOption

type SearchOption func(*searchParams)

SearchOption configures a search or series-list call.

func WithExcludeTags

func WithExcludeTags(tags ...string) SearchOption

WithExcludeTags excludes series matching the given tags (FRED: exclude_tag_names).

func WithFilter

func WithFilter(variable, value string) SearchOption

WithFilter filters results by variable and value (FRED: filter_variable, filter_value).

func WithLimit

func WithLimit(n int) SearchOption

WithLimit sets the maximum number of results to return. 0 means unlimited.

func WithOrderBy

func WithOrderBy(ob OrderBy) SearchOption

WithOrderBy sets the field to sort search results by.

func WithSearchType

func WithSearchType(t string) SearchOption

WithSearchType sets the search type (FRED: search_type). Values: full_text, series_id.

func WithSortOrder

func WithSortOrder(o SortOrder) SearchOption

WithSortOrder sets the result sort order for search/series results.

func WithTagNames

func WithTagNames(tags ...string) SearchOption

WithTagNames filters results to series matching the given tags (FRED: tag_names).

type SearchResult

type SearchResult struct {
	ID                      string `json:"id"`
	RealtimeStart           string `json:"realtime_start"`
	RealtimeEnd             string `json:"realtime_end"`
	Title                   string `json:"title"`
	ObservationStart        string `json:"observation_start"`
	ObservationEnd          string `json:"observation_end"`
	Frequency               string `json:"frequency"`
	FrequencyShort          string `json:"frequency_short"`
	Units                   string `json:"units"`
	UnitsShort              string `json:"units_short"`
	SeasonalAdjustment      string `json:"seasonal_adjustment"`
	SeasonalAdjustmentShort string `json:"seasonal_adjustment_short"`
	LastUpdated             string `json:"last_updated"`
	Popularity              int    `json:"popularity"`
	Notes                   string `json:"notes,omitempty"`
}

SearchResult represents a series search result.

type Series

type Series struct {
	ID                      string `json:"id"`
	RealtimeStart           string `json:"realtime_start"`
	RealtimeEnd             string `json:"realtime_end"`
	Title                   string `json:"title"`
	ObservationStart        string `json:"observation_start"`
	ObservationEnd          string `json:"observation_end"`
	Frequency               string `json:"frequency"`
	FrequencyShort          string `json:"frequency_short"`
	Units                   string `json:"units"`
	UnitsShort              string `json:"units_short"`
	SeasonalAdjustment      string `json:"seasonal_adjustment"`
	SeasonalAdjustmentShort string `json:"seasonal_adjustment_short"`
	LastUpdated             string `json:"last_updated"`
	Popularity              int    `json:"popularity"`
	Notes                   string `json:"notes,omitempty"`
	Tags                    []Tag  `json:"tags,omitempty"`
}

Series represents metadata for a FRED series.

type SeriesGroup

type SeriesGroup struct {
	Title       string `json:"title"`
	RegionType  string `json:"region_type"`
	SeriesGroup string `json:"series_group"`
	Season      string `json:"season"`
	Units       string `json:"units"`
	Frequency   string `json:"frequency"`
	MinDate     string `json:"min_date"`
	MaxDate     string `json:"max_date"`
}

SeriesGroup represents metadata for a GeoFRED map series.

type SortOrder

type SortOrder string

SortOrder specifies ascending or descending sort.

const (
	SortAsc  SortOrder = "asc"
	SortDesc SortOrder = "desc"
)

type Source

type Source struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Link  string `json:"link,omitempty"`
	Notes string `json:"notes,omitempty"`
}

Source represents a FRED data source.

type SourceOption

type SourceOption func(*sourceParams)

SourceOption configures source calls.

func WithSourceLimit

func WithSourceLimit(n int) SourceOption

WithSourceLimit sets the maximum number of sources (FRED: limit).

func WithSourceSortOrder

func WithSourceSortOrder(o SortOrder) SourceOption

WithSourceSortOrder sets the sort order for source results (FRED: sort_order).

type TableOption

type TableOption func(*tableParams)

TableOption configures release table calls.

func WithIncludeObservationValues

func WithIncludeObservationValues(b bool) TableOption

WithIncludeObservationValues includes observation values in table rows (FRED: include_observation_values).

func WithObservationDate

func WithObservationDate(d string) TableOption

WithObservationDate sets the observation date for table values (FRED: observation_date).

func WithTableElementID

func WithTableElementID(id int) TableOption

WithTableElementID filters tables by element ID (FRED: element_id).

type Tag

type Tag struct {
	Name        string `json:"name"`
	GroupID     string `json:"group_id"`
	Notes       string `json:"notes,omitempty"`
	Created     string `json:"created"`
	Popularity  int    `json:"popularity"`
	SeriesCount int    `json:"series_count"`
}

Tag represents a FRED tag.

type TagOption

type TagOption func(*tagParams)

TagOption configures a tag-related call.

func WithTagGroupID

func WithTagGroupID(g string) TagOption

WithTagGroupID filters tags by group ID (FRED: tag_group_id).

func WithTagLimit

func WithTagLimit(n int) TagOption

WithTagLimit sets the maximum number of tags to return (FRED: limit).

func WithTagOrderBy

func WithTagOrderBy(ob OrderBy) TagOption

WithTagOrderBy sets the field to sort tags by (FRED: order_by).

func WithTagSearchText

func WithTagSearchText(text string) TagOption

WithTagSearchText filters tags by search text (FRED: search_text).

func WithTagSetExclude

func WithTagSetExclude(tags ...string) TagOption

WithTagSetExclude excludes results by tag names (FRED: exclude_tag_names).

func WithTagSetNames

func WithTagSetNames(tags ...string) TagOption

WithTagSetNames filters results by tag names (FRED: tag_names).

func WithTagSortOrder

func WithTagSortOrder(o SortOrder) TagOption

WithTagSortOrder sets the sort order for tag results (FRED: sort_order).

type UpdateOption

type UpdateOption func(*updateParams)

UpdateOption configures series updates calls.

func WithEndTime

func WithEndTime(s string) UpdateOption

WithEndTime filters updates by end time (FRED: end_time).

func WithFilterValue

func WithFilterValue(v string) UpdateOption

WithFilterValue filters updates by category (FRED: filter_value). Values: macro, regional, all.

func WithStartTime

func WithStartTime(s string) UpdateOption

WithStartTime filters updates by start time (FRED: start_time).

func WithUpdateLimit

func WithUpdateLimit(n int) UpdateOption

WithUpdateLimit sets the maximum number of updated series (FRED: limit).

Directories

Path Synopsis
examples
search command
Example: search FRED for GDP-related series.
Example: search FRED for GDP-related series.
series command
Example: fetch and display recent 20-year Treasury yield observations.
Example: fetch and display recent 20-year Treasury yield observations.
vintage command
Example: get the first-published values for a series at each date.
Example: get the first-published values for a series at each date.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL