1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Rate limiting for Kraken API.
//!
//! Kraken has strict rate limits that vary by endpoint type and verification tier.
//! This module provides automatic rate limiting to prevent API bans.
//!
//! ## Rate Limit Categories
//!
//! - **Public endpoints**: Limited by IP address (sliding window)
//! - **Private endpoints**: Limited by API key, varies by verification tier (token bucket)
//! - **Trading endpoints**: Additional penalties for order placement/cancellation
//!
//! ## Example
//!
//! ```rust,ignore
//! use kraken_api_client::spot::rest::SpotRestClient;
//! use kraken_api_client::rate_limit::{RateLimitedClient, RateLimitConfig};
//! use kraken_api_client::types::VerificationTier;
//!
//! // Wrap a client with automatic rate limiting
//! let client = SpotRestClient::new();
//! let rate_limited = RateLimitedClient::new(client, RateLimitConfig {
//! tier: VerificationTier::Intermediate,
//! enabled: true,
//! });
//!
//! // All requests are automatically rate limited
//! let time = rate_limited.get_server_time().await?;
//! ```
//!
//! ## Low-Level Rate Limiters
//!
//! You can also use the rate limiters directly for custom logic:
//!
//! ```rust
//! use kraken_api_client::rate_limit::{TtlCache, KeyedRateLimiter, TradingRateLimiter};
//! use std::time::Duration;
//!
//! // Track orders for rate limit penalty calculation
//! let mut order_cache: TtlCache<String, i64> = TtlCache::new(Duration::from_secs(300));
//!
//! // Per-pair rate limiting for order book requests
//! let mut pair_limiter: KeyedRateLimiter<String> = KeyedRateLimiter::new(Duration::from_secs(1), 5);
//!
//! // Trading rate limiter with order lifetime penalties
//! let mut trading_limiter = TradingRateLimiter::new(20, 1.0);
//! ```
pub use RateLimitedClient;
pub use ;
pub use ;
pub use TtlCache;
use crateVerificationTier;
/// Rate limiter configuration.
/// Rate limit constants by verification tier.