Coding DIY part 5: Fetching Cryptocurrency Live Data With Python
Made with postermywall
Good day, friends. I hope you're doing great at your end. In today's coding DIY, I tried using Python to fetch cryptocurrency data from a public API. I have not used Python for a long time because I got so attached to JavaScript nowadays that almost all my activities are done with it.
I had a nice experience playing with Python today, and I was able to accomplish the task with just 15 lines of code. I used Python's Requests library to fetch cryptocurrency information from coincap API.
Coincap is very useful tool that covers real-time pricing data of over 1000 of the cryptocurrencies. Developers can easily track the various cryptocurrencies in their project with coincap because it covers real-time exchange data from different markets worldwide making it very accurate.
Now let's get started on how to fetch these data with just some few lines of python codes.
Step 1. Initializing the project in VS Code
I created a folder named Crypto info. Inside the folder, I created the coin.py file where I will be writing the code.
Step 2: Creating virtual environment
It is always advisable to create a virtual environment(venv) in your python projects as its a good way to manage python packages in your projects to avoid installing the packages globally which could cause issues like breaking system tools. I created and activated venv as seen below.
step 3: Installing the needed library
In this project i will be using only the requests library, that is what is used to fetch the data from coincap's api. It's installed as seen below
step 4: Writing the Code
Here, I first of all have to import the library. After importing, I can then use it to fetch the data from the API. I declared a variable named user_inputs, which prompts the user to enter the cryptocurrency to fetch information for.
I made another variable that uses the get function to get the data from the API. The code is shown below.
Step 5. Finally, the code is complete, and we can run it by opening the location of the project and typing python coin_info.py
. It will then ask the user to enter the cryptocurrency name, and the data will be displayed.
That was it for today. The task was accomplished with less stress using the requests Python library.
All screenshots used in this post are from my Laptop
I hope you found this useful. I am Abdul-Salam Issahaku, from Ghana. I am a student web developer and a blockchain enthusiast. I blog about technology, life and investments. You can follow me to be part of my Hive family. Thank you for your time.
Yay! 🤗
Your content has been boosted with Ecency Points, by @lifeof.abdul.
Use Ecency daily to boost your growth on platform!
Support Ecency
Vote for new Proposal
Delegate HP and earn more
You really make programming even more interesting, it's really fun coding
There is a lot of fun in coding. That is literally what I do for plesure. I'm glad you find it interesting too.
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!
Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).
You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.
Congratulations @lifeof.abdul! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)
Your next target is to reach 4000 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out our last posts: