Skip to content

houseofapis/currencyapi-go

Repository files navigation

CurrencyApi Golang wrapper

Go project version Coverage Status

Note: API v1 is deprecated and will be retired on 31st July 2026, at which point all v1 traffic will be redirected to v2. This SDK (v2.0.0+) targets API v2. If you are on an older version of this SDK, please upgrade.

CurrencyApi.net provides live currency rates via a REST API. A live currency feed for over 166 currencies, including physical (USD, GBP, EUR + more) and cryptos (Bitcoin, Litecoin, Ethereum + more). A JSON and XML currency api updated every 60 seconds.

Features:

  • Live exchange rates (updated every 60 seconds).
  • 166 world currencies.
  • Popular cryptocurrencies included; Bitcoin, Litecoin etc.
  • Convert currencies on the fly with the convert endpoint.
  • Historical currency rates back to year 2000.
  • OHLC (Open, High, Low, Close) candlestick data for technical analysis (Tier 3+).
  • Easy to follow documentation

Signup for a free or paid account here.

This package is a:

Golang wrapper for CurrencyApi.net endpoints.

Developer Guide

For an easy to following developer guide, check out our Golang Developer Guide.

Alternatively keep reading below.

Prerequisites

  • Minimum Go 1.21
  • Working on Go 1.26
  • Free or Paid account with CurrencyApi.net

Test Coverage

  • 100% coverage

Installation

go get github.com/houseofapis/currencyapi-go

then import the package with:

import (
    ...
	"github.com/houseofapis/currencyapi-go"
	...
)

Usage

Instantiating

client := currencyapi.Client("API_KEY")

Live rates:

params := map[string]string{
    "output": "JSON",
    "base":   "USD",
}

body, err := client.Rates(params)

Available params for rates endpoint

Methods Description
base The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. Default: USD.
output Response output in either JSON or XML. Default: JSON.

List of available currencies:

params := map[string]string{
    "output": "XML"
}

body, err := client.Currencies(params)

Available methods for currencies endpoint

Methods Description
output Response output in either JSON or XML. Default: JSON.

Convert:

params := map[string]string{
    "output": "JSON",
    "from": "USD",
    "to": "GBP",
    "amount": 15.99,
}

body, err := client.Convert(params)

Available methods for convert endpoint

Methods Description
amount The value of the currency you want to convert from. This should be a number and can contain a decimal place. Required.
from The currency you want to convert. This will be a three letter ISO 4217 currency code from one of the currencies we have rates for. Required.
to The currency you want to convert the amount 'to'. Again this will be a three letter currency code from the ones we offer. Required.
output Response output in either JSON or XML. Default: JSON.

Historical:

params := map[string]string{
    "output": "JSON",
    "base": "GBP",
    "date": "2019-01-01"
}

body, err := client.History(params)

Available methods for historical endpoint

Methods Description
date The historical date you wish to receive the currency conversions for. This should be formatted as YYYY-MM-DD. Required.
base The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. Default: USD.
output Response output in either JSON or XML. Default: JSON.

Timeframe:

params := map[string]string{
    "output": "JSON",
    "base": "GBP",
    "start_date": "2019-01-01"
    "end_date": "2019-01-05"
}

body, err := client.Timeframe(params)

Available methods for timeframe endpoint

Methods Description
start_date The historical date you wish to receive the currency conversions from. This should be formatted as YYYY-MM-DD. Required.
end_date The historical date you wish to receive the currency conversions until. This should be formatted as YYYY-MM-DD. Required.
base The base currency you wish you receive the currency conversions for. This will output all currency conversions for that currency. Default: USD.
output Response output in either JSON or XML. Default: JSON.

OHLC (Open, High, Low, Close):

params := map[string]string{
    "quote":    "EUR",
    "date":     "2023-12-25",
    "interval": "1h",
}

body, err := client.Ohlc(params)

Available params for OHLC endpoint

Parameter Description
quote The quote currency code to retrieve OHLC data for (e.g. EUR, GBP, BTC). Required.
date The date you wish to retrieve OHLC data for. This should be formatted as YYYY-MM-DD and must be in the past. Required.
base The base currency for the pair. Default: USD.
interval The time interval for each OHLC candle. Allowed values: 5m, 15m, 30m, 1h, 4h, 12h, 1d. Default: 1d.
output Response output in either JSON or XML. Default: JSON.

Note: The OHLC endpoint requires a Tier 3 (Professional) subscription.

Packages

 
 
 

Contributors