Enroll Course

100% Online Study
Web & Video Lectures
Earn Diploma Certificate
Access to Job Openings
Access to CV Builder



Online Certification Courses

How To Check Any Cryptocurrency Price From Your Linux Terminal

How to Check Any Cryptocurrency Price From Your Linux Terminal. 

Checking Cryptocurrencies Prices From Your Terminal

If you are trying to get the latest prices of cryptocurrencies from your Linux terminal, then by following this simple tutorial, you can be up and running in a matter of minutes.

This simple project makes use of an application programming interface (API) to pull the latest crypto prices. For this tutorial, you will use the API that is provided by CoinMarketCap. While it is free to use, you would need to first register on the site.

While this project does not assume that you are a rockstar coder, it is a technical tutorial. I would guide you every step of the way, but I recommend that you are at least interested in the technical side of things.

1. Register with the CoinMarketCap Developer Portal

As mentioned above, you would need a free account to access CoinMarketCap’s data. While CoinMarketCap does charge for API access, the free tier provides basic information and 10,000 requests per month. To max this out, you’d need to access the price every five minutes for an entire month!

Start by visiting the CoinMarketCap API signup page and filling in your information. You only need to provide your name, email address, and create a password. Make sure you select the Basic plan, which is free.

Once registered, confirm your email address by clicking the button in the email you should have received from CoinMarketCap. You’ll then have access to the CoinMarketCap API dashboard, which shows you statistics about your account. You can see your API key, most recent requests, and the total remaining credits, which get used up when making requests.

Copy Your Access Key

Your access key is like a password. With this key, CoinMarketCap knows who you are. They use this to limit how many times you can access the API. This helps protect CoinMarketCap’s resources from abuse and is an industry-standard way of securing an API. Suffice to say, plenty of people are often looking to steal API keys to use for their own purposes. Treat your API key like a password.

2. Basic Command-Line Usage

Now that you have an account and an API key, open up your terminal. Here’s the code you need to get started with the Bitcoin price but don’t run it yet:

curl -H "X-CMC_PRO_API_KEY: "YOUR_KEY_HERE" -H "Accept: application/json" -d "symbol=BTC" -G https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest

So, to run this, replace “YOUR_KEY_HERE” with your API key from the previous step. Paste this into your terminal and press return. You’ll see a lot of data come back, including the current Bitcoin price, number of trading pairs, and much more. Let’s explore that command.

The word “curl” (spelled cURL) stands for “client URL”. It’s a software tool to perform web-based commands, a bit like a virtual web browser. It’s a very popular tool for this kind of task.

Everything that follows “curl” are the options for your command. These tell cURL what API to use, what API key to use, and various other options.

The -H option configures the request headers. Headers are a secure way of sending extra data with the request, sent as key-value pairs. In this instance, the header key is “CMC_PRO_API_KEY“, and the value of this is “YOUR_KEY_HERE“, or your real API key. This is how CoinMarketCap knows who you are. It’s the preferred way of sharing your API key.

Next is another header, configured with the -H flag. This looks like “Accept: application/json“. It tells CoinMarketCap how to return the data JSON in this case.

The -d option sends our request data to CoinMarketCap. This is where you can specify what cryptocurrency you want to see. The value of “symbol=BTC” tells CoinMarketCap to send the data it has for Bitcoin. You can pass in a comma-separated list of all the cryptocurrencies you’d like to see like this: “symbol=BTC,ETH,XRP“.

Finally, the -G option configures cURL to perform a GET request instead of a POST request. This is like loading a webpage and putting all your options in the URL bar, instead of pressing a button to make your Amazon order (where the website shares your data without changing the URL). It sends this to “https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest“, which is the CoinMarketCap URL which returns the basic information you need

Reading the Response Data

This API response is in the JSON format. This is a machine-readable format, comprising of keys and values, like your headers above.

To keep things simple, the current Bitcoin price lives nested inside the data section, under BTC -> quote -> USD.

While parsing this data and extracting specific information is a bigger task than this article allows time for, that’s possible with a little programming knowledge.

Troubleshooting

If this won’t work for you, you may need to perform some basic troubleshooting or “debugging” steps. The first place to look is your API key have you swapped out “YOUR_KEY_HERE” for your API key from step one?

Next, the CoinMarketCap response provides useful information alongside your data. If you make a bad request, your data will contain a status code, error, and message. This may explain the problem, but often the biggest hint here is the status code.

 

Corporate Training for Business Growth and Schools