read.cash is a platform where you can earn money for your articles and comments. You can get paid upvotes
from other users or just earn points for writing articles and comments, which are converted daily to
Bitcoin Cash (BCH) cryptocurrency, which can be used on the Internet or converted to your local money.
Takes one minute, no documents required
Advanced BCH Monitoring with Tasker (Part 3: Recovering price quotations from an exchange data API)
Among all the exchange rate quotes providers, the most known is CoinGecko, as it is used on many projects as data providing API.
The good news is they have a very nice and easy REST API and the quotes they provide are updated with the proper frequency. The steps we are going to follow are very similar for every other REST API capable to provide this information, so if you feel like using others or having many to avoid having no quotes if CoinGecko is down, you are free to do it!
We'll start cloning the IExchangeAPI task and calling it CoinGeckoExchangeAPI.
We do an HTTP Request to the https://api.coingecko.com/api/v3/simple/price endpoint to query BCH exchange rates (ids=bitcoin-cash) on United States Dollars, Euro and Bitcoin Core (vs_currencies=usd,eur,btc)
We check if the HTTP Response Code is greater than 299, meaning that it's 300 or more, codes usually used to inform the user that something went wrong. If something went wrong we'll return an ERROR so the caller can know that this happened
We save the JSON result on a global variable so we can use it later.
We replace all '-' on the response by '_' as the first is a reserved character meant for subtract operations
Returning SUCCESS as if we reach this instruction no error happened
Running this task will clear the last JSON loaded (if any) and load a new one, will return if anything goes wrong and will show a push notification with the BCH to USD exchange rate if everything goes all right.