Skip to content

feat: add configurable rate limits with functional options API#5

Merged
terwey merged 2 commits intomainfrom
claude/configure-user-ratelimits-011CUzq42cKrg7xAGznYYX8H
Nov 10, 2025
Merged

feat: add configurable rate limits with functional options API#5
terwey merged 2 commits intomainfrom
claude/configure-user-ratelimits-011CUzq42cKrg7xAGznYYX8H

Conversation

@terwey
Copy link
Copy Markdown
Collaborator

@terwey terwey commented Nov 10, 2025

Summary

Adds configurable rate limiting based on 3Commas subscription tiers and refactors client initialization to use functional options pattern instead of config structs.

Changes

Rate Limiting by Plan Tier

  • Add PlanTier enum with three tiers matching 3Commas API limits:
    • Starter: 5 requests/minute (read-only)
    • Pro: 50 requests/minute (read-only)
    • Expert: 120 requests/minute (read/write, default)
  • Modify rate limiter engine to use tier-based global limits
  • Update WithThreeCommasRateLimits() to accept optional tier parameter

Functional Options Pattern

  • Replace ClientConfig struct with functional options for cleaner API
  • Add new option functions:
    • WithAPIKey(string)
    • WithPrivatePEM([]byte)
    • WithThreeCommasBaseURL(string)
    • WithPlanTier(PlanTier)
  • Validate required fields (API key, private key) in constructor

Testing & Documentation

  • Update all existing tests to use new option pattern
  • Add comprehensive rate limiter tests for each tier
  • Update README with:
    • Functional options usage examples
    • Rate limiting configuration guide
    • Tier comparison table
    • Updated features list

Migration Guide

Before:

client, err := threecommas.New3CommasClient(threecommas.ClientConfig{
    APIKey:     "key",
    PrivatePEM: pemBytes,
})

After:

client, err := threecommas.New3CommasClient(
    threecommas.WithAPIKey("key"),
    threecommas.WithPrivatePEM(pemBytes),
    threecommas.WithPlanTier(threecommas.PlanPro), // optional
)

Rationale

3Commas introduced tiered rate limits based on subscription plans. This change allows users to configure their tier to avoid unnecessary rate limiting while maintaining backward compatibility (defaults to Expert tier).

- Add PlanTier enum (Starter, Pro, Expert) with corresponding rate limits
  - Starter: 5 req/min
  - Pro: 50 req/min
  - Expert: 120 req/min (default)
- Replace ClientConfig struct with functional options pattern
  - WithAPIKey(), WithPrivatePEM(), WithThreeCommasBaseURL(), WithPlanTier()
- Update WithThreeCommasRateLimits() to accept optional tier parameter
- Modify rate limiter engine to use tier-based global limits
- Update all tests to use new option pattern
- Add comprehensive tests for plan tier functionality
- Replace ClientConfig struct example with functional options pattern
- Add Configuration section documenting all available options
- Add Rate Limiting section with tier comparison table
- Document rate limiter features (token bucket, 429/418 handling)
- Update Features list to include new capabilities
@terwey terwey marked this pull request as ready for review November 10, 2025 21:33
@terwey terwey merged commit 23af021 into main Nov 10, 2025
1 check passed
@terwey terwey deleted the claude/configure-user-ratelimits-011CUzq42cKrg7xAGznYYX8H branch November 10, 2025 21:41
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.

2 participants