Skip to content

feat(slice-012): CoinGecko rate limiting#13

Merged
fredericomozzato merged 5 commits into
mainfrom
feat/012-coingecko-rate-limiting
Apr 15, 2026
Merged

feat(slice-012): CoinGecko rate limiting#13
fredericomozzato merged 5 commits into
mainfrom
feat/012-coingecko-rate-limiting

Conversation

@fredericomozzato
Copy link
Copy Markdown
Owner

Summary

  • Implement request throttling in internal/api/coingecko.go — minimum 2s gap between API calls, respecting context cancellation
  • Detect HTTP 429 responses and extract Retry-After header into a RateLimitError type with IsRateLimitError and RetryAfterFromError helpers
  • Extend manual refresh (r key) to no-op when rate-limited or already refreshing
  • Surface rate-limit status in the status bar with countdown: Rate limited — retry in Xs
  • Exponential backoff on repeated 429s (1×, 2×, 4×, 8×, capped at 5min), reset on successful refresh
  • Mark slice 012 as DONE in roadmap and issue tracker

Test Plan

  • make check passes (fmt, lint, test, vuln)
  • Throttle logic tested with short intervals (10ms)
  • 429 detection and Retry-After header parsing tested via httptest.NewServer
  • MarketsModel rate-limit state transitions tested (backoff, cooldown, reset on success, status bar rendering)
  • No real network requests in any test

- Add RateLimitError type with RetryAfter field
- Add IsRateLimitError and RetryAfterFromError helpers
- Add throttle mechanism to HTTPClient with 2s min interval
- Add 429 detection in FetchMarkets and FetchPrices
- Add comprehensive tests for throttling and rate limiting
- Add rateLimitedUntil and refreshAttempts fields to MarketsModel
- Update errMsg handler to detect RateLimitError and apply exponential backoff
- Block manual refresh (r key) when rate-limited
- Block auto-refresh (tickMsg) when rate-limited
- Reset backoff state on successful prices update
- Update statusRight() to show rate-limited countdown
- Update renderStatusBar() with dark orange style for rate-limited state
- Add comprehensive tests for rate-limit state transitions
- Update roadmap: IN_PROGRESS -> IN_REVIEW
- Update issue frontmatter: in_progress -> in_review
…lock and timer fire

Closes finding I1 in docs/reviews/012-coingecko-rate-limiting/revision-1.md
@fredericomozzato fredericomozzato merged commit 05f05ba into main Apr 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant