The Currency Exchange API allows developers to add real-time exchange rate information from 19 supported currencies into their software applications. Currency Exchange is a SOAP API that uses the Simple Object Access Protocol and XML to return values from input queries.
Sign up for a free RapidAPI account to use the API with code snippets, endpoint testing, and continual uptime monitoring facilities. The service is free to use through RapidAPI with an API key. Developers can utilize the Currency Exchange API to pull real-time values for exchange rates into their applications.
This tutorial will review the basic code snippets required for use with PHP, Python, Ruby, and JavaScript applications. RapidAPI supports 19 popular programming languages with code auto-generation facilities aimed at software developers.
1. About the Currency Exchange API Service
The Currency Exchange API is a service created by NTTSG Global in Singapore as a means to demonstrate the functionality of the Kong Konnect platform and to provide an easy-to-use system for retrieving dynamic currency exchange rate information. The Currency Exchange API returns a single value in plain text over XML that can be used to input dynamic text into websites and mobile applications. Developers can receive exchange rate quotes in US dollars, Euros, British Sterling, Yen, and other currencies.
In order to use the Currency Exchange API, programmers will need to build the dynamic values for the trading quotes into application displays with support for international monetary symbols. The API can be used to build tables of price displays with real-time values or to provide data for custom charts and graphs. Since the Currency Exchange API only returns the latest or current price for each Forex value, developers who seek to build charts from the service will need to use their own storage for historical data with timestamps. The API does not provide trading charts for international currencies that can be embedded as widgets in financial services applications or blogs.
2. What is the Currency Exchange API?
The Currency Exchange API returns live values with the latest market rates from Forex trading services. There is support for 19 different currencies. Developers submit the API query in their applications every time a page is loaded to return the current value. There are no default settings for the API variables. Developers must specify the target currency for exchange rates and the currency for the pricing reference on each API call.
The supported currencies using the “GET listquotes” API call with RapidAPI are:
- “SGD” – Singapore Dollar
- “MYR” – Malaysian Ringgit
- “EUR” – Euro [E.U.]
- “USD” – U.S. Dollar
- “AUD” – Australian Dollar
- “JPY” – Japanese Yen
- “CNH” – Chinese Yuan
- “HKD” – Hong Kong Dollar
- “CAD” – Canadian Dollar
- “INR” – Indian Rupee
- “DKK” – Danish Krone
- “GBP” – Great Britain Pound [Sterling]
- “RUB” – Russian Ruble
- “NZD” – New Zealand Dollar
- “MXN” – Mexican Peso
- “IDR” – Indonesian Rupiah
- “TWD” – Taiwanese Dollar
- “THB” – Thai Baht
- “VND” – Vietnamese Dong
The variables listed above can be used interchangeably in the Currency Exchange API to build whatever pair combination is required for your applications. Because the service only returns live market values, developers will need to build their own database storage for price values if they require historical data references for charts. In programming, the use of live prices for exchange rates across multiple base currencies is easy to script into websites, mobile applications, PWAs, etc. using the Currency API code snippets.
3. How does the Currency Exchange API work?
The Currency Exchange API is built through the Kong Konnect platform. After signing up for a RapidAPI account, developers can use an auto-generated API key to access the currency exchange service for the requirements of their software applications. Programmers can build tables and charts with exchange rates listed for 19 major world currencies. The latest market value will be retrieved on each page load for websites and mobile applications that require dynamic content. Publishers can build with Node.js or Ajax for streaming Forex quotes.
A common example would be where the developer requires the current market rates for the Euro exchange rate listed in U.S. dollars. There are easy options to use the Currency Exchange API to retrieve the latest market prices for any of the 19 currencies. Each of the supported currencies can also be used as a price base. In this manner, international developers can price exchange rates in their local currency or implement geolocation detection for dynamic user displays in a web browser. Developers can also use Cron to retrieve values at fixed times for historical chart references.
The Currency Exchange API is based on SOAP standards and returns prices in plain text over XML. The service operates with 100% uptime and an average latency of 460 ms on the RapidAPI platform. The main API command is the “GET exchange” call which is used to specify the currencies for the exchange rates. Developers will need to include both their RapidAPI key and the two variables for the currency pair in each API call.
4. Who is the Currency Exchange API for exactly?
The Currency Exchange API is designed for programmers that need a quick and easy way to insert dynamic values for exchange rates into their web pages and mobile applications. The service is best suited for software requirements that need a current market rate for Forex values displayed on a static page that is refreshed with every reload. The Currency Exchange API does not support charts with historical data.
Developers building with open source CMS scripts can use PHP snippets below to call the Currency Exchange API to create custom display pages or insert tables of currency exchange rates into their applications. Web publishers can use the PHP code to add support for the Currency Exchange API to WordPress, Drupal, or Joomla pages. Python developers working with Django, Flask, or other app frameworks can add the API script to their code easily with snippets. Developers will need to add the appropriate currency symbols for each value, as the API only returns the numeric prices in plain text.
The Currency Exchange API is intended for software developers who prefer to use a free service through RapidAPI. The RapidAPI interface guarantees a standard level of functionality over time that is ideal for small business requirements, startup companies, and independent publishers. Experienced developers may be able to use the API queries with their own database storage for historical value references. The Currency Exchange API provides real-time exchange rates that are validated at the time of each page load individually.
5. Tutorial: How to Connect to the Currency Exchange API
To connect to the Currency Exchange API and import live exchange rate values to a website or mobile application, first sign in to RapidAPI and navigate to the resource page. Under the “Endpoints” tab, the API Playground contains a reference table with a drop-down menu listing all of the supported programming languages. The Currency Exchange API has code snippets available for 19 of the most popular programming languages for software development, including PHP, Python, Ruby, & JavaScript.
PHP Code Snippets:
For PHP applications and websites, there are four different methods that the code can be input into a web page. Developers can use cUrl, HTTP, or Unirest request.
To embed the Currency Exchange API with cUrl in PHP for the currency pair USD-to-EUR:
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://currency-exchange.p.rapidapi.com/exchange?to=USD&from=EUR&q=1.0", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: currency-exchange.p.rapidapi.com", "x-rapidapi-key: insert-your-unique-rapidapi-key-here" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
To embed the Currency Exchange API with an HTTP request in PHP:
<?php $request = new HttpRequest(); $request->setUrl('https://currency-exchange.p.rapidapi.com/exchange'); $request->setMethod(HTTP_METH_GET); $request->setQueryData([ 'to' => 'USD', 'from' => 'EUR', 'q' => '1.0' ]); $request->setHeaders([ 'x-rapidapi-key' => 'insert-your-unique-rapidapi-key-here', 'x-rapidapi-host' => 'currency-exchange.p.rapidapi.com' ]); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; }
Use an alternative HTTP method with the Currency Exchange API in PHP:
<?php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://currency-exchange.p.rapidapi.com/exchange'); $request->setRequestMethod('GET'); $request->setQuery(new http\QueryString([ 'to' => 'USD', 'from' => 'EUR', 'q' => '1.0' ])); $request->setHeaders([ 'x-rapidapi-key' => 'insert-your-unique-rapidapi-key-here', 'x-rapidapi-host' => 'currency-exchange.p.rapidapi.com' ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
Add the Currency Exchange API to your PHP code with a Unirest request:
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://currency-exchange.p.rapidapi.com/exchange?to=USD&from=EUR&q=1.0", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: currency-exchange.p.rapidapi.com", "x-rapidapi-key: insert-your-unique-rapidapi-key-here" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
There is no difference in the endpoint construction no matter which code snippet is used. Make sure to replace the placeholder text with your custom API key from RapidAPI in order for the request to process. This is automated in the API Playground.
Python Code Snippets:
For Python applications and websites, there are three different methods that the Currency Exchange API code can be input into web pages and mobile applications. Developers can use the HTTP client, an import request, or a Unirest command to embed the functionality in any required display page.
To embed the Currency Exchange API with the HTTP Client in Python:
import http.client conn = http.client.HTTPSConnection("currency-exchange.p.rapidapi.com") headers = { 'x-rapidapi-key': "insert-your-unique-rapidapi-key-here", 'x-rapidapi-host': "currency-exchange.p.rapidapi.com" } conn.request("GET", "/exchange?to=USD&from=EUR&q=1.0", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
To add the Currency Exchange API with a Python import request:
import requests url = "https://currency-exchange.p.rapidapi.com/exchange" querystring = {"to":"USD","from":"EUR","q":"1.0"} headers = { 'x-rapidapi-key': "insert-your-unique-rapidapi-key-here", 'x-rapidapi-host': "currency-exchange.p.rapidapi.com" } response = requests.request("GET", url, headers=headers, params=querystring) print(response.text)
To embed the Currency Exchange API with a Unirest command in Python:
import http.client conn = http.client.HTTPSConnection("currency-exchange.p.rapidapi.com") headers = { 'x-rapidapi-key': "insert-your-unique-rapidapi-key-here", 'x-rapidapi-host': "currency-exchange.p.rapidapi.com" } conn.request("GET", "/exchange?to=USD&from=EUR&q=1.0", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
Make sure to replace the placeholder text with your custom API key from RapidAPI.
Ruby Code Snippets:
For Ruby applications and websites, there are two different methods that the Currency Exchange API code can be input into a web page or mobile application. Developers can use a net::HTTP request or a Unirest command to retrieve the latest market rates.
To embed the Currency Exchange API with a net::HTTP request in Ruby:
require 'uri' require 'net/http' require 'openssl' url = URI("https://currency-exchange.p.rapidapi.com/exchange?to=USD&from=EUR&q=1.0") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'insert-your-unique-rapidapi-key-here' request["x-rapidapi-host"] = 'currency-exchange.p.rapidapi.com' response = http.request(request) puts response.read_body
To embed the Currency Exchange Calculator API with a Unirest command in Ruby:
require 'uri' require 'net/http' require 'openssl' url = URI("https://currency-exchange.p.rapidapi.com/exchange?to=USD&from=EUR&q=1.0") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'insert-your-unique-rapidapi-key-here' request["x-rapidapi-host"] = 'currency-exchange.p.rapidapi.com' response = http.request(request) puts response.read_body
Make sure to replace the placeholder text with your custom API key from RapidAPI.
JavaScript Code Snippets:
For JavaScript applications and websites, there are four different methods that the code can be input into a web page or mobile application. Developers can use jQuery, fetch, an XML HTTP request, or Axios to build displays for exchange rates in the application.
To embed the Currency Exchange API with jQuery in JavaScript:
const settings = { "async": true, "crossDomain": true, "url": "https://currency-exchange.p.rapidapi.com/exchange?to=USD&from=EUR&q=1.0", "method": "GET", "headers": { "x-rapidapi-key": "insert-your-unique-rapidapi-key-here", "x-rapidapi-host": "currency-exchange.p.rapidapi.com" } }; $.ajax(settings).done(function (response) { console.log(response); });
To insert the Currency Exchange API with fetch in JavaScript:
fetch("https://currency-exchange.p.rapidapi.com/exchange?to=USD&from=EUR&q=1.0", { "method": "GET", "headers": { "x-rapidapi-key": "insert-your-unique-rapidapi-key-here", "x-rapidapi-host": "currency-exchange.p.rapidapi.com" } }) .then(response => { console.log(response); }) .catch(err => { console.error(err); });
To add the Currency Exchange API with an XML HTTP request in JavaScript:
const data = null; const xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { console.log(this.responseText); } }); xhr.open("GET", "https://currency-exchange.p.rapidapi.com/exchange?to=USD&from=EUR&q=1.0"); xhr.setRequestHeader("x-rapidapi-key", "insert-your-unique-rapidapi-key-here"); xhr.setRequestHeader("x-rapidapi-host", "currency-exchange.p.rapidapi.com"); xhr.send(data);
To use the Currency Exchange API with Axios in JavaScript:
import axios from "axios"; const options = { method: 'GET', url: 'https://currency-exchange.p.rapidapi.com/exchange', params: {to: 'USD', from: 'EUR', q: '1.0'}, headers: { 'x-rapidapi-key': 'insert-your-unique-rapidapi-key-here', 'x-rapidapi-host': 'currency-exchange.p.rapidapi.com' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); });
Make sure to replace the placeholder text with your custom API key from RapidAPI.
6. Endpoints of the Currency Exchange API
The reference endpoint for the Currency Exchange API is related to the “GET listquotes” command. By using the following PHP code or the functionally equivalent snippet from the API Playground in Python, Ruby, JavaScript, etc.:
<?php $request = new HttpRequest(); $request->setUrl('https://currency-exchange.p.rapidapi.com/listquotes'); $request->setMethod(HTTP_METH_GET); $request->setHeaders([ 'x-rapidapi-key' => 'insert-your-unique-rapidapi-key-here', 'x-rapidapi-host' => 'currency-exchange.p.rapidapi.com' ]); try { $response = $request->send(); echo $response->getBody(); } catch (HttpException $ex) { echo $ex; }
The Currency Exchange API will return the list of supported currency codes:
["SGD","MYR","EUR","USD","AUD","JPY","CNH","HKD","CAD","INR","DKK","GBP","RUB","NZD","MXN","IDR","TWD","THB","VND"]
Developers can use the values for the various currencies to create over 340 different endpoints for exchange rate values. The RapidAPI service hosts the code snippets for 19 different programming languages, where the endpoint for each request is the same.
To implement the endpoint for specific currency pairs, use the variables above with the code from the tutorial section. For example, the endpoint for the U.S. dollar to Euro exchange rate using the “GET exchange” command is:
0.822155
The endpoint for the Euro to U.S. dollar exchange rate using the “GET exchange” command is:
1.215902
In each instance, the value returned by XML from the SOAP API is in plain text. Developers will need to add the appropriate monetary symbols ($/€) and any required CSS styling using div, span, or paragraph statements in their application code.
Use the following monetary symbols in the application code to support currency values:
- Singapore Dollar – $
- Malaysian Ringgit – RM
- Euro [E.U.] – €
- U.S. Dollar – $
- Australian Dollar – $
- Japanese Yen – ¥
- Chinese Yuan – ¥
- Hong Kong Dollar – $
- Canadian Dollar – $
- Indian Rupee – ₹
- Danish Krone – kr
- Great Britain Pound [Sterling] – £
- Russian Ruble – р
- New Zealand Dollar – $
- Mexican Peso – $
- Indonesian Rupiah – Rp
- Taiwanese Dollar – $
- Thai Baht – ฿
- Vietnamese Dong – ₫
The Currency Exchange API does not return the monetary symbol with the “GET exchange” command, so developers will need to add it to the display of their code.
7. Alternatives to the Currency Exchange API
There are many API services that offer exchange rates and Forex trading information. Some of the most popular currency exchange API services in the marketplace are:
- Exchange Rate API: Supports the conversion of 160 currencies for exchange rate trading applications. – https://www.exchangerate-api.com/
- Currency Converter API: Real-time information on 150 currencies with 100 requests per minute. – https://rapidapi.com/natkapral/api/currency-converter5
- Currency Layer API: A REST API with trading data on 168 currencies and precious metal prices. – https://english.api.rakuten.net/apilayer/api/currencylayer
- Free Currency Converter API: Includes 8 days of historical information with 60 minute update times. – https://free.currencyconverterapi.com/
- Exchange Rates API: High volume API service that scales to enterprise web traffic levels with a focus on delivery speed. – https://exchangeratesapi.io/
- XE Currency Data API: Paid subscription plans with SDK for programmers and 7 day free trial. – https://www.xe.com/xecurrencydata/
- OANDA REST-v20 API: Access OANDA’s fxTrade platform and next-generation v20 trading engine. – https://developer.oanda.com/rest-live-v20/introduction/
Programming teams with a high volume of user requests in support of applications will need to subscribe to a paid API service. Most free plans only support up to 100 user requests per minute. Make sure the service supports the required currency pairs and distinguish between service providers on the inclusion of historical information with charts. The latency of API services can slow down your application runtime speeds.
8. What are the benefits of the Currency Exchange API?
The Currency Exchange API provides real-time financial information for exchange rates that can be used to build custom website displays and mobile applications. Some of the recognized user benefits of the Currency Exchange API service are:
- Developers can list current exchange rates in tables or embed individual values in web pages for dynamic user displays based on geolocation data.
- Travel websites can keep up-to-date information on different currencies on their app pages to support clients with custom destination content.
- Programmers can use the values returned from API calls to display chart information that is useful to Forex traders.
- API results can be stored in a database or spreadsheet for historical price references and technical analysis.
The main advantages of the Currency Exchange API are that exchange rate values update quickly with accurate results and that the service is free to use in any type of commercial or non-commercial application without restriction. The price of similar services can cost thousands of dollars per year depending on the scale of requests from user pages. The limitation of 100 API calls per minute is sufficient for most of the software application requirements from independent developers & small businesses.
The uptime of the Currency Exchange API service is 100% on RapidAPI, with low latency that will support apps coded in most of the popular web and mobile programming languages. It is easy to use the code snippets provided by RapidAPI to quickly insert real-time information on exchange rates into application display pages.
9. Developer Resources for the Currency Exchange API
For more information on using the Currency Exchange API to build custom software applications, please reference the following articles:
- LastCall: “Top 10 Best Currency Converter APIs [34+ APIs Reviewed]” (2021): https://rapidapi.com/blog/currency-converter-api/
- RapidAPI: “Top Currency Converter and Exchange APIs” (2021): https://rapidapi.com/collection/currency-converter-exchange-api
- Yasunaka Cho: “Top 10 Currency and Forex APIs: OANDA, XE, and Currencylayer” (2019):
https://medium.com/@yasunaka.cho.rakuten/top-10-currency-and-forex-apis-oanda-xe-and-currencylayer-9914c830d4b2
To learn more about SOAP APIs, the resources listed below are recommended:
- API 101: What Is a SOAP API?
- What is SOAP: Formats, Protocols, Message Structure, and How SOAP is Different from REST:
- SOAP API Developer Guide:
- SOAP vs REST 101: Understand The Differences:
Although it is not required to understand all of the details behind SOAP API design to use the Currency Exchange service, it is helpful for developer reference.
10. Summary: Dynamic Exchange Rate Information
The Currency Exchange API is easy for programmers to implement in website and mobile application development with code snippets for PHP, Python, Ruby, JavaScript, and other languages available at RapidAPI. Use the code to embed exchange rate information for 19 currencies with the free service that supports up to 100 user requests per minute. The Currency Exchange API has low latency and a 100% uptime score. Look at the other API services if your project requires a higher volume of requests or support for historical information in chart displays.
The Currency Exchange API is recommended for financial applications, Forex trading, travel websites, and stock market blog publications. Developers can use geolocation information from the web browser to further customize results for local users. SOAP APIs are reliable for platform automation and are a popular solution to provide dynamic results with real-time trading information in Forex applications. Make sure to style the XML data with CSS and the proper currency symbols to match the design of your website or branded mobile app. Best practice is to build demo apps and MVPs using the Currency Exchange API, then upgrade to a paid subscription service for Forex trading data to support higher rates of web traffic in production if required by demand.
Leave a Reply