Why would you ever manually check cryptocurrency prices again if you could write a programm to automatically fetch all prices from Coinmarketcap and output them in your Terminal?
I wouldn´t either so let´s start. We need some really basic prerequisites.
- Python 3.6
- editor of choice
Setting up your Enviroment
I assume you already have a basic understanding how Python works but actually you should still follow along pretty easily since the syntax is not that hard.
Before we can start hacking our code we need to check coinmarketcap html structure to see where and how to information is titled and stored.
Luckily for us, coinmarketcap contains a API here which automatically provided us with a nicely formated Json file.
Writing the code
Now we can start hacking...
Fire up your favourite Texteditor or IDE and start importing the first and only module request by typing:
specify your url like:
url = https://api.coinmarketcap.com/v1/ticker/?convert=EUR&Limit=10
using the request libary we can make use of the
function which will provide us with a list. Let´s wrap this in some code!
for coin in requests.get(url).json(): print(coin['name], coin['price_usd’])
that was basically it! Pretty easy right?
Actually this program was never intendented as a standalone version rather as a libary to use in a Telegram Chatbot or to automatic monitor the cryptocurrency prices.