Upgrading to Coinmarketcap.com API v2
As someone of you may know, I published a cryptocurrency portfolio template for Google sheet. It uses coinmarketcap.com's API to get it's prices.
Yesterday, coinmarketcap released their API v2. They are deprecating API v1 on November 30th, 2018. So, I tried upgrading my template to use the new API.
At first look, the API didn't seem to change much. It provides almost same data and almost same arguments. The resulting JSON is more structured.
The largest change is the coin ID. It used to accept string (which they call website_slug) which is the last url string of the cryptoasset's webpage. It is replaced by their internal numeral id. The JSON results contains the "id" for each cryptoassets. But client need to know the "id" before it makes a request to get each coin info from the API. So I had to make a lookup table by enumerating all coins and save to a sheet. I also added "CMC ID" column, so the script doesn't have to use the lookup table every time it sends an API request.
The next thing the new API didn't return was price in BTC. So I had to calculate the price in BTC by getting the price of Bitcoin in USD first and calculate the price for each coin's USD value.
They were getting too many requests and was forced to make the API less friendly to achieve better server performance. I agree with the decision they made. But they should have at least considered providing a lookup API for coins, so developers don't have to enumerate all coins to build a lookup table.
Here's the new template. I think I need to test it more before upgrading the already shared template.
If you are using template v2, you can replace the script and it will function properly. On first run, it will add a "lookup" sheet which takes a few minutes.