Hız Limitleri
TCG Price Lookup API hız limitlerini, günlük kotaları ve patlama hızlarını anlama ve yönetme.
Plana Göre Hız Limitleri
| Plan | Günlük İstek | Patlama Hızı |
|---|---|---|
| Ücretsiz | 200 | 3 saniyede 1 istek |
| Trader | 10.000 | Saniyede 1 istek |
| Business | 100.000 | Saniyede 3 istek |
Günlük limitler her gün UTC gece yarısında sıfırlanır.
Hız Limiti Başlıkları
Tüm API yanıtlarında mevcut hız limiti bilgisi bulunur:
X-RateLimit-Limit: 200
X-RateLimit-Remaining: 150
X-RateLimit-Reset: 1704067200
| Başlık | Açıklama |
|---|---|
X-RateLimit-Limit | Dönem başına maksimum istek sayısı |
X-RateLimit-Remaining | Kalan istek sayısı |
X-RateLimit-Reset | Limitin sıfırlanacağı UNIX zaman damgası |
429 Hatasını Yönetme
Hız limitini aştığınızda 429 Too Many Requests döner:
{
"error": {
"code": "rate_limit_exceeded",
"message": "Daily request limit reached. Resets at midnight UTC."
}
}
Bir sonraki isteğe kadar beklenecek süreyi kontrol etmek için Retry-After başlığını kullanın:
async function fetchWithRetry(url, options, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
const response = await fetch(url, options);
if (response.status === 429) {
const retryAfter = parseInt(response.headers.get('retry-after') || '60');
await new Promise(r => setTimeout(r, retryAfter * 1000));
continue;
}
return response;
}
}
En İyi Uygulamalar
Toplu istekler kullanın (Trader planı veya üzeri):
// Verimsiz: 20 ayrı istek
for (const id of cardIds) {
await tcg.cards.get(id); // ✗
}
// Verimli: 1 toplu istek
const cards = await tcg.cards.batch(cardIds); // ✓
Yanıtları önbelleğe alın:
Fiyatlar birkaç saatte bir güncellenir. Kısa süreli önbelleğe alma (5-15 dakika) birçok kullanım senaryosu için uygundur:
const cache = new Map();
const CACHE_TTL = 5 * 60 * 1000; // 5 dakika
async function getCachedCard(id) {
const cached = cache.get(id);
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
return cached.data;
}
const data = await tcg.cards.get(id);
cache.set(id, { data, timestamp: Date.now() });
return data;
}