fx

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package fx (piece ⑤) downloads the European Central Bank's daily reference rates: free, no API key, about 30 currencies (ADR 0008). Rates are stored with their date so past charges can be valued at their own day's rate.

Index

Constants

View Source
const (
	DailyURL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
	Hist90   = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml"
)

Sources: the latest day, and the last 90 days for backfill.

Variables

This section is empty.

Functions

func Save

func Save(ctx context.Context, st *store.Store, rates []Rate) error

Save stores rates.

Types

type Rate

type Rate struct {
	Day      string
	Currency string
	Rate     string
}

Rate is units of Currency per 1 EUR on Day.

func Parse

func Parse(r io.Reader) ([]Rate, error)

Parse reads an ECB eurofxref XML document.

type Updater

type Updater struct {
	St     *store.Store
	Log    *slog.Logger
	Client *http.Client
	Every  time.Duration
}

Updater keeps the rates table fresh. It is a supervised service.

func (*Updater) Refresh

func (u *Updater) Refresh(ctx context.Context) error

Refresh downloads the latest rates (and 90 days of history on first run).

func (*Updater) Serve

func (u *Updater) Serve(ctx context.Context) error

Serve refreshes now and then every u.Every (default 12 h). Failures are logged and retried; the app keeps working with the last known rates.

func (*Updater) String

func (u *Updater) String() string

Jump to

Keyboard shortcuts

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