How to use Python to get live forex data using

Currency API allows developers to obtain real-time exchange rate data using a single currency API endpoint. The endpoint can be used to return exchange rate data for 300+ cryptocurrencies, commodities (Gold and Silver) as well as 1800+ forex currency pairs.

To use the you will have to first signup for an account and choose either of the two plans it offers; the Starter plan (with 7 days free trial) that costs $19 per month or the premium plan that costs $199 per month.

The main difference between the two plans is that the starter plan only allows for 10,000 API calls per month and does not return historical data while the premium plan allows for 100,000 API calls per month and also returns historical data.

The currency API supports a majority of programming languages including JavaScript, PHP, Python, PowerShell, cURL, C#, Go (Native), Ruby, Swift, NodeJs, and Java. In this article, we will concentrate on how to get live forex data using when programming using Python.

Using Python to get forex data using Currency

The first thing that you need to know is the API’s URL, which is:

Next is the access key, which is also referred to as the API authentication or token. It is used to authenticate that you have subscribed to one of the plans. You have to append it for you to be able to access the live data using the Below is an example of how to append the access key:

In the above example, you should replace the ‘ACCESS_TOKEN’ with the access key you were provided with when you sign up with

/markets is the endpoint.

If you want to get a list of all the available pairs in a specific market (cryptocurrency, commodity and forex), you should use the following:

In the above example, you should replace ‘MARKET_NAME’ with a specific market name like crypto, forex, or commodity.

However, to obtain the data of a single currency pair, you can query using the base currency or currency pair. Below is an example of the code line to use:


You should replace ‘ACCESS_TOKEN’ with your access key and ‘SYMBOL’ with the currency pair or base currency you want to query. If you use EURUSD as the ‘SYMBOL’ for example, you should get the following results:


“t” is the date and time of the query result, “tms” is the update timestamp, “s” is the currency pair, “b” is the bid price, “bd” is the bid price direction, “a” is the ask price, “ad” is the ask price direction and “p” is the currency precision (decimal points).

If you have subscribed for the premium plan, you can also query historical data using the following code line:

&offset=OFFSET // Optional (candles offset)
&scale=SCALE // Optional (e.g., 1, 60, 1D, 1W, 1M), default to 1D

When using Python, you can choose to use ‘import http.client’ or ‘import requests’ to write a code that gets live exchange rate data using the

Below is an example of a code using ‘import requests’:

import requests
tuper = ""
headers = {}
res = requests.request("GET", tuper, headers=headers, data=payload)

You should replace the ‘ACCESS_TOKEN’ with the access key.

Below is a code example of when using ‘import http.client’:

import http.client
duer = http.client.HTTPSConnection("")
response = duer.getresponse()
data =