0

Problem:

  • On July 23, this code suddenly stop working.

Environment:

Error Message:

Exception: Request failed for https://api.coingecko.com returned code 429. Truncated server response: {"status":{"error_code":429, "error_message": "You've exceeded the Rate Limit. Please visit https://www.coingecko.com/en/api/pricing to subscribe to ... (use the muteHttpExceptions option to examine the full response)

Code:

function test() {
  const URL = 'https://api.coingecko.com/api/v3/coins/bitcoin'
  
  Utilities.sleep(10000)
  const fetchedData1 = UrlFetchApp.fetch(url)
  console.log(fetchedData1)

  Utilities.sleep(10000)
  const fetchedData2 = UrlFetchApp.fetch(url)
  console.log(fetchedData2)
  
}
Jinn Jinn
  • 25
  • 5
  • 1
    Use a exponential backoff – TheMaster Jul 25 '22 at 09:08
  • Try caching recent results so that they do not need to be refetched. See [Use the Cache service](https://developers.google.com/apps-script/guides/support/best-practices#use_the_cache_service). If you are using the service a lot, consider subscribing to a paid plan. – doubleunary Jul 25 '22 at 09:18
  • 1
    According to the [docs](https://www.coingecko.com/en/api/documentation) Coin Gecko's free plan allows up to 50 calls/per minute. Are you making more requests against the api than you did prior to July 23rd? Also consider, IIRC, that GAS uses a fixed set of IPs, so if that's what the API uses to track usage (they don't use an API key to distinguish users), you and every other script that uses GAS to access the API would contribute to that quota. – TheAddonDepot Jul 25 '22 at 13:20
  • @TheAddonDepot Yes, I am aware of the rate limit of coin gecko and I hadn't changed the quota at all and the quota is only 14 calls. Additionally, I have not got any GAS quota limit error. – Jinn Jinn Jul 26 '22 at 02:58

1 Answers1

0

Try adding Utilities.sleep(10000); before CoinGecko.tryCatch(i); to reduce the calls rate to the API.

Use trial and error to find the "optimal value" for the Utilities.sleep parameter and use together with an advanced algorithm like exponential backoff to handle Google Apps Script performance variations.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Hi, Ruben. Thank you. But this didn't solve the issue. I adjusted the sleep time. Yet, some times only few calls have succeeded, sometimes 0 calls have succeeded. I have no idea what causes this irregular failures. In any cases, it ends up returning undefined. – Jinn Jinn Jul 26 '22 at 03:27