Building Binance reserves tracking bot. (Part 2)
What if you could see the Binance account reserves for each cryptocurrency? Analytics claim that a substantial increase in these numbers correlates with future margin calls, so it can be a mechanism to jump out of a train faster than it gets to full speed.
A few weeks ago, I decided to try and do just that and start with Ethereum. Using nothing but the public data API and some simple Python code, I created a viz that displays the total USD value of Ethereum reserves held by Binance.
I have just released a new course on Udemy called “Practical Web Scraping Course”. It contains video tutorials packed with coding tips for web scraping that would help you build your data-based apps in no time. You can find code and ideas from this article and my other tutorials there in a convenient visual format.
In the previous part, I have covered the steps of creating a data retrieval script, how to host it and schedule its execution on an hourly basis. Take the time to read it as well to understand the general data flow better:
This article will show you the tools and approach to visualize the raw data.
Data
Unlike the approach I took in the first part, I’ve opted to use ORM — object relations mapping tool this time. It’s called Peewee and it seems both intuitive and powerful enough for quick POC’s.
I’ve compiled a quick flask proxy app that would serve me my data from PostgreSQL database. Here’s the codebase for it:
As you can see, my flask app has one route called “/records” that goes to the database and pulls records according to the model defined on line 23. I do some math just to make the results look nice and then return them in JSON format.
This method’s not really fail-proof as I wanted to show an overview of a solution rather than provide a working product. For production usage you would also need:
- Add caching for results of endpoints;
- Add validation for parameters of API;
- Add some try/except logic to make sure that every scenario is handled;
FrontEnd
For my quick iterations on pet projects, I’m using stack “Heroku <- Docker <- React + Flask” quite often as all those technologies are well-known to me and give lots of prebuilt options. For the representation of financial data I’ve found a convenient react-chartjs-2 library and built a simple React app to serve Binance accounts reserves.
As a backbone for the frontend solution, I’ve used create-react-app. You can see how I use this npm package in more detail in this story:
Here’s a snippet that you can just copy/paste for your POC:
Admittedly, I could spend more time working of visuals for this project but that wasn’t my main idea here.
Hosting
While hosting would seem like the hardest part for many, with Heroku, it’s not that tricky. It allows you to leverage the docker containers and for Flask + React solution it seems like the best way to go. Here’s a docker-compose script that would create you an isolated artefact that you can deploy to Heroku Hub:
Analytics
I’ve explored Ethereum on-chain metrics in one of my recent articles and exchange reserves were one of the most useful there. It seems like they have a lagging correlation with price action and that can be a good predictive indicator. While Binance cannot actually represent the whole market, it contains roughly 50% of it and therefore can give a good projection of the scale of the actual reserve.
As for particular use cases, here’s how the correlation of Ethereum reserves to Price changes with regards to period shift:
This plot shows that when the large portions of Eth are coming to crypto, it typically has a reverse correlation with the price within around 38 days. While this indicator cannot be a single source of truth, it was quite useful for a price estimation in general.
Conclusion
For tracking web3 data you don’t need a pricy API like CryptoQuant’s. While they have lots of fancy statistics and a lot more sources of data than a single Ethscan tracker, you can still capture useful data for your trading decisions.
Let me know if you have trouble with this tutorial and don’t forget to subscribe for future articles as it motivates me beyond reasonable!
Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing