Crypto API Rate Limiting: Best Practices for Trading Bots
Crypto API Rate Limiting: Best Practices for Trading BotsIf you're building a crypto trading bot, you've hit rate limits. CoinGecko's 30 req/min, Binance's 1200/min with burst limits, and every other API has. . .

Crypto API Rate Limiting: Best Practices for Trading BotsIf you're building a crypto trading bot, you've hit rate limits. CoinGecko's 30 req/min, Binance's 1200/min with burst limits, and every other API has its own rules. Here's how to handle them properly. The ProblemMost bot developers hit rate limits because they:Poll every endpoint every second (you don't need BTC price 60x/minute)Don't cache responses that haven't changedDon't handle 429 responses gracefullyUse a single data source with no fallbackSolution 1: Smart CachingMost market data doesn't change meaningfully every second. Cache aggressively:importtimeimportrequestsclassCachedAPI:def__init__(self):self. _cache={}defget(self,url,ttl_seconds=60):now=time. time()ifurlinself. _cache:data,ts=self. _cache[url]ifnow-ts<ttl_seconds:returndataresp=requests. get(url,timeout=10)resp. raise_for_status()data=resp. json()self. _cache[url]=(data,now)returndataapi=CachedAPI()# Regime changes slowly — cache for 5 minutesregime=api. get("https://getregime. com/api/v1/market/regime",ttl_seconds=300)# Prices change faster — cache for 30 secondsoverview=api. get("https://getregime. com/api/v1/market/overview",ttl_seconds=30)Enter fullscreen modeExit fullscreen modeSolution 2: Exponential BackoffWhen you do hit a rate limit, back off exponentially:importtimeimportrequestsdeffetch_with_backoff(url,max_retries=3):forattemptinrange(max_retries):resp=requests. get(url,timeout=10)ifresp. status_code==429:wait=(2**attempt)*1# 1s, 2s, 4sretry_after=resp. headers. get('Retry-After',wait)print(f"Rate limited. Waiting{retry_after}s. . . ")time. sleep(float(retry_after))continueresp. raise_for_status()returnresp. json()raiseException("Max retries exceeded")Enter fullscreen modeExit fullscreen modeSolution 3: Read the Rate Limit HeadersGood APIs tell you exactly where you stand:resp=requests. get("https://getregime. com/api/v1/market/regime",headers={"Authorization":"Bearer YOUR_KEY"})limit=resp. headers. get("X-RateLimit-Limit")# e. g. , 120remaining=resp. headers. get("X-RateLimit-Remaining")# e. g. , 85reset=resp. headers. get("X-RateLimit-Reset")# seconds until reset# Also check for upgrade hints when approaching the limitupgrade_hint=resp. headers. get("X-Upgrade-Hint")ifupgrade_hint:print(f"Approaching limit:{upgrade_hint}")Enter fullscreen modeExit fullscreen modeSolution 4: Multi-Source FailoverDon't depend on a single API:SOURCES=[{"url":"https://getregime. com/api/v1/market/overview","name":"Regime"},{"url":"https://api. coingecko. com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd","name":"CoinGecko"},]defget_btc_price():forsourceinSOURCES:try:resp=requests. get(source["url"],timeout=5)ifresp. ok:data=resp. json()ifsource["name"]=="Regime":returndata["btc"]["price"]elifsource["name"]=="CoinGecko":returndata["bitcoin"]["usd"]except:continueraiseException("All sources failed")Enter fullscreen modeExit fullscreen modeRate Limits by APIAPIFree LimitPaid LimitNotesRegime10 RPM / 500/day120 RPM / 10K/day (Pro)Headers includedBinance1200 req/minSameWeight-based systemCoinGecko30 req/min500 req/min (Pro)429 common at peakCryptoCompare100K/month2M/monthMonthly quotaMessari20 req/min100 req/minPer-endpoint limitsKey TakeawaysCache everything— most data doesn't change faster than your cache TTLUse regime for decisions, price feeds for execution— you don't need real-time regime (it changes every few hours, not seconds)Read rate limit headers— they tell you exactly when to slow downBuild failover— no single API is 100% reliableStart with the free tier:curl https://getregime. com/api/v1/market/regimeFull docs:getregime. com/quickstartTry Regime IntelligenceRegime is a real-time crypto market regime detection API. One endpoint tells you if the market is bull, bear, or chop — so your bot only trades when conditions match your strategy. Free API access →|See pricing →|API docs →