Documentation
¶
Overview ¶
Package allratestoday is the official Go client for the AllRatesToday exchange rate API (https://allratestoday.com). It provides real-time mid-market exchange rates for 160+ currencies, conversion, up to a year of daily history (paid plans), and the official rates published by 121 central banks and 3 tax authorities.
Create a free API key at https://allratestoday.com/register (300 free requests, lifetime). Keys look like "art_live_...", and the client sends yours as a Bearer token in the Authorization header. Symbols, OfficialRates and OfficialSources work without a key. Historical and dated rates (ConvertOnDate, Historical, TimeSeries, GetHistoricalRates) need a paid plan; free and trial keys get HTTP 403 with code "historical_requires_paid_plan". The keyed API sends no CORS headers, so call it from server-side code only.
client := allratestoday.NewClient("art_live_your_api_key")
rates, err := client.Latest(context.Background(), "USD", []string{"EUR", "GBP"})
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Convert(ctx context.Context, from, to string, amount float64) (*ConvertResponse, error)
- func (c *Client) ConvertOnDate(ctx context.Context, from, to string, amount float64, date string) (*ConvertResponse, error)
- func (c *Client) GetHistoricalRates(ctx context.Context, source, target, period string) (*HistoricalRatesResponse, error)
- func (c *Client) GetRate(ctx context.Context, from, to string) (*RateResponse, error)
- func (c *Client) GetRates(ctx context.Context, source string, targets ...string) ([]Rate, error)
- func (c *Client) Historical(ctx context.Context, date, base string, symbols []string) (*HistoricalResponse, error)
- func (c *Client) Latest(ctx context.Context, base string, symbols []string) (*LatestResponse, error)
- func (c *Client) OfficialRates(ctx context.Context, bank, source, target string) (*OfficialRatesResponse, error)
- func (c *Client) OfficialSources(ctx context.Context) (*OfficialSourcesResponse, error)
- func (c *Client) Symbols(ctx context.Context) (*SymbolsResponse, error)
- func (c *Client) TimeSeries(ctx context.Context, startDate, endDate, base string, symbols []string) (*TimeSeriesResponse, error)
- type ConvertResponse
- type CurrencySymbol
- type Error
- type HistoricalRatePoint
- type HistoricalRatesResponse
- type HistoricalResponse
- type LatestResponse
- type OfficialRateAttribution
- type OfficialRateEntry
- type OfficialRatesResponse
- type OfficialSource
- type OfficialSourcesResponse
- type Option
- type Rate
- type RateResponse
- type SymbolsResponse
- type TimeSeriesResponse
Constants ¶
const DefaultBaseURL = "https://allratestoday.com"
DefaultBaseURL is the production API host.
Variables ¶
var ErrMissingAPIKey = errors.New("allratestoday: API key is required; register for free at https://allratestoday.com/register")
ErrMissingAPIKey is returned by methods that need an API key when the client was created with an empty one.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the AllRatesToday API client. Create one with NewClient. A Client is safe for concurrent use by multiple goroutines.
func NewClient ¶
NewClient returns a Client that authenticates with the given API key. Get a free key at https://allratestoday.com/register. Pass "" to use only the keyless methods (Symbols, OfficialRates, OfficialSources).
func (*Client) Convert ¶
func (c *Client) Convert(ctx context.Context, from, to string, amount float64) (*ConvertResponse, error)
Convert converts an amount from one currency to another at the current rate.
func (*Client) ConvertOnDate ¶ added in v1.1.0
func (c *Client) ConvertOnDate(ctx context.Context, from, to string, amount float64, date string) (*ConvertResponse, error)
ConvertOnDate converts an amount at the rate on a past date (YYYY-MM-DD, within the last 365 days). It uses the closest earlier point when the date has none (the 1-year window is weekly). Requires a paid plan: free and trial keys get a 403 *Error (code "historical_requires_paid_plan").
func (*Client) GetHistoricalRates ¶
func (c *Client) GetHistoricalRates(ctx context.Context, source, target, period string) (*HistoricalRatesResponse, error)
GetHistoricalRates returns a currency pair's history over a preset period: "1d", "7d", "30d" or "1y" (daily points; weekly for "1y"). Points are sorted oldest first. Requires a paid plan: free and trial keys get a 403 *Error (code "historical_requires_paid_plan").
func (*Client) GetRates ¶ added in v1.1.0
GetRates returns the raw rate list from GET /api/v1/rates, one entry per target, each with its observation time. Pass no targets for every available currency.
func (*Client) Historical ¶
func (c *Client) Historical(ctx context.Context, date, base string, symbols []string) (*HistoricalResponse, error)
Historical returns rates as of a past date (YYYY-MM-DD, within the last 365 days) for the given symbols. symbols is required: the history endpoint takes one target per call, so each symbol costs one request. Requires a paid plan: free and trial keys get a 403 *Error (code "historical_requires_paid_plan").
func (*Client) Latest ¶
func (c *Client) Latest(ctx context.Context, base string, symbols []string) (*LatestResponse, error)
Latest returns the most recent mid-market rates for a base currency. Pass a nil or empty symbols slice to receive every available currency.
func (*Client) OfficialRates ¶ added in v1.1.0
func (c *Client) OfficialRates(ctx context.Context, bank, source, target string) (*OfficialRatesResponse, error)
OfficialRates returns the latest table of official rates published by a central bank or tax authority (e.g. "ecb", "fed", "hmrc"). Pass source and target (e.g. "EUR", "USD") for one pair, or both empty for the full table. No API key needed.
func (*Client) OfficialSources ¶ added in v1.1.0
func (c *Client) OfficialSources(ctx context.Context) (*OfficialSourcesResponse, error)
OfficialSources lists every covered official source with its code, name, latest publication date and whether it is behind schedule. No API key needed.
func (*Client) Symbols ¶
func (c *Client) Symbols(ctx context.Context) (*SymbolsResponse, error)
Symbols lists every supported currency. No API key needed.
func (*Client) TimeSeries ¶
func (c *Client) TimeSeries(ctx context.Context, startDate, endDate, base string, symbols []string) (*TimeSeriesResponse, error)
TimeSeries returns daily rates between two dates (YYYY-MM-DD, start within the last 365 days), keyed by date then currency. symbols is required; each symbol costs one request. Requires a paid plan: free and trial keys get a 403 *Error (code "historical_requires_paid_plan").
type ConvertResponse ¶
type ConvertResponse struct {
// Deprecated: always true. Failures are returned as an error.
Success bool `json:"success"`
From string `json:"from"`
To string `json:"to"`
Amount float64 `json:"amount"`
Result float64 `json:"result"`
Rate float64 `json:"rate"`
// Date is set (YYYY-MM-DD) only for ConvertOnDate.
Date string `json:"date,omitempty"`
}
ConvertResponse is returned by Convert and ConvertOnDate.
type CurrencySymbol ¶
type CurrencySymbol struct {
Code string `json:"code"`
Name string `json:"name"`
Symbol string `json:"symbol"`
}
CurrencySymbol describes one supported currency.
type Error ¶
type Error struct {
// StatusCode is the HTTP status code returned by the API.
StatusCode int
// Message is the response body (usually a JSON error payload such as
// {"error":"..."}).
Message string
}
Error is returned when the API responds with a non-2xx status code.
type HistoricalRatePoint ¶
type HistoricalRatePoint struct {
// Date is YYYY-MM-DD.
Date string `json:"date"`
Rate float64 `json:"rate"`
// Timestamp is milliseconds since the Unix epoch.
Timestamp int64 `json:"timestamp"`
}
HistoricalRatePoint is a single observation in a HistoricalRatesResponse.
type HistoricalRatesResponse ¶
type HistoricalRatesResponse struct {
// Deprecated: always true. Failures are returned as an error.
Success bool `json:"success"`
Source string `json:"source"`
Target string `json:"target"`
Period string `json:"period"`
// Rates is sorted oldest first.
Rates []HistoricalRatePoint `json:"data"`
}
HistoricalRatesResponse is returned by GetHistoricalRates.
type HistoricalResponse ¶
type HistoricalResponse struct {
// Deprecated: always true. Failures are returned as an error.
Success bool `json:"success"`
Base string `json:"base"`
Date string `json:"date"`
Rates map[string]float64 `json:"rates"`
}
HistoricalResponse is returned by Historical.
type LatestResponse ¶
type LatestResponse struct {
// Deprecated: always true. Failures are returned as an error.
Success bool `json:"success"`
Base string `json:"base"`
// Date is the observation time of the rates, e.g.
// "2026-10-16T11:31:01+0000".
Date string `json:"date"`
Rates map[string]float64 `json:"rates"`
}
LatestResponse is returned by Latest.
type OfficialRateAttribution ¶ added in v1.1.0
type OfficialRateAttribution struct {
Source string `json:"source"`
URL string `json:"url"`
Terms string `json:"terms"`
}
OfficialRateAttribution is the attribution block on official responses.
type OfficialRateEntry ¶ added in v1.1.0
type OfficialRateEntry struct {
Base string `json:"base"`
Quote string `json:"quote"`
// Type is the rate type as the institution labels it, e.g.
// "reference", "buy", "sell", "mid".
Type string `json:"type"`
Value float64 `json:"value"`
}
OfficialRateEntry is one row of an official published table.
type OfficialRatesResponse ¶ added in v1.1.0
type OfficialRatesResponse struct {
Bank string `json:"bank"`
// RateDate is the publication date of the table (YYYY-MM-DD); cite this,
// not today's date.
RateDate string `json:"rate_date"`
Rates []OfficialRateEntry `json:"rates,omitempty"`
Source string `json:"source,omitempty"`
Target string `json:"target,omitempty"`
Rate float64 `json:"rate,omitempty"`
RateType string `json:"rate_type,omitempty"`
// Derived is true when the pair was cross-computed inside the bank's
// own table rather than published directly.
Derived bool `json:"derived,omitempty"`
Method string `json:"method,omitempty"`
AgeDays int `json:"age_days"`
// Stale is true when the institution is behind its own schedule.
Stale bool `json:"stale"`
Cadence string `json:"cadence,omitempty"`
Attribution OfficialRateAttribution `json:"attribution"`
FreeKey string `json:"free_key,omitempty"`
}
OfficialRatesResponse is returned by OfficialRates. With a pair, Source, Target, Rate and RateType are set; without one, Rates holds the full table.
type OfficialSource ¶ added in v1.1.0
type OfficialSource struct {
// Code is what you pass as bank to OfficialRates, e.g. "ecb".
Code string `json:"code"`
Name string `json:"name"`
// Latest is the latest publication date, or "" if never ingested.
Latest string `json:"latest"`
AgeDays int `json:"age_days"`
Stale bool `json:"stale"`
Cadence string `json:"cadence"`
}
OfficialSource is one entry returned by OfficialSources.
type OfficialSourcesResponse ¶ added in v1.1.0
type OfficialSourcesResponse struct {
Sources []OfficialSource `json:"sources"`
StaleCount int `json:"stale_count"`
CheckedAt string `json:"checked_at"`
Docs string `json:"docs"`
FreeKey string `json:"free_key"`
}
OfficialSourcesResponse is returned by OfficialSources.
type Option ¶
type Option func(*Client)
Option configures a Client created by NewClient.
func WithBaseURL ¶
WithBaseURL overrides the default API host (useful for testing).
func WithHTTPClient ¶
WithHTTPClient replaces the underlying *http.Client (custom timeouts, proxies, instrumentation, ...).
type Rate ¶ added in v1.1.0
type Rate struct {
Rate float64 `json:"rate"`
Source string `json:"source"`
Target string `json:"target"`
// Time is the observation time, e.g. "2026-10-16T11:31:01+0000".
Time string `json:"time"`
}
Rate is one element of the list returned by GET /api/v1/rates.
type RateResponse ¶
type RateResponse struct {
// Deprecated: always true. Failures are returned as an error.
Success bool `json:"success"`
From string `json:"from"`
To string `json:"to"`
Rate float64 `json:"rate"`
// Date is the observation time, e.g. "2026-10-16T11:31:01+0000".
Date string `json:"date"`
}
RateResponse is returned by GetRate.
type SymbolsResponse ¶
type SymbolsResponse struct {
// Deprecated: always true. Failures are returned as an error.
Success bool `json:"success"`
// Symbols maps each currency code to its details.
Symbols map[string]CurrencySymbol `json:"symbols"`
// Currencies is the list in the order the API returns it.
Currencies []CurrencySymbol `json:"currencies"`
Count int `json:"count"`
}
SymbolsResponse is returned by Symbols.
type TimeSeriesResponse ¶
type TimeSeriesResponse struct {
// Deprecated: always true. Failures are returned as an error.
Success bool `json:"success"`
Base string `json:"base"`
StartDate string `json:"start_date"`
EndDate string `json:"end_date"`
Rates map[string]map[string]float64 `json:"rates"`
}
TimeSeriesResponse is returned by TimeSeries. Rates is keyed by date (YYYY-MM-DD), then by currency code.