Detailed examples for easy integration, examples include jQuery, Python, and PHP
We provide a JSON REST API with both live and historical currency exchange rates for over 40 currencies. Data is sourced from an aggregated feed of institutional providers, (not a broker feed), giving you reliable and up-to-date traded rates that are used by banks globally. We have systems in place to remove irregular prices, giving you the cleanest prices available. Our forex API powers applications and financial software in major financial institutions all around the world.
Authentication with API Key
API key can be accessed by signing up to the service. The API's data endpoints can be accessed using the api_key. To access the data, add your api_key to the URL endpoint: following is an example of an API call to access live data:
https://fxmarketapi.com/apilive
? api_key = api_key
Our forex API will respond with a JSON object. For more details see below.
{ "timestamp": 1541012848, "price": { "EURUSD": 1.1323, "GBPUSD": 1.2776, "USDJPY": 112.9855 } }
The forex API will return timestamp and price object containing requested currency pairs' exchange rates and timestamp
Field | Type | Description |
---|---|---|
timestamp | integer | UNIX time of the price in seconds |
price | JSON object | Contains all currency pair codes (string) and their respective exchange rates (float). |
A list of all the available currencies can be accessed through requesting the API or clicking the link stated here. To request data, add the currencies codes together to form a currency pair. For example, EURNOK can be requested by adding EUR and NOK together. In order to get the inverse of the same pair, simply reverse the quote to NOKEUR. To access JSON object containing all available currency codes verus USD, Simply append your api_key to the fxmarketapi apicurrencies endpoint:
https://fxmarketapi.com/apicurrenciesSign Up ?api_key=api_key
{ "currencies": { "USDAED": "United Arab Emirates Dirham", "USDARS": "Argentine Peso", "AUDUSD": "Australian Dollar", "USDBRL": "Brazilian Real", "BTCUSD": "Bitcoin", "USDCAD": "Canadian Dollar", "USDCHF": "Swiss Franc", "USDCLP": "Chilean Peso", "USDCNY": "Chinese Yuan", "USDCOP": "Colombian Peso", "USDCZK": "Czech Republic Koruna", "USDDKK": "Danish Krone", "EURUSD": "Euro", "GBPUSD": "British Pound Sterling", ... } }
Field | Type | Description |
---|---|---|
currencies | JSON Object | Returns all currency pair codes and thier names in a (string) format that are available through the API |
Our exchange rate API has six endpoints serving different format of currency rates. Below is a summary of these endpoints.
API Endpoints |
---|
https://fxmarketapi.com/apilive?&api_key=api_key |
https://fxmarketapi.com/apihistorical?date=YYYY-MM-DD-00:00&interval=hourly&api_key=api_key |
https://fxmarketapi.com/apiconvert?api_key=api_key&from=EUR&to=SEK&amount=100 |
https://fxmarketapi.com/apitimeseries?currency=EURUSD,GBPUSD&start_date=2018-07-02-00:00&end_date=2018-09-03-10:00&interval=daily&api_key=api_key |
https://fxmarketapi.com/apichange?currency=EURUSD,EURGBP&api_key=api_key |
https://fxmarketapi.com/apipandas?currency=EURUSD,GBPUSD&start_date=2018-07-02&end_date=2018-09-03&interval=hourly&api_key=api_key |
Our exchange rates API endpoints supports a number of error codes. Below is a summary of these error codes.
Error Codes | Description |
---|---|
202 | Requested currency code invalid or not in plan for Live and Convert Endpoints |
203 | Requested currency code invalid or not in plan for the Historical, Change, Timeseries and Pandas Endpoints |
301 | Invalid date type |
302 | Requested date is a weekend applicable to Historical, Change, Timeseries and Pandas Endpoints |
401 | Api_Key is invalid |
501 | Requestout of Range |
502 | Interval Parameters invalid |
our exchange rate API live endpoint provides a live currency exchange rates feed to the users.
https://fxmarketapi.com/apiliveSign Up ?api_key=api_key
Field | Type | Description |
---|---|---|
api_key | string | API Key. |
currency | string | [Optional] A comma-separated list of currencies; default is EURUSD, GBPUSD, and USDJPY |
{ "timestamp": 1541521247, "price": { "AUDUSD": 0.7225, "EURUSD": 1.1412, "GBPUSD": 1.3079, "USDJPY": 113.3845 } }
Field | Type | Description |
---|---|---|
timestamp | integer | Returns the exact date and time (UNIX) the exchange rates were collected. |
price | JSON object | Contains all currency pair codes (string) and their respective exchange rates (float). |
Our exchange rate API provides historical currency rates for the past 10 years
https://fxmarketapi.com/apihistoricalSign Up ?api_key=api_key &date=2018-05-02
Field | Type | Description |
---|---|---|
api_key | string | API Key. |
date | string | Provide a date for which historical currency rates are requested. yyyy-mm-dd. For hourly and minute interval use yyyy-mm-dd-HH:MM |
interval | string | Use daily, hourly and minute |
currency | string | [Optional] A comma-separated list of currencies; default is EURUSD, GBPUSD, and USDJPY |
{ "date": "2018-05-02", "price": { "EURUSD": 1.19509, "GBPUSD": 1.35748, "USDJPY": 109.8405 } }
Field | Type | Description |
---|---|---|
date | string | Returns the date for which historical currency rates were requested |
price | JSON object | Contains all currency pair codes (string) and their respective FX rates (float). |
The FXMarketAPI API's convert endpoint's provides a live currency conversion rates from one to other.
https://fxmarketapi.com/apiconvertSign Up ?api_key=api_key & from=EUR & to=SEK & amount=1000
Field | Type | Description |
---|---|---|
api_key | string | API Key. |
from | string | Three digit currency code (example EUR) of the base currency |
to | string | Three digit currency code (example SEK) of the quoted currency |
amount | string | Notional amount of the base currency to be converted |
{ "price": 10.2477, "timestamp": 1544112937, "total": 10247.7, "from":"EUR" "to":"SEK" }
Field | Type | Description |
---|---|---|
timestamp | integer | Returns the UTC date and time (UNIX) the exchange rates were collected. |
price | float | Exchange Rate Price. |
total | float | Total Converted Amount. |
from | string | Base Currency. |
to | string | Quoted Currency. |
Time series api endpoint provides historical rates (OHLC) for the currencies requested. It is recommended that you do not request more than one year of data at a time, or more than three currencies at a time. To request just close price just use &format = close (optional parameter). The maximum data allowed for hourly and minute interval is 2 months and one day respectively.
https://fxmarketapi.com/apitimeseriesSign Up ?api_key=api_key & currency=EURUSD,GBPUSD & start_date=2018-07-02 & end_date=2018-09-03 & format=ohlc
Field | Type | Description |
---|---|---|
api_key | string | API Key. |
start_date | string | Provide the start date of your timeseries in yyyy-mm-dd format. For hourly and minute interval use yyyy-mm-dd-HH:MM |
end_date | string | [Optional] Provide the end date of your timeseries in yyyy-mm-dd format. Default is current date. For hourly and minute interval use yyyy-mm-dd-HH:MM |
interval | string | Use daily, hourly and minute |
currency | string | [Optional] A comma-separated list of currencies; default is EURUSD, GBPUSD, and USDJPY . |
format | string | [Optional] Add "close" in the request to get single quote per period; default is OHLC. |
{ "start_date": "2018-07-02", "end_date": "2018-09-03", "price": { "2018-07-02": { "EURUSD": { "close": 1.1639, "high": 1.1692, "low": 1.1591, "open": 1.168 }, "GBPUSD": { "close": 1.3143, "high": 1.3212, "low": 1.3095, "open": 1.3194 } }, "2018-07-03": { "EURUSD": { "close": 1.1658, "high": 1.1673, "low": 1.162, "open": 1.1639 }, "GBPUSD": { "close": 1.3192, "high": 1.3208, "low": 1.3115, "open": 1.315 } }, ... } }
Field | Type | Description |
---|---|---|
start_date | string | Returns the start date of the timeseries for which exchange rates were requested |
end_date | string | Returns the end date of the timeseries for which exchange rates were requested |
price | JSON object | The price contains all OHLC exchange rates (float) for the currencies requested that are date stamped (string) in yyyy-mm-dd format. |
The change endpoint enables the user to request the calculated difference and percentage change for a given currency pair between two dates. The user will also be returned a start rate and an end rate for the date specified.
https://fxmarketapi.com/apichangeSign Up ?api_key=api_key & currency=EURUSD,GBPUSD & start_date=2018-07-02 & end_date=2018-09-03
Field | Type | Description |
---|---|---|
api_key | string | API Key. |
start_date | string | Provide the start date of your timeseries in yyyy-mm-dd format. |
end_date | string | [Optional] Provide the end date of your timeseries in yyyy-mm-dd format. Default is current date. |
currency | string | [Optional] A comma-separated list of currencies; default is EURUSD, GBPUSD, and USDJPY . |
{ "start_date": "2018-07-02", "end_date": "2018-09-03", "price": { "EURUSD": { "change": 0.0038, "end_rate": 1.1601, "pct_change": -0.3299, "start_rate": 1.16394 }, "GBPUSD": { "change": 0.0183, "end_rate": 1.296, "pct_change": -1.3909, "start_rate": 1.31428 } } }
Field | Type | Description |
---|---|---|
api_key | string | API Key. |
start_date | string | Provide the start date of your timeseries in yyyy-mm-dd format. |
end_date | string | [Optional] Provide the end date of your timeseries in yyyy-mm-dd format. Default is current date. |
price | JSON Object | The price object will contain sub-objects [currency] |
currency [start_rate] | float | Exchange rates at the open of the start_date. |
currency [end_rate] | float | Exchange rates at the close of the end_date. |
currency [change] | float | The difference between the currency's start_rate and end_rate. |
currency [pct_change] | float | The percentage change between the currency's start_rate and end_rate. |
Pandas api endpoint returns historical forex rates in a format that is easy to use in Jupyter Notebook/Python. If one currency is requested a dataframe is returned with OHLC data which is datetime indexed. If multiple currencies are requested dataframe is returned with close data for multiple currencies which are datetime indexed
This endpoint is very useful for python developers that want to use forex data
https://fxmarketapi.com/apipandasSign Up ?api_key=api_key & currency=EURUSD,GBPUSD & start_date=2018-07-02 & end_date=2018-09-03
import pandas as pd
df = pd.read_json("https://fxmarketapi.com/apipandas?api_key=api_key¤cy=EURUSD,GBPUSD&start_date=2018-07-02&end_date=2018-09-03")
Field | Type | Description |
---|---|---|
api_key | string | API Key. |
start_date | string | Provide the start date of your timeseries in yyyy-mm-dd format. For hourly and minute interval use yyyy-mm-dd-HH:MM |
end_date | string | [Optional] Provide the end date of your timeseries in yyyy-mm-dd format. Default is current date. For hourly and minute interval use yyyy-mm-dd-HH:MM |
interval | string | Use daily, hourly and minute |
currency | string | [Optional] A comma-separated list of currencies; default is EURUSD, GBPUSD, and USDJPY . |
EURUSD | GBPUSD | |
---|---|---|
2018-11-30 | 1.13190 | 1.27506 |
2018-12-03 | 1.13548 | 1.27239 |
2018-12-04 | 1.13432 | 1.27183 |
..... |
Below is an example for live exchange rates data using PHP (CURL):
?php
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_PORT => "443",
CURLOPT_URL => "https://fxmarketapi.com/apilive?currency=USDJPY,AUDUSD,GBPUSD,EURUSD&api_key=api_key",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Below is an example for live exchange rates endpoint using Python:
import requests
url = "https://fxmarketapi.com/apilive"
querystring = {"currency":"USDJPY","api_key":"api_key"}
response = requests.get(url, params=querystring)
print(response.json())
Below is an example for live currency rates endpoint using jQuery:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://fxmarketapi.com/apilive?currency=USDJPY,AUDUSD,GBPUSD,EURUSD&api_key=api_key",
"method": "GET",
"headers": {}
}
$.ajax(settings).done(function (response) {
console.log(response);
});