NAV Navbar
cURL Go Python JavaScript Node.js PHP Java Ruby

Introduction

Welcome to the xChangeAPI.com documentation

You can use this API to access all our API endpoints.

The API is organized around REST. All requests should be made over SSL.

We also have some specific language bindings to make integration easier. You can switch the programming language of the examples with the tabs in the top right.

Currently we support the following official client bindings: Shell, Go, Python, JavaScript, Node.js, PHP, Java and Ruby.

To play around with a few examples, we recommend a REST client called Postman. Simply tap the button below to import a pre-made collection of examples.

URL Adress

The URL address that you need to use to connect to our API is:

Authentication

We use API keys to allow access to the API. You can register a new account on our website.

We expect for the API key to be included in all API requests to the server in a api-key header.

Data preview and properties

The response data from API can contain various properties. In general there are two structures of responses: the first one is for methods that obtain actual exchange rates and the second for the methods that enables you getting data from the past. Here we give the description for all the properties of response data.

Example response for actual exchange rates looks like this:

{
    "ask": "1.38488",
    "bid": "1.38477",
    "name": "EURUSD",
    "time": "1398420924.000"
}

Data contains the following fields:

Methods for data from the past (historical data, chart data) will have the following response structure:

{
    "1396267200": [
        1.3775,
        1.38071,
        1.37837,
        1.37989,
        1.37738,
        1.38055,
        1.37827,
        1.37976
    ],
    "1396274400": [
        1.37716,
        1.38071,
        1.37789,
        1.37758,
        1.37706,
        1.38059,
        1.37777,
        1.37747
    ]
}

This data contains is a dictionary of lists; each key in dictionary is a timestamp, which indicates the beginning of a single period for which the values were collected. The difference between timestamps is called the resolution of data.

The interpretation of values in each list is following:

Name Description
minimal ask price minimal ask price in the related period
maximal ask price maximal ask price in the related period
open ask price ask price at the beginning of the related period
close ask price ask price at the end of the related period
minimal bid price minimal bid price in the related period
maximal bid price maximal bid price in the related period
open bid price bid price at the beginning of the related period
close bid price bid price at the end of the related period

Data formats

For your needs and convenience, the currencies data is available in three formats: JSON, XML and CSV.

JSON

All methods for JSON are available as GET and POST methods. In both cases names and types of parameters are identical. Because JSON is the default format, you can also use the below presented methods without the /json part in each URL (for example, /currencies/all is a shorthand for /json/currencies/all). This is kept for consistency with other formats. When requesting data in this format, set the Content-Type header to application/json.

XML

Methods for XML format are available as POST methods and requires XML-formatted request body. Names of methods and parameters are identical to those in JSON format. When requesting data in XML format, set the Content-Type header to application/xml or text/xml. Here we present the example requests and responses specific to XML format; the details of each method and its parameters can be found in JSON section.

CSV

All methods for CSV format are available as both GET and POST methods. The input parameters are taken in JSON format and the method calls are the same as for the JSON format (JSON), in this case, only the output is CSV-formatted. When requesting API for CSV format, the Content-Type header should be set to application/json. In this section we present available methods and example responses in CSV format; the details of each method and its parameters, as well as example requests can be found in JSON section.

For each method, first row in response is a header row with names of each column and the following rows contain the exchange rates data. For the description of fields go to Data preview and properties.

Single currency pair rates

In order to get the current exchange rate for a single currency pair, use the following method:

JSON

GET
/json/currencies/<currency-pair>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/json/currencies/EURUSD' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/json/currencies/EURUSD"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/json/currencies/EURUSD"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/json/currencies/EURUSD");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/json/currencies/EURUSD',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/json/currencies/EURUSD",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/json/currencies/EURUSD")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/json/currencies/EURUSD")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

{
    "ask": "1.06742",
    "bid": "1.06727",
    "name": "EURUSD",
    "time": "1584640370.007"
}

XML

POST
/xml/currencies/<currency-pair>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)

Example request:

curl --location --request POST 'https://api.xchangeapi.com/xml/currencies/EURUSD' \
--header 'Content-Type: application/xml' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/xml/currencies/EURUSD"
  method := "POST"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/xml")
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/xml/currencies/EURUSD"

payload  = {}
headers = {
  'Content-Type': 'application/xml',
  'api-key': 'your-api-key'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.xchangeapi.com/xml/currencies/EURUSD");
xhr.setRequestHeader("Content-Type", "application/xml");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api.xchangeapi.com/xml/currencies/EURUSD',
  'headers': {
    'Content-Type': 'application/xml',
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/xml/currencies/EURUSD",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/xml",
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/xml/currencies/EURUSD")
  .method("POST", body)
  .addHeader("Content-Type", "application/xml")
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/xml/currencies/EURUSD")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/xml"
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

<result>
    <currency>
        <ask>1.06815</ask>
        <bid>1.06802</bid>
        <name>EURUSD</name>
        <time>1584637850.267</time>
    </currency>
</result>

CSV

GET
/csv/currencies/<currency-pair>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/csv/currencies/EURUSD' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/csv/currencies/EURUSD"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/csv/currencies/EURUSD"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/csv/currencies/EURUSD");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/csv/currencies/EURUSD',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/csv/currencies/EURUSD",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/csv/currencies/EURUSD")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/csv/currencies/EURUSD")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

ask,bid,name,time
1.06657,1.06644,EURUSD,1584640537.442

Many currency pairs rates

Use this method to get rates for a list of provided currencies pairs.

JSON

GET
/json/currencies?pairs=["<currency-pair-1>", [...], "<currency-pair-n>"]
Parameter Description
currency-pair-{1-n} desired currency pair (see: list of available currencies)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/json/currencies?pairs=[%22EURUSD%22,%20%22CHFGBP%22]%0A' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/json/currencies?pairs=%5B%22EURUSD%22,%20%22CHFGBP%22%5D%0A"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/json/currencies?pairs=[\"EURUSD\", \"CHFGBP\"]
"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/json/currencies?pairs=%5B%22EURUSD%22,%20%22CHFGBP%22%5D%0A");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/json/currencies?pairs=%5B%22EURUSD%22,%20%22CHFGBP%22%5D%0A",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/json/currencies?pairs=[\"EURUSD\", \"CHFGBP\"]
")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/json/currencies?pairs=[\"EURUSD\", \"CHFGBP\"]
")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

[
    {
        "ask": "1.06750",
        "bid": "1.06739",
        "name": "EURUSD",
        "time": "1584641785.210"
    },
    {
        "ask": "0.87759",
        "bid": "0.87680",
        "name": "CHFGBP",
        "time": "1584641785.001"
    }
]

XML

POST
/xml/currencies

Requests should be sent with the following body:

<data>
  <pair>EURUSD</pair>
  <pair>CHFGBP</pair>
</data>

Example request:

curl --location --request POST 'https://api.xchangeapi.com/xml/currencies
' \
--header 'Content-Type: application/xml' \
--header 'api-key: your-api-key' \
--data-raw '<data>
  <pair>EURUSD</pair>
  <pair>CHFGBP</pair>
</data>'
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/xml/currencies%0A"
  method := "POST"

  payload := strings.NewReader("<data>\n  <pair>EURUSD</pair>\n  <pair>CHFGBP</pair>\n</data>")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/xml")
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/xml/currencies
"

payload = "<data>\n  <pair>EURUSD</pair>\n  <pair>CHFGBP</pair>\n</data>"
headers = {
  'Content-Type': 'application/xml',
  'api-key': 'your-api-key'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "<data>\n  <pair>EURUSD</pair>\n  <pair>CHFGBP</pair>\n</data>");
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/xml/currencies
")
  .method("POST", body)
  .addHeader("Content-Type", "application/xml")
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api.xchangeapi.com/xml/currencies\n',
  'headers': {
    'Content-Type': 'application/xml',
    'api-key': 'your-api-key'
  },
  body: "<data>\n  <pair>EURUSD</pair>\n  <pair>CHFGBP</pair>\n</data>"

};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/xml/currencies%0A",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"<data>\n  <pair>EURUSD</pair>\n  <pair>CHFGBP</pair>\n</data>",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/xml",
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "<data>\n  <pair>EURUSD</pair>\n  <pair>CHFGBP</pair>\n</data>");
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/xml/currencies
")
  .method("POST", body)
  .addHeader("Content-Type", "application/xml")
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/xml/currencies
")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/xml"
request["api-key"] = "your-api-key"
request.body = "<data>\n  <pair>EURUSD</pair>\n  <pair>CHFGBP</pair>\n</data>"

response = http.request(request)
puts response.read_body

Example response:

<result>
    <currency>
        <ask>1.06765</ask>
        <bid>1.06751</bid>
        <name>EURUSD</name>
        <time>1584642398.460</time>
    </currency>
    <currency>
        <ask>0.87803</ask>
        <bid>0.87731</bid>
        <name>CHFGBP</name>
        <time>1584642398.623</time>
    </currency>
</result>

CSV

GET
/csv/currencies?pairs=["<currency-pair-1>", [...], "<currency-pair-n>"]
Parameter Description
currency-pair-{1-n} desired currency pair (see: list of available currencies)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/csv/currencies?pairs=[%22EURUSD%22,%20%22CHFGBP%22]%0A' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/csv/currencies?pairs=%5B%22EURUSD%22,%20%22CHFGBP%22%5D%0A"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/csv/currencies?pairs=[\"EURUSD\", \"CHFGBP\"]
"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/csv/currencies?pairs=%5B%22EURUSD%22,%20%22CHFGBP%22%5D%0A");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/csv/currencies?pairs=["EURUSD", "CHFGBP"]\n',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/csv/currencies?pairs=%5B%22EURUSD%22,%20%22CHFGBP%22%5D%0A",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/csv/currencies?pairs=[\"EURUSD\", \"CHFGBP\"]
")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/csv/currencies?pairs=[\"EURUSD\", \"CHFGBP\"]
")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

ask,bid,name,time
1.06716,1.06703,EURUSD,1584642639.905
0.87774,0.87709,CHFGBP,1584642639.276

All currency pairs rates

Use this method to get rates for all of available currencies pairs.

JSON

GET
/json/currencies/all

Example request:

curl --location --request GET 'https://api.xchangeapi.com/json/currencies/all' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/json/currencies/all"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/json/currencies/all"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/json/currencies/all");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/json/currencies/all',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/json/currencies/all",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/json/currencies/all")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/json/currencies/all")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

[
    {
        "ask": "28.23900",
        "bid": "27.23900",
        "name": "USDUAH",
        "time": "1584712816.841"
    },
    [...]
    {
        "ask": "230.68705",
        "bid": "227.99439",
        "name": "ETHNZD",
        "time": "1584793264.569"
    }
]

XML

GET
/xml/currencies/all

Example request:

curl --location --request GET 'https://api.xchangeapi.com/xml/currencies/all' \
--header 'Content-Type: application/xml' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/xml/currencies/all"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/xml")
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/xml/currencies/all"

payload  = {}
headers = {
  'Content-Type': 'application/xml',
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/xml/currencies/all");
xhr.setRequestHeader("Content-Type", "application/xml");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/xml/currencies/all',
  'headers': {
    'Content-Type': 'application/xml',
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/xml/currencies/all",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/xml",
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/xml/currencies/all")
  .method("GET", null)
  .addHeader("Content-Type", "application/xml")
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/xml/currencies/all")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["Content-Type"] = "application/xml"
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

<result>
    <currency>
        <ask>28.23900</ask>
        <bid>27.23900</bid>
        <name>USDUAH</name>
        <time>1584712816.841</time>
    </currency>
    [...]
    <currency>
        <ask>231.24748</ask>
        <bid>228.43153</bid>
        <name>ETHNZD</name>
        <time>1584793483.684</time>
    </currency>
</result>

CSV

GET
/csv/currencies/all

Example request:

curl --location --request GET 'https://api.xchangeapi.com/csv/currencies/all' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/csv/currencies/all"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/csv/currencies/all"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/csv/currencies/all");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/csv/currencies/all',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/csv/currencies/all",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/csv/currencies/all")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/csv/currencies/all")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

ask,bid,name,time
1.05611,1.05272,AUDBGN,1584737977.016
[...]
6.33750,6.26250,ZARJPY,1584737972.955

Historical data

You can access historical exchange rates with the specified resolution by using the following method.

JSON

GET
/json/history/<currency-pair>?starttime=<starttime>&endtime=<endtime>&resolution=<resolution>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
starttime UNIX timestamp indicating the date of the beginning of requested period, for example 1577836800 for 1st of January 2020.
endtime as above, but it is the date of the end of requested period
resolution resolution of data, possible values are: 1, 5, 10, 60, 1800 (see: data properties)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/json/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

{
    "1577836800": [
        1.12182,
        1.1221,
        1.12182,
        1.1221,
        1.12169,
        1.12199,
        1.12169,
        1.12199
    ],
    "1577836920": [
        1.12181,
        1.12182,
        1.12181,
        1.12181,
        1.12169,
        1.12169,
        1.12169,
        1.12169
    ],
    "1577836860": [
        1.12181,
        1.12182,
        1.12181,
        1.12181,
        1.12169,
        1.12169,
        1.12169,
        1.12169
    ]
}

XML

POST
/xml/history/
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
starttime UNIX timestamp indicating the date of the beginning of requested period, for example 1577836800 for 1st of January 2020.
endtime as above, but it is the date of the end of requested period
resolution resolution of data, possible values are: 1, 5, 10, 60, 1800 (see: data properties)

Example request:

curl --location --request POST 'https://api.xchangeapi.com/xml/history/EURUSD' \
--header 'Content-Type: application/xml' \
--header 'api-key: your-api-key' \
--data-raw '<data>
    <starttime>1577836800</starttime>
    &lt;endtime>1577836920</endtime>
    &lt;resolution>60</resolution>
</data>'
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/xml/history/EURUSD"
  method := "POST"

  payload := strings.NewReader("<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n    &lt;resolution>60</resolution>\n</data>")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/xml")
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/xml/history/EURUSD"

payload = "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n    &lt;resolution>60</resolution>\n</data>"
headers = {
  'Content-Type': 'application/xml',
  'api-key': 'your-api-key'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n    &lt;resolution>60</resolution>\n</data>";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.xchangeapi.com/xml/history/EURUSD");
xhr.setRequestHeader("Content-Type", "application/xml");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api.xchangeapi.com/xml/history/EURUSD',
  'headers': {
    'Content-Type': 'application/xml',
    'api-key': 'your-api-key'
  },
  body: "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n    &lt;resolution>60</resolution>\n</data>"

};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/xml/history/EURUSD",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n    &lt;resolution>60</resolution>\n</data>",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/xml",
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n    &lt;resolution>60</resolution>\n</data>");
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/xml/history/EURUSD")
  .method("POST", body)
  .addHeader("Content-Type", "application/xml")
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/xml/history/EURUSD")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/xml"
request["api-key"] = "your-api-key"
request.body = "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n    &lt;resolution>60</resolution>\n</data>"

response = http.request(request)
puts response.read_body

Example response:

<result>
    <item>
        <time>1577836800</time>
        <min_ask>1.12182</min_ask>
        <max_ask>1.1221</max_ask>
        <open_ask>1.12182</open_ask>
        <close_ask>1.1221</close_ask>
        <min_bid>1.12169</min_bid>
        <max_bid>1.12199</max_bid>
        <open_bid>1.12169</open_bid>
        <close_bid>1.12199</close_bid>
    </item>
    <item>
        <time>1577836860</time>
        <min_ask>1.12181</min_ask>
        <max_ask>1.12182</max_ask>
        <open_ask>1.12181</open_ask>
        <close_ask>1.12181</close_ask>
        <min_bid>1.12169</min_bid>
        <max_bid>1.12169</max_bid>
        <open_bid>1.12169</open_bid>
        <close_bid>1.12169</close_bid>
    </item>
    <item>
        <time>1577836920</time>
        <min_ask>1.12181</min_ask>
        <max_ask>1.12182</max_ask>
        <open_ask>1.12181</open_ask>
        <close_ask>1.12181</close_ask>
        <min_bid>1.12169</min_bid>
        <max_bid>1.12169</max_bid>
        <open_bid>1.12169</open_bid>
        <close_bid>1.12169</close_bid>
    </item>
</result>

CSV

GET
/csv/history/<currency-pair>?starttime=<starttime>&endtime=<endtime>&resolution=<resolution>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
starttime UNIX timestamp indicating the date of the beginning of requested period, for example 1577836800 for 1st of January 2020.
endtime as above, but it is the date of the end of requested period
resolution resolution of data, possible values are: 1, 5, 10, 60, 1800 (see: data properties)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var http = require('follow-redirects').http;
var fs = require('fs');

var options = {
  'method': 'GET',
  'hostname': 'api.xchangeapi.com',
  'path': '/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920',
  'headers': {
    'api-key': 'your-api-key'
  },
  'maxRedirects': 20
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

req.end();
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/csv/history/EURUSD?starttime=1577836800&resolution=60&endtime=1577836920")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_bodys

Example response:

time,min_ask,max_ask,open_ask,close_ask,min_bid,max_bid,open_bid,close_bid
1577836800,1.12182,1.1221,1.12182,1.1221,1.12169,1.12199,1.12169,1.12199
1577836860,1.12181,1.12182,1.12181,1.12181,1.12169,1.12169,1.12169,1.12169
1577836920,1.12181,1.12182,1.12181,1.12181,1.12169,1.12169,1.12169,1.12169

Chart peaks for selected period

Chart data is similar to historical data. The only difference is, that in this case the resolution is calculated automatically. With the following method, you can access data for the specified periods of time.

JSON

GET
/json/chart/<currency-pair>/<period>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
period one of predefined time periods (30m - last 30 minutes, 1h - last hour, 6h - last 6 hours, 12h - last 12 hours, 1d - last day, 2d - last 2 days, 7d - last 7 days, 1M - last month, 3M - last 3 months, 6M - last 6 months, 1Y - last year)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/json/chart/EURUSD/1d' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/json/chart/EURUSD/1d"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/json/chart/EURUSD/1d"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/json/chart/EURUSD/1d");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/json/chart/EURUSD/1d',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/json/chart/EURUSD/1d",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/json/chart/EURUSD/1d")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/json/chart/EURUSD/1d")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

{
    "1584714240": [
        1.07217,
        1.07372,
        1.07329,
        1.07233,
        1.07205,
        1.07358,
        1.07315,
        1.07217
    ],
    [...]
    "1584728880": [
        1.0641,
        1.06594,
        1.06543,
        1.06542,
        1.06396,
        1.06583,
        1.06531,
        1.06529
    ]
}

XML

POST
/xml/chart/<currency-pair>/<period>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
period one of predefined time periods (30m - last 30 minutes, 1h - last hour, 6h - last 6 hours, 12h - last 12 hours, 1d - last day, 2d - last 2 days, 7d - last 7 days, 1M - last month, 3M - last 3 months, 6M - last 6 months, 1Y - last year)

Example request:

curl --location --request POST 'https://api.xchangeapi.com/xml/chart/EURUSD/1d' \
--header 'Content-Type: application/xml' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/xml/chart/EURUSD/1d"
  method := "POST"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/xml")
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/xml/chart/EURUSD/1d"

payload  = {}
headers = {
  'Content-Type': 'application/xml',
  'api-key': 'your-api-key'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.xchangeapi.com/xml/chart/EURUSD/1d");
xhr.setRequestHeader("Content-Type", "application/xml");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api.xchangeapi.com/xml/chart/EURUSD/1d',
  'headers': {
    'Content-Type': 'application/xml',
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/xml/chart/EURUSD/1d",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/xml",
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/xml/chart/EURUSD/1d")
  .method("POST", body)
  .addHeader("Content-Type", "application/xml")
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/xml/chart/EURUSD/1d")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/xml"
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

<result>
    <item>
        <time>1584709680</time>
        <min_ask>1.07</min_ask>
        <max_ask>1.07129</max_ask>
        <open_ask>1.0703</open_ask>
        <close_ask>1.0711</close_ask>
        <min_bid>1.06988</min_bid>
        <max_bid>1.07115</max_bid>
        <open_bid>1.07019</open_bid>
        <close_bid>1.07097</close_bid>
    </item>
    [...]
    <item>
        <time>1584737520</time>
        <min_ask>1.06966</min_ask>
        <max_ask>1.07034</max_ask>
        <open_ask>1.0699</open_ask>
        <close_ask>1.06996</close_ask>
        <min_bid>1.0692</min_bid>
        <max_bid>1.06987</max_bid>
        <open_bid>1.06927</open_bid>
        <close_bid>1.06966</close_bid>
    </item>
</result>

CSV

GET
/csv/chart/<currency-pair>/<period>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
period one of predefined time periods (30m - last 30 minutes, 1h - last hour, 6h - last 6 hours, 12h - last 12 hours, 1d - last day, 2d - last 2 days, 7d - last 7 days, 1M - last month, 3M - last 3 months, 6M - last 6 months, 1Y - last year)

Example request:

curl --location --request GET 'https://api.xchangeapi.com/csv/chart/EURUSD/1d' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/csv/chart/EURUSD/1d"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/csv/chart/EURUSD/1d"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/csv/chart/EURUSD/1d");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/csv/chart/EURUSD/1d',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/csv/chart/EURUSD/1d",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/csv/chart/EURUSD/1d")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/csv/chart/EURUSD/1d")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

time,min_ask,max_ask,open_ask,close_ask,min_bid,max_bid,open_bid,close_bid
1584709680,1.07024,1.07129,1.0703,1.0711,1.07014,1.07115,1.07019,1.07097
[...]
1584737520,1.06966,1.07034,1.0699,1.06996,1.0692,1.06987,1.06927,1.06966

Chart peaks for date range

Use this method to get the chart data for some specific period of time.

JSON

GET
/json/chart/<currency-pair>?starttime=<starttime>&endtime=<endtime>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
starttime UNIX timestamp indicating the date of the beginning of requested period, for example 1577836800 for 1st of January 2020.
endtime as above, but it is the date of the end of requested periods

Example request:

curl --location --request GET 'https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/json/chart/EURUSD?starttime=1577836800&endtime=1577836920")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

{
    "1577836800": [
        1.12182,
        1.1221,
        1.12182,
        1.1221,
        1.12169,
        1.12199,
        1.12169,
        1.12199
    ],
    "1577836920": [
        1.12181,
        1.12182,
        1.12181,
        1.12181,
        1.12169,
        1.12169,
        1.12169,
        1.12169
    ],
    "1577836860": [
        1.12181,
        1.12182,
        1.12181,
        1.12181,
        1.12169,
        1.12169,
        1.12169,
        1.12169
    ]
}

XML

POST
/xml/chart/<currency-pair>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
starttime UNIX timestamp indicating the date of the beginning of requested period, for example 1577836800 for 1st of January 2020.
endtime as above, but it is the date of the end of requested periods

Example request:

curl --location --request POST 'https://api.xchangeapi.com/xml/chart/EURUSD' \
--header 'Content-Type: application/xml' \
--header 'api-key: your-api-key' \
--data-raw '<data>
    <starttime>1577836800</starttime>
    &lt;endtime>1577836920</endtime>
</data>'
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/xml/chart/EURUSD"
  method := "POST"

  payload := strings.NewReader("<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n</data>")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("Content-Type", "application/xml")
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/xml/chart/EURUSD"

payload = "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n</data>"
headers = {
  'Content-Type': 'application/xml',
  'api-key': 'your-api-key'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n</data>";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://api.xchangeapi.com/xml/chart/EURUSD");
xhr.setRequestHeader("Content-Type", "application/xml");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://api.xchangeapi.com/xml/chart/EURUSD',
  'headers': {
    'Content-Type': 'application/xml',
    'api-key': 'your-api-key'
  },
  body: "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n</data>"

};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/xml/chart/EURUSD",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS =>"<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n</data>",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/xml",
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/xml");
RequestBody body = RequestBody.create(mediaType, "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n</data>");
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/xml/chart/EURUSD")
  .method("POST", body)
  .addHeader("Content-Type", "application/xml")
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/xml/chart/EURUSD")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/xml"
request["api-key"] = "your-api-key"
request.body = "<data>\n    <starttime>1577836800</starttime>\n    &lt;endtime>1577836920</endtime>\n</data>"

response = http.request(request)
puts response.read_body

Example response:

<result>
    <item>
        <time>1577836800</time>
        <min_ask>1.12182</min_ask>
        <max_ask>1.1221</max_ask>
        <open_ask>1.12182</open_ask>
        <close_ask>1.1221</close_ask>
        <min_bid>1.12169</min_bid>
        <max_bid>1.12199</max_bid>
        <open_bid>1.12169</open_bid>
        <close_bid>1.12199</close_bid>
    </item>
    <item>
        <time>1577836860</time>
        <min_ask>1.12181</min_ask>
        <max_ask>1.12182</max_ask>
        <open_ask>1.12181</open_ask>
        <close_ask>1.12181</close_ask>
        <min_bid>1.12169</min_bid>
        <max_bid>1.12169</max_bid>
        <open_bid>1.12169</open_bid>
        <close_bid>1.12169</close_bid>
    </item>
    <item>
        <time>1577836920</time>
        <min_ask>1.12181</min_ask>
        <max_ask>1.12182</max_ask>
        <open_ask>1.12181</open_ask>
        <close_ask>1.12181</close_ask>
        <min_bid>1.12169</min_bid>
        <max_bid>1.12169</max_bid>
        <open_bid>1.12169</open_bid>
        <close_bid>1.12169</close_bid>
    </item>
</result>

CSV

GET
/csv/chart/<currency-pair>?starttime=<starttime>&endtime=<endtime>
Parameter Description
currency-pair desired currency pair (see: list of available currencies)
starttime UNIX timestamp indicating the date of the beginning of requested period, for example 1577836800 for 1st of January 2020.
endtime as above, but it is the date of the end of requested periods

Example request:

curl --location --request GET 'https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920' \
--header 'api-key: your-api-key' \
--data-raw ''
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)

func main() {

  url := "https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920"
  method := "GET"

  payload := strings.NewReader("")

  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
  }
  req.Header.Add("api-key", "your-api-key")

  res, err := client.Do(req)
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)

  fmt.Println(string(body))
}
import requests

url = "https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920"

payload  = {}
headers = {
  'api-key': 'your-api-key'
}

response = requests.request("GET", url, headers=headers, data = payload)

print(response.text.encode('utf8'))
var data = "";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920");
xhr.setRequestHeader("api-key", "your-api-key");

xhr.send(data);
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920',
  'headers': {
    'api-key': 'your-api-key'
  }
};
request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "api-key: your-api-key"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920")
  .method("GET", null)
  .addHeader("api-key", "your-api-key")
  .build();
Response response = client.newCall(request).execute();
require "uri"
require "net/http"

url = URI("https://api.xchangeapi.com/csv/chart/EURUSD?starttime=1577836800&endtime=1577836920")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
request["api-key"] = "your-api-key"

response = http.request(request)
puts response.read_body

Example response:

time,min_ask,max_ask,open_ask,close_ask,min_bid,max_bid,open_bid,close_bid
1577836800,1.12182,1.1221,1.12182,1.1221,1.12169,1.12199,1.12169,1.12199
1577836860,1.12181,1.12182,1.12181,1.12181,1.12169,1.12169,1.12169,1.12169
1577836920,1.12181,1.12182,1.12181,1.12181,1.12169,1.12169,1.12169,1.12169

Websocket API

We designed a special websocket api to minimize traffic and latency. There you will find how to use this protocol. You will find also Protocol implementations, that you can use on your side.

Protocol description

It is websocket (rfc_6455), with disabled problematic PING/PONG messages. After initialization connections stays open unless you decide to close it (or you reach your limits etc). It’s avaliable via HTTP and HTTPS.

Message codes

The first character of each reply is a message code. The rest is a message body. There are the following codes:

Message code Example message Description
0 0{"time_mult": 1000, "start_time": 1401263211.188452,
"order": ["name", "ask", "bid", "time"],
"mapping": {"0": "EURUSD"}}
Output parameters:
  • time_mult - time multiplier, divide received relative timestamps for messages with code 1 by that value
  • start_time - a time that is base for all further relative timestamps
  • order - field names for key/value mapping used by code 1 messages
  • mapping - messages with code 1 will return numbers instead of pair names. Use this mapping to receive requested names.
1 10|1.36239|1.36223|2022 Data is separated by |. 0 means EURUSD (see mapping from 0 code) then we have ask value later we have bid value and at the end we have relative timestamp. Calculate like: 1401263211.188452 + 2022 / 1000 (start_time + relative_timestamp / time_mult)
2 2 A ping message (in most of implementations you can ignore it)

Error codes

Message code Example message Description
9 9{"num_error":90,"name":"XXXYYY","error":"Invalid choice"} Invalid pair chosen
7 7{"num_error":72 ,"error":"No valid elements given"} None of requested elements is avaliable.
7 7{"num_error":73 ,"error":"Invalid request data", data={}} Request data was malformed, data contains error information.

Example implementation

index.html

<!DOCTYPE html>
<html>
<body>
  <script src="websocket.js"></script>
  <pre id="output">Example API output:
-------------------
</pre>
  <script>

      var protocb = new Object(),
          wscb = new Object(),
          ws,
          pre = document.getElementById('output');

      protocb.__default = null;

      protocb.on0 = function() {
        print('Connected.');
      };

      protocb.on1 = function(data) {
        print('Data received: ' + JSON.stringify(data));
      };

      protocb.on2 = function() {
        print('Ping received.');
      };

      protocb.on7 = function(error) {
        print('Error:' + error);
      };

      protocb.on8 = function(error) {
        print('Error:' + error);
      };

      protocb.on9 = function(error) {
        print('Error:' + error);
      };

      protocb.fatal = function(error) {
        print('Error:' + error);
      };

      wscb.onopen = function() {
        print('Connection opened.');
      };

      wscb.onclose = function() {
        print('Connection closed.');
      };

      wscb.onerror = function() {
        print('Fatal error.');
      };

      var p = new Proto('wss://api.xchangeapi.com/websocket/live?api-key=your-api-key', wscb, protocb);

      p.start(['EURUSD', 'GBPCHF']);

      function print(message) {
        console.log(message);
        pre.innerHTML += message + "\n"
      }

  </script>
</body>
</html>

websocket.js

var Proto = function _Proto(wsUri, wscb, protocb, opts) {
    this.start_time = 0;
    this.wsUri = wsUri;
    this.time_mult = 1;
    this.mapping = {};
    this.order = [];
    this.wscbs = wscb;
    this.protocb = protocb;
    this.opts = opts || {};
};

Proto.prototype.start = function(pairs) {
    var ws = new WebSocket(this.wsUri);

    var self = this;

    ws.onmessage = function(evt) {
        return self.process(evt.data);
    }

    ws.onclose = this.wscbs.onclose;
    ws.onopen = function(evt) {
        self.wscbs.onopen(evt);
        ws.send(self.pack({"pairs": pairs, "options": self.opts}))
    };

    ws.onerror = this.wscbs.onerror;
}

Proto.prototype.process = function (data) {
    var t = data.substring(0, 1);
    var msg = data.substring(1);
    cb = this.protocb['on' + t]
    var inc_data = null;
    switch (t) {
    case '0':
        inc_data = this.unpackInit(msg);
        break;
    case '7':
    case '8':
    case '9':
        inc_data = this.unpackErrPair(msg);
        break;
    case '1':
        inc_data = this.unpackData(msg);
        break;
    case '2':
        inc_data = "";
        break
    default:
        break;
    }
    if(inc_data != null) {
        if(cb) {
            cb(inc_data);
        } else {
            if(cb === null) { return } // quiet mode
            var default_cb = this.protocb['__default'];
            if(default_cb) {
                default_cb(inc_data);
            } else {
                this.protocb.fatal(data);
            }
        }
    } else {
        this.protocb.fatal(data);
    }
};

Proto.prototype.unpackErrPair = function (data) {
    return JSON.parse(data);
};

Proto.prototype.unpackInit = function (data) {
    var meta = JSON.parse(data);
    this.start_time = meta['start_time'];
    this.mapping = meta['mapping'];
    this.order = meta['order'];
    this.time_mult = meta['time_mult'];
    return meta;
};

Proto.prototype.unpackData = function(data) {
    var inc = data.split('|');
    var out = {};
    for (var i in this.order) {
        out[this.order[i]] = inc[i];
    };
    out["name"] = this.mapping[out["name"]];
    out["time"] = parseFloat(out["time"]) / this.time_mult;
    out["time"] += this.start_time;
    return out;
};

Proto.prototype.pack = function(data) {
    return JSON.stringify(data);
};

Proto.prototype.toString = function(data) {
    return JSON.stringify(data);
};

Available currencies

The following table contains list of available currencies. In order to query our API you have to provide a currency pair which containts two of the available currencies (for example EURUSD).

Symbol Currency
AUD Austalian Dollar
BGN Bulgarian Lev
BRL Brazilian Real
CAD Canadian Dollar
CHF Swiss Franc
CNY Chinese Yuan
CZK Czech Koruna
DKK Danish Krone
EUR Euro
GBP Pound Sterling
HKD Hong Kong Dollar
HUF Hungarian Forint
ILS Israeli New Shekel
INR Indian Rupee
JPY Japanese Yen
MXN Mexican Peso
NOK Norwegian Krone
NZD New Zealand Dollar
PLN Polish Zloty
RON Romanian Leu
RUB Russian Ruble
SEK Swedish Krona
SGD Singapore Dollar
TRY Turkish Lira
UAH Ukrainian Hryvnia
USD United States Dollar
ZAR South African Rand