Documentation
ยถ
Overview ยถ
Package allratestoday is the official Go client for the AllRatesToday exchange rate API (https://allratestoday.com). It provides access to real-time mid-market exchange rates for 160+ currencies, plus historical data, time series and conversion.
Create a free API key at https://allratestoday.com/register. Keys look like "art_live_...", and the client sends yours as a Bearer token in the Authorization header on every request.
client := allratestoday.NewClient("art_live_your_api_key")
rates, err := client.Latest(context.Background(), "USD", []string{"EUR", "GBP"})
Index ยถ
- Constants
- type Client
- func (c *Client) Convert(ctx context.Context, from, to string, amount float64) (*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) 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) 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 Option
- type RateResponse
- type SymbolsResponse
- type TimeSeriesResponse
Constants ยถ
const DefaultBaseURL = "https://allratestoday.com"
DefaultBaseURL is the production API host.
Variables ยถ
This section is empty.
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.
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.
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".
func (*Client) Historical ยถ
func (c *Client) Historical(ctx context.Context, date, base string, symbols []string) (*HistoricalResponse, error)
Historical returns exchange rates as of a specific past date (YYYY-MM-DD). Pass a nil or empty symbols slice for every currency.
func (*Client) Latest ยถ
func (c *Client) Latest(ctx context.Context, base string, symbols []string) (*LatestResponse, error)
Latest returns the most recent exchange rates for a base currency. Pass a nil or empty symbols slice to receive every available currency.
func (*Client) Symbols ยถ
func (c *Client) Symbols(ctx context.Context) (*SymbolsResponse, error)
Symbols lists every supported currency code with its details.
func (*Client) TimeSeries ยถ
func (c *Client) TimeSeries(ctx context.Context, startDate, endDate, base string, symbols []string) (*TimeSeriesResponse, error)
TimeSeries returns exchange rates across a date range, keyed by date. Dates are YYYY-MM-DD. Pass a nil or empty symbols slice for every currency.
type ConvertResponse ยถ
type ConvertResponse struct {
Success bool `json:"success"`
From string `json:"from"`
To string `json:"to"`
Amount float64 `json:"amount"`
Result float64 `json:"result"`
Rate float64 `json:"rate"`
}
ConvertResponse is the response from GET /v1/convert.
type CurrencySymbol ยถ
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).
Message string
}
Error is returned when the API responds with a non-2xx status code.
type HistoricalRatePoint ยถ
HistoricalRatePoint is a single date/rate observation in a HistoricalRatesResponse.
type HistoricalRatesResponse ยถ
type HistoricalRatesResponse struct {
Success bool `json:"success"`
Source string `json:"source"`
Target string `json:"target"`
Period string `json:"period"`
Rates []HistoricalRatePoint `json:"rates"`
}
HistoricalRatesResponse is the response from GET /v1/historical-rates (a currency pair over a preset period).
type HistoricalResponse ยถ
type HistoricalResponse struct {
Success bool `json:"success"`
Base string `json:"base"`
Date string `json:"date"`
Rates map[string]float64 `json:"rates"`
}
HistoricalResponse is the response from GET /v1/historical.
type LatestResponse ยถ
type LatestResponse struct {
Success bool `json:"success"`
Base string `json:"base"`
Date string `json:"date"`
Rates map[string]float64 `json:"rates"`
}
LatestResponse is the response from GET /v1/latest.
type Option ยถ
type Option func(*Client)
Option configures a Client created by NewClient.
func WithBaseURL ยถ
WithBaseURL overrides the default API host (useful for testing or a self-hosted deployment).
func WithHTTPClient ยถ
WithHTTPClient replaces the underlying *http.Client (custom timeouts, proxies, instrumentation, ...).
type RateResponse ยถ
type RateResponse struct {
Success bool `json:"success"`
From string `json:"from"`
To string `json:"to"`
Rate float64 `json:"rate"`
Date string `json:"date"`
}
RateResponse is the response from GET /v1/rate (single pair).
type SymbolsResponse ยถ
type SymbolsResponse struct {
Success bool `json:"success"`
Symbols map[string]CurrencySymbol `json:"symbols"`
}
SymbolsResponse is the response from GET /v1/symbols.
type TimeSeriesResponse ยถ
type TimeSeriesResponse struct {
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 the response from GET /v1/timeseries. Rates is keyed by date (YYYY-MM-DD), then by currency code.