getting currency exchange rates in Linux terminal

How to get real time currency exchange rates in your Linux terminal

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:

APP ID for currency conversion

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:

API ID / API key from account to be used for getting currency exchange rates

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.

currency exchange rates in Linux terminal using API

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.

Output for filtered currency rates in Linux terminal. USD to INR and USD CAD currency exchange rates example outputs.

 

Thats it folks! Hope this helps! If you liked this tutorial, leave a comment down below and follow to get future updates ! 🙂

6 thoughts on “How to get real time currency exchange rates in your Linux terminal”

  1. try piping into jq for the exact data.

    curl -s -X GET https://openexchangerates.org/api/latest.json\?app_id\=5bf21772d6ee4577ad43f07326fc864a | jq -r ‘.rates.INR’

    will just return the number

    curl -s -X GET https://openexchangerates.org/api/latest.json\?app_id\=5bf21772d6ee4577ad43f07326fc864a | jq -r ‘.rates.INR * 250’

    will return USD 250 in INR and

    curl -s -X GET https://openexchangerates.org/api/latest.json\?app_id\=5bf21772d6ee4577ad43f07326fc864a | jq -r ‘300000 / .rates.INR’

    will return INR 3Lakh in USD

    1. @Balamurugan, Thanks a ton for posting it. Till now, I was using awk + cut to pull the value alone: ( the very long way)

      curl -s https://openexchangerates.org/api/latest.json?app_id=appIDhere | grep INR | awk ‘{print $2}’ | cut -d”,” -f1

      But the jq one looks like a neat one liner.I am never messed with jq(newbie here when in comes in jq). I just started learning jq a week back and came across your post. I will be testing this one out shortly.

      Thanks a ton for stopping by.

  2. Thanks for the post. Had been using GnuCash which uses a perl module and works, but for various reasons now setting up Ledger-CLI and was looking for a command line tool like this. By creating a bash alias, I just have to type, e.g.,
    forex | grep KES
    to get the rate for Kenya shillings which is helpful over here in Nairobi!

  3. Just adding my thanks to Balmurugan as I didn’t study it at first.
    I installed jq and can now use it with my KES quotes.

  4. Install:$ sudo apt-get install qalc
    then inter:$ qlac
    after that you can exchange any currencyfor example/
    type: 50 USD to EUR

    * The currency simple must be in capital litter.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.