ecb

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ecb is the library behind the ecb command line: the HTTP client, request shaping, and the typed data models for ECB exchange rates.

The Client talks to the ECB Statistical Data Warehouse (data-api.ecb.europa.eu), returns SDMX-JSON responses, and decodes them into clean RateRecord values. It paces requests, retries transient failures, and sets an honest User-Agent.

Index

Constants

View Source
const BaseURL = "https://data-api.ecb.europa.eu/service/data"
View Source
const Host = "data-api.ecb.europa.eu"

Variables

View Source
var KnownCurrencies = []string{
	"USD", "GBP", "JPY", "CHF", "AUD", "CAD", "CNY", "SEK", "NOK", "DKK",
	"PLN", "HUF", "CZK", "RON", "BGN", "HRK", "INR", "KRW", "SGD", "HKD",
	"MXN", "BRL", "ZAR", "TRY",
}

KnownCurrencies is the fixed set of major currency codes this CLI supports.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP *http.Client
	// exported for newClient in domain.go to set
	UserAgent string
	Rate      time.Duration
	Retries   int
	// contains filtered or unexported fields
}

Client talks to the ECB data API.

func NewClient

func NewClient() *Client

NewClient returns a Client with DefaultConfig settings.

func (*Client) GetLatest

func (c *Client) GetLatest(ctx context.Context) ([]RateRecord, error)

GetLatest returns the most recent rate for each major currency (monthly freq).

func (*Client) GetRates

func (c *Client) GetRates(ctx context.Context, currency, freq, start, end string, limit int) ([]RateRecord, error)

GetRates returns exchange rates for a currency pair. freq: "D" (daily), "M" (monthly), or "A" (annual). start/end: date strings; empty means no bound. limit > 0: append lastNObservations param.

func (*Client) GetRatesURL

func (c *Client) GetRatesURL(ctx context.Context, rawURL, currency string) ([]RateRecord, error)

GetRatesURL fetches and parses an SDMX-JSON response from an arbitrary URL. This is mainly used in tests to point at a local httptest server.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds all tunables for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain

type Domain struct{}

Domain is the ecb driver. It carries no state.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns an input string into a (type, id) pair.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme and identity for this domain.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id) pair.

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type RateRecord

type RateRecord struct {
	Date     string  `json:"date" kit:"id"`
	Currency string  `json:"currency"`
	Rate     float64 `json:"rate"`
}

RateRecord is one exchange rate observation.

Jump to

Keyboard shortcuts

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