As I’m penning this in early February of 2022, the crypto market (in addition to the inventory market) has been experiencing a reasonably tough decline. However earlier than that, after I started this undertaking, crypto noticed via a powerful bull run the place bitcoin reached an all-time excessive of $69,000 on November 10, 2021. Critical tasks with progressive expertise in addition to cash with the only real objective of meme potential (or “shitcoins” as lovingly referred to by the crypto sphere, reminiscent of my favourite — DogeBonk) have been thriving.
Whereas I make investments in severe tasks as properly, I actually take pleasure in buying and selling altcoins, particularly these on the Binance Good Chain (BSC). It is vitally clearly only a type of playing, but it surely’s pleasant to comply with the community-generated memes for shitcoins.
Nevertheless, one draw back I got here throughout is the power to trace your cash and present revenue. These aware of BSC tokens will know of BSCscan and poocoin.app
, however these websites have limitations within the relative ease of monitoring your transactions.
I made a decision to construct a dashboard desk that shall be robotically emailed to me every day and can present the stats I wish to see for my BSC tokens, and I plan on strolling via step-by-step how I achieved this.
You’ll first wish to head over to https://www.covalenthq.com/ and get an API key. Covalent generously presents a free API with tons of endpoints and supported blockchain networks, and I used Covalent’s API for a lot of the capabilities on this undertaking.
The very first thing we’ll wish to do is a pull an up to date snapshot of our pockets, utilizing the operate beneath.
“Deal with” refers back to the 42-digit handle of your pockets. Hidelist is solely a listing of crypto tickers (“ETH”, and so on.) that you simply don’t wish to present up within the outcomes of your pockets.
Typically instances rip-off tokens will attempt to add your pockets as a part of a rip-off — disguise these so that you don’t fear about them. Please additionally be aware that if utilizing a community apart from BSC, you’ll want a special quantity somewhat than ‘56’ within the API URL. Discuss with Covalent’s documentation for different community IDs.
Getting Pricing Information
With the pockets listing of dictionaries knowledge that was returned from the get_wallet()
operate, we now wish to get the newest, correct costs. Whereas the Covalent API offers value as an API endpoint, I discovered that the worth knowledge was lagging. I used PancakeSwap’s API as a substitute.
We will then modify our pockets listing with these up to date costs. I additionally generated a special listing to make use of later as a filter to take away any responses that gave a ‘0’ as the worth (tokens that have been eliminated or had a difficulty with the API gathering the information).
# Replace pockets costs
for i in pockets:
for j in current_prices:
if j['Name'] == i['Name']:
i['Price'] = j['Price']# Generate filter to take away '0' costs
zerodrop = []
for i in current_prices:
if float(i['Price']) == 0:
if i['Name'] != 'BNB':
zerodrop.append(i['Name'])
The subsequent factor we wish is the cumulative sum of all of our transactions for our shitcoins. This subsequent operate reads in our pockets knowledge from the prior operate and calculates the equal BNB worth of the tokens transacted multiplied by the USD worth of BNB on the time of transaction to get a greenback worth for the sum of all transactions for every of our tokens. This offers us a internet value in USD for every of the tokens in our pockets.
Nice! Now we will add this output to our pockets knowledge.
# Replace pockets listing of dicts with internet value worth
for i in pockets:
for j in netcost:
if j['Name'] == i['Name']:
i['Net Cost'] = j['Net Cost']
Within the Jupyter pocket book the place I ran this code, I then transformed that pockets response right into a dataframe, cleaned up some formatting, up to date the USD worth column, and generated a “P.c Acquire” column.
I additionally wished to incorporate some transferring averages — each one week and 6 weeks. Under I’ve included the code for the one-week transferring common:
The very last thing we have to do is generate the dashboard with this data and ship it to my electronic mail.
The 2 figures I began with so as to add to the dashboard to ship within the electronic mail are a distribution of funds, or how my BSC crypto pockets is break up amongst totally different cash, and a determine to indicate my share acquire/loss for every of the cash in my pockets.
There are many different visualizations that may very well be generated with the information I gathered from Covalent.
For instance, for those who saved the information returned from Covalent right into a SQL desk every day, you might then monitor your portfolio worth over time.
For now, we’ll persist with the dataframe desk and the 2 visualizations we generated within the final embedded code block.
For configuring the portfolio knowledge to be despatched to my electronic mail, I borrowed and modified some nice code I discovered in a Medium article by Dominik Polzer, discovered here.
I created a brand new Gmail account that shall be used solely to ship automated emails with Python (I used this identical account to ship in inventory notifications in one other article I wrote here). I’d advocate towards utilizing your major electronic mail account for this job.
After configuring the mail credentials, we then arrange the message to be despatched. On this case, I transformed the dataframe object and dashboard objects to HTML to make sure they present up accurately in an electronic mail.
Right here’s a screenshot of the e-mail despatched to my inbox:
To automate sending the emails every day, I transformed the .ipynb
file right into a .bat
file and arrange Activity Scheduler to run the duty as soon as a day. Try my article about automated in-stock notifications here for extra details about methods to arrange Activity Scheduler to run the script.