# Introduction

Currency API is fast and friendly crypto, commodity, and FX Currency Conversion JSON API, covering over 1200+ pairs.

# Requirements

We've made it easy to be up and running. All you need to do is to visit "My Account" and locate your token. If you don't have one yet, please subscribe and get one immediately.

# Getting Started

Get ready to connect to Currency API using few coding lines of your favorite programming language.

# Definitions

DefinitionDescription
API URLThe URL which all API request endpoints and URLs are based on.
TokenThe access key assigned to your account and used to authenticate with the API.
SymbolThe three-letter currency code or currency pair (e.g., EUR, EURUSD).
Base CurrencyThe currency to which exchange rates are relative to. (If 1 USD = X EUR, USD is the base currency)
Target CurrencyThe currency an amount is converted to. (If 1 USD = X EUR, EUR is the target currency)
Timestamp formatAll timestamps are unix/epoch timestamps (seconds that have passed since since January 1, 1970 UTC).

# API URL

The Currency API comes with a single endpoint that enables you to query one or many currency codes or pairs, with readable parameters. Depending on your subscription plan, the endpoint will return real-time exchange rate data.

https://api.currencyapi.io/

# Authentication (Token)

Your API token is a unique access key passed into the API URL's token parameter to authenticate with the Currency API. The following is an example of how to append the access token for authentication:

https://api.currencyapi.io/markets
    ?token=ACCESS_TOKEN

# Available symbols (Pairs)

To get the complete list of a specific market (e.g., Forex, Crypto, etc.) available symbols/pairs, use the following endpoint. Replace the MARKET_NAME with the targeted market (crypto or forex)

https://api.currencyapi.io/markets
    ?token=ACCESS_TOKEN
    &market=MARKET_NAME

# Tick data API

/markets endpoint provides you the ability to query a base currency (e.g., EUR) or currency pair (e.g.,EURUSD).

# Query with base curency or pair

# Search symbol/s
GET https://api.currencyapi.io/markets
    ?token=ACCESS_TOKEN
    &search=SYMBOL

Response

[
 {
  "t":"2021-04-15T03:53:00.593Z",
  "tms":"1618458780086",
  "s":"EURUSD",
  "b":1.19864,
  "bd":0,
  "a":1.19867,
  "ad":1,
  "p":5
 }
]
# Get exact symbol/s
GET https://api.currencyapi.io/markets
    ?token=ACCESS_TOKEN
    &symbol=SYMBOL

Response

{
  "t":"2021-04-15T03:53:00.593Z",
  "tms":"1618458780086",
  "s":"EURUSD",
  "b":1.19864,
  "bd":0,
  "a":1.19867,
  "ad":1,
  "p":5
}
# Symbol Response JSON Structure
KeyDescription
tThe last update date/time of query result.
tmsThe last update timestamp of query result.
sThe currency pair.
bThe bid price. It is also referring to the highest price a buyer will pay for a currency.
bdThe bid price direction. It is also referring to the color code of the displayed bid price (e.g., red/green).
aThe ask price. It is also referring to the lowest price a seller will accept for a currency.
adThe ask price direction. It is also referring to the color code of the displayed ask price (e.g., red/green).
pThe Currency precision

# Historical data API

You can get the historical data of any of the available symbols by adding the historical parameter.

Response

[
  [
    1620604800,
    58336.16,
    59603,
    57399.33,
    57960
  ],
  ...
]
GET https://api.currencyapi.io/markets
    ?token=ACCESS_TOKEN
    &symbol=SYMBOL
    &historical=true
    &offset=OFFSET // Optional (candles offset)
    &scale=SCALE // Optional (e.g., 1, 60, 1D, 1W, 1M), default to 1D
# Historical Data Response JSON Structure
indexDescription
0Timestamp.
1Open.
2High.
3Low.
4Close.

# Code Examples

Currency API supports your favorite programming languages. Here are few examples of how to connect and start getting real-time quotes:

# JavaScript

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch(
 "https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL",
 requestOptions
 )
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
1
2
3
4
5
6
7
8
9
10
11
12
var settings = {
  "url": "https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL",
  "method": "GET",
  "timeout": 0,
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
1
2
3
4
5
6
7
8
9
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

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

xhr.open("GET", "https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL");

xhr.send();
1
2
3
4
5
6
7
8
9
10
11
12

# PHP

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

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

xhr.open(
 "GET",
 "https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL"
);

xhr.send();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl(
 'https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL'
);
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl(
 'https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL'
);
$request->setRequestMethod('GET');
$request->setOptions(array());

$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
1
2
3
4
5
6
7
8
9
10
11
12

# Python

import http.client

conn = http.client.HTTPSConnection("api.currencyapi.io")
conn.request(
 "GET",
 "/markets?token=ACCESS_TOKEN&symbol=SYMBOL",
)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
1
2
3
4
5
6
7
8
9
10
import requests

url = "https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL"

payload={}
headers = {}

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

print(response.text)
1
2
3
4
5
6
7
8
9
10

# PowerShell

$response = Invoke-RestMethod 'https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
1
2

# cURL

curl --location --request GET 'https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL'

# C#

var client = new RestClient("https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
1
2
3
4
5

# Go (Native)

package main

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

func main() {

  url := "https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL"
  method := "GET"

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

  if err != nil {
    fmt.Println(err)
    return
  }
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# Ruby

require "uri"
require "net/http"

url = URI("https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true

request = Net::HTTP::Get.new(url)

response = https.request(request)
puts response.read_body
1
2
3
4
5
6
7
8
9
10
11
12

# Swift

import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

var semaphore = DispatchSemaphore (value: 0)

var request = URLRequest(url: URL(
 string: "https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL")!,
 timeoutInterval: Double.infinity
)
request.httpMethod = "GET"

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
  guard let data = data else {
    print(String(describing: error))
    semaphore.signal()
    return
  }
  print(String(data: data, encoding: .utf8)!)
  semaphore.signal()
}

task.resume()
semaphore.wait()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

# NodeJs

var axios = require('axios');

var config = {
  method: 'get',
  url: 'https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL',
  headers: { }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL',
  'headers': {
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

1
2
3
4
5
6
7
8
9
10
11
12

# Java

OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
Request request = new Request.Builder()
  .url("https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL")
  .method("GET", null)
  .build();
Response response = client.newCall(request).execute();
1
2
3
4
5
6
7
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.get("https://api.currencyapi.io/markets?token=ACCESS_TOKEN&symbol=SYMBOL")
  .asString();
1
2
3
Last Updated: 5/10/2021, 2:17:24 PM