This a tutorial on how to get real time currency exchange rates directly from your Linux terminal (+ lots of screenshots).
Requirements:
-A computer ( *facepalm* 😛 )
-Any Linux/Windows machine with curl installed.
-Free account with openexchangerates.org
We will be using the “curl” utility to perform the API requests which usually comes pre-installed in most Linux systems.
In case, yours does not have it installed, you can install it using the following:
[You can run “apt install curl” for Ubuntu based systems, or “yum install curl” for RHEL/CentOS/Fedora based systems or “dnf install curl” for newer Fedora systems.]
Step 1: Sign up for a free account in openexchange. You can use the below link:
https://openexchangerates.org/signup/free
I would suggest to create an account with a new password that you have never used before.
[Note: The free account has restrictions but should be sufficient to get latest conversion rates with base currency set as USD. With the free account we cannot change the base currency. This means with the free account you can translate 1USD to any other currency. I will create a different tutorial describing another method to get ]
Step 2: Get your APP ID
-Once you sign up for the account, you would receive an email with a verification email which will have your “APP ID”. Below is a screenshot:
You would need to get this ID when performing the API call.
-Alternatively, once you have signed up you get your API key once you login to your account. Below is a screenshot:
Step 3: Get exchange rates:
-Open your terminal and run the following command:
curl -X GET https://openexchangerates.org/api/latest.json?app_id=enteryourAPIKEYhere
Enter your app ID after “=”. For example, if your APP ID is 1234, them you would run the following:
curl -X GET https://openexchangerates.org/api/latest.json?app_id=1234
Below is a sample output which displays the different currencies and its conversion values.
You would notice the output is in JSON format which has values in keypairs. (For example: the “currency name”: “value”.)
The data that is pulled is in realtime and it also displays the “timestamp” for which the currency converstions are in linux EPOC time.
Additional Information:
To know the current EPOC time in your system, you can command “date +%s” in your terminal. This is the number of seconds since 1970-01-01 00:00:00 UTC.
For simplicity, If you are looking to convert USD to a particular currency, you can simply grep the output with the currency you need to convert to.
For example: If you convert 1 USD to INR, you can simply grep the currency name to filter out the output.
curl -s -X GET https://openexchangerates.org/api/latest.json?app_id=1234 | grep INR
Below is a screenshot of the outputs.
Thats it folks! Hope this helps! If you liked this tutorial, leave a comment down below and follow to get future updates ! 🙂