Code Example: Get latest rates

Last updated 3 months ago

Get all the rates with base currency Euro. Every other base is also possible. For getting even more accurate rates, attach your premium token to the request url

Please note that these are basic examples not targeted for production usage.

const request = require('request');
//Make request
request('', function (error, response, body) {
//Error catching
if (error){
//Parse JSON data
let responseObj = JSON.parse(body);
//Dataset timestamp
//1000 because JavaScript uses milliseconds for date - unix timestamp is only seconds
let dataTimestamp = new Date(responseObj.timestamp*1000);"Data Timestamp: "+ dataTimestamp);
//Iterate over rates and print them
//foreach-loop for objects - kind of ;)
Object.keys(responseObj.rates).forEach(function(key) {
let singleRate = responseObj.rates[key];
//1000 because JavaScript uses milliseconds for date - unix timestamp is only seconds
let singleRateTimestamp = new Date(singleRate.timestamp*1000);
let singleRateRate = singleRate.rate;
let singleRateCurrencyCode = singleRate.currency;
console.log("["+singleRateTimestamp+"]: 1 EUR = "+singleRateRate+" "+singleRateCurrencyCode);
$apiURL = "";
$jsonApiData = file_get_contents($apiURL);
//Decode the the json to php object
$apiObj = json_decode($jsonApiData);
//dataset timestamp
//Iterate trough object
foreach($apiObj->rates as &$rate){
printf("[".date('c',$rate->timestamp)."]: 1 EUR = ".$rate->rate." ".$rate->currency."<br>");
package main
import (
type CurrencyRate struct{
Currency string `json:"currency" xml:"currency,attr"`
Rate float64 `json:"rate" xml:"rate,attr"`
type LatestRatesResponse struct{
XMLName xml.Name `xml:"latest_rates" json:"-"`
Timestamp string `json:"timestamp_utc" xml:"timestamp_utc,attr"`
BaseCurrency string `xml:"base_currency,attr" json:"base_currency"`
Rates map[string]CurrencyRate `json:"rates" xml:"rates"`
func main() {
var latestRates LatestRatesResponse
//Get api data
resp, err := http.Get("")
if err != nil{
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil{
err = json.Unmarshal(body,&latestRates)
if err != nil{
for k,v := range latestRates.Rates{
fmt.Printf("1 %s = %f %s\n",latestRates.BaseCurrency,v.Rate,k);