Using Covalent’s API to generate an up-to-date dashboard

As I’m writing this in early February of 2022, the crypto market (as well as the stock market) has been experiencing a pretty rough decline. But before that, when I began this project, crypto saw through an impressive bull run where bitcoin reached an all-time high of $69,000 on November 10, 2021. Serious projects with innovative technology as well as coins with the sole purpose of meme potential ( or “shitcoins” as lovingly referred to by the crypto sphere, such as my favorite — DogeBonk) were thriving.
While I invest in serious projects as well, I really enjoy trading altcoins, namely those on the Binance Smart Chain (BSC). It is very clearly just a form of gambling, but it’s enjoyable to follow the community-generated memes for shitcoins.
However, one downside I came across is the ability to track your coins and current profit. Those familiar with BSC tokens will know of BSCscan and poocoin.app
but these sites have limitations in the relative ease of tracking your transactions.
I decided to build a dashboard table that will be automatically emailed to me daily and will provide the stats I want to see for my BSC tokens, and I plan on walking through step by step how I achieved this.
You’ll first want to head over to https://www.covalenthq.com/ and get an API key. Covalent generously offers a free API with tons of endpoints and supported blockchain networks, and I used Covalent’s API for most of the functions in this project.
The first thing we’ll want to do is a pull an updated snapshot of our wallet, using the function below.
“Address” refers to the 42-digit address of your wallet. Hidelist is simply a list of crypto tickers (“ETH”, etc.) that you don’t want to show up in the results of your wallet.
Often times scam tokens will try and add your wallet as part of a scam — hide these so you don’t worry about them. Please also note that if using a network other than BSC, you’ll need a different number rather than ’56’ in the API URL. Refer to Covalent’s documentation for other network IDs.
Getting Pricing Data
With the wallet list of dictionaries data that was returned from the get_wallet()
function, we now want to get the latest, accurate prices. While the Covalent API gives price as an API endpoint, I found that the price data was lagging. I used PancakeSwap’s API instead.
We can then modify our wallet list with these updated prices. I also generated a different list to use later as a filter to remove any responses that gave a ‘0’ as the price (tokens that were removed or had an issue with the API gathering the data).
# Update wallet prices
for i in wallet:
for j in current_prices:
if j['Name'] == i['Name']:
i['Price'] = j['Price']# Generate filter to remove '0' prices
zerodrop = []
for i in current_prices:
if float(i['Price']) == 0:
if i['Name'] != 'BNB':
zerodrop.append(i['Name'])
The next thing we want is the cumulative sum of all of our transactions for our shitcoins. This next function reads in our wallet data from the prior function and calculates the equivalent BNB value of the tokens transacted multiplied by the USD value of BNB at the time of transaction to get a dollar value for the sum of all transactions for each of our tokens . This gives us a net cost in USD for each of the tokens in our wallet.
Great! Now we can add this output to our wallet data.
# Update wallet list of dicts with net cost value
for i in wallet:
for j in netcost:
if j['Name'] == i['Name']:
i['Net Cost'] = j['Net Cost']
In the Jupyter notebook where I ran this code, I then converted that wallet response into a dataframe, cleaned up some formatting, updated the USD value column, and generated a “Percent Gain” column.
I also wanted to include some moving averages — both one week and six weeks. Below I’ve included the code for the one-week moving average:
The last thing we need to do is generate the dashboard with this information and send it to my email.
The two figures I started with to add to the dashboard to send in the email are a distribution of funds, or how my BSC crypto wallet is split amongst different coins, and a figure to show my percentage gain/loss for each of the coins in my wallet.
There are plenty of other visualizations that could be generated with the data I gathered from Covalent.
For example, if you saved the data returned from Covalent into a SQL table daily, you could then track your portfolio value over time.
For now, we’ll stick with the dataframe table and the two visualizations we generated in the last embedded code block.
For configuring the portfolio data to be sent to my email, I borrowed and modified some great code I found in a Medium article by Dominik Polzer, found here.
I created a new Gmail account that will be used to send automated emails with Python (I used this same account to send in stock notifications in another article I wrote here). I would recommend against using your main email account for this task.
After configuring the mail credentials, we then set up the message to be sent. In this case, I converted the dataframe object and dashboard objects to HTML to ensure they show up correctly in an email.
Here’s a screenshot of the email sent to my inbox:
To automate sending the emails daily, I converted the .ipynb
file into a .bat
file and set up Task Scheduler to run the task once a day. Check out my article about automated in-stock notifications here for more information about how to set up Task Scheduler to run the script.