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 ¶
const BaseURL = "https://data-api.ecb.europa.eu/service/data"
const Host = "data-api.ecb.europa.eu"
Variables ¶
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 (*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 ¶
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.
type Domain ¶
type Domain struct{}
Domain is the ecb driver. It carries no state.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme and identity for this domain.
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.