For anyone trying to fix issue with Coingecko API
Today was one of the toughest days for me. Ever since I woke up in the morning I had to deal with issues on multiple services that I host for others. Something is wrong with Coingecko. I did not bother to check my apps when Aggy made an announcement yesterday. Today I was forced to check my apps and do some fixes. Someone said that Coingecko API had a DDoS attack on their API and the regular requests were also affected.
I guess Coingecko is now switching from an open API to an API key-based solution. I guess that's better because only authenticated people will be able to get their requests served. I did not get the time to explore this and was also not sure if their DDoS problem was resolved or not. I started looking for an alternative solution and thought of using Coinmarketcap instead. They have an API key-based solution and there are only limited requests someone can make to the API per day. It is only 333 requests per day.
It was a long day for me so, this post is going to be a short one. For someone switching from Coingecko's API to Coinmarketcap, below is the code snippet to query the price of Hive and HBD with the help of the coinmarketcap API endpoint. It took me a while to understand the documentation and come up with this function.
const axios = require('axios');
const price = async () => {
try {
const p = await axios.get(
'https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?slug=hive-dollar,hive-blockchain',
{
headers: {
'X-CMC_PRO_API_KEY': '03be2b5b-f285-4624-8082-0ab0c077fcfa',
},
},
);
return {
hive: p.data.data['5370'].quote.USD.price,
hbd: p.data.data['5375'].quote.USD.price,
};
} catch (e) {
// eslint-disable-next-line no-console
console.log('Error in getting price', e);
return e;
}
};
I have this function being called every 5 minutes to get the updated price. I initially had a once in 30 seconds call but with the current API restrictions, I guess I will not be able to do calls that frequently. So I'm switching to a once in 5 minutes call and also saving the price locally. This way I don't have to call the API every time I need data. Maybe if I can use two API keys from two email addresses, I guess I should be able to do more calls which would be 666 calls per day. But currently, I don't have a need for it. Maybe in the future, if there is a need, I can think of having multiple email addresses as the solution.
There is also one more option instead of using Coingecko API or Coinmarketcap API. This would be to get the price directly from exchanges and get an average out of them. This function in the price feed application can also be used for this purpose. Anyone who would like to explore these can give them a try.
If you like what I'm doing on Hive, you can vote me as a witness with the links below.
|
|
|
|
|
|
https://twitter.com/180355589/status/1641173626899800064
The rewards earned on this comment will go directly to the people( @bala41288 ) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.
I am experiencing API problems at CoinGecko as well. It has affected some of my pricing updates.
But it is not all endpoints. Other endpoints are working fine, for example
I'm sure they've blocked endpoints that are taking the DDOS hits and hopefully can make all available again soon.
I do have multiple price and info API engines coded. But for some features in my app, CoinGecko's API can load my data more a lot more efficiently in one call.
Yeah I also liked coingecko and it was better than the other options we had. I did not check the other end points. As soon as my console was filled with errors I looked for alternative.
I really appreciate you posting this article. It saved me from wondering and researching if the problem was on my end.
Glad to hear that my article was helpful for you.