1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-08-01 19:11:39 +00:00

Resolve "Add rate limiting"

This commit is contained in:
2023-10-16 05:54:35 +00:00
parent 87d9346f98
commit 662344bf18
5 changed files with 48 additions and 16 deletions

View File

@@ -7,6 +7,7 @@ import schedule
from markdownify import markdownify
from common.Symbol import Coin
from common.utilities import rate_limited
log = logging.getLogger(__name__)
@@ -24,6 +25,11 @@ class cg_Crypto:
self.get_symbol_list()
schedule.every().day.do(self.get_symbol_list)
# Coingecko's rate limit is 30 requests per minute.
# Since there are two bots sharing the same IP, we allocate half of that limit to each bot.
# This results in a rate limit of 15 requests per minute for each bot.
# Given this, the rate limit effectively becomes 1 request every 4 seconds for each bot.
@rate_limited(0.25)
def get(self, endpoint, params: dict = {}, timeout=10) -> dict:
url = "https://api.coingecko.com/api/v3" + endpoint
resp = r.get(url, params=params, timeout=timeout)