Expand description
§Rate Limiter Module
This module implements sophisticated per-endpoint rate limiting based on official KiteConnect API limits to prevent exceeding rate limits and API key suspension.
§Rate Limiting Strategy
KiteConnect API has different rate limits for different endpoint categories:
- Quote endpoints: 1 request/second (real-time market data)
- Historical endpoints: 3 requests/second (historical data)
- Order endpoints: 10 requests/second (order placement/modification)
- Standard endpoints: 10 requests/second (all other operations)
§Implementation Details
The rate limiter uses a token bucket algorithm with per-category tracking:
- Each category has its own rate limit and timing
- Requests are tracked with precise timing to ensure compliance
- Automatic delays are inserted when limits would be exceeded
- Thread-safe implementation supports concurrent operations
§Usage
The rate limiter is automatically integrated into all API calls through
the KiteConnect
client. No manual intervention is required.
§Example
use kiteconnect_async_wasm::connect::KiteConnect;
let client = KiteConnect::new("api_key", "access_token");
// These calls are automatically rate-limited
let _ = client.quote_typed(vec!["NSE:RELIANCE"]).await?; // 1 req/sec limit
let _ = client.orders().await?; // 10 req/sec limit
§Performance Considerations
- Minimal overhead: Rate limiting adds microseconds per request
- Memory efficient: Only stores timing data for active categories
- Concurrent safe: Supports multiple simultaneous requests
- Auto-cleanup: Unused categories are automatically cleaned up
Structs§
- Category
Stats - Statistics for a specific rate limit category
- Rate
Limiter - Rate limiter for KiteConnect API endpoints
- Rate
Limiter Stats - Statistics about rate limiter state