Rate Limiting and Quotas
Smart Money API의 요청 제한, 각 구독 티어별 일일 할당량 및 API 사용을 극대화하기 위한 최적화 전략을 이해하세요.
개요
Smart Money API는 서비스 품질과 모든 사용자에게 공정한 환경을 보장하기 위해 일일 요청 할당량을 적용합니다. 각 구독 티어마다 다른 일일 제한이 적용됩니다. 일일 할당량을 초과하면 UTC 자정에 할당량이 재설정될 때까지 429 Too Many Requests 오류가 발생합니다.
Rate limit은 API 키별로 적용됩니다. 각 키는 독립적인 할당량을 가집니다. 다른 애플리케이션을 위해 여러 키를 생성하고 각 키의 사용량을 별도로 모니터링할 수 있습니다.
구독 티어별 할당량
| 티어 |
일일 요청 |
가격 |
기능 |
| 무료 |
200 requests/day |
$0 |
BTC, ETH, SOL, funding rates, liquidations |
| Trader |
1,000 requests/day |
$29/month |
모든 심볼, 고래 포지션, 오픈인테레스트 데이터 |
| Pro |
5,000 requests/day |
$79/month |
확인 점수, 온체인 데이터, 웹훅 |
| Enterprise |
맞춤형 |
맞춤형 |
전용 지원, 맞춤형 통합 |
모든 API 응답에는 현재 할당량 상태를 나타내는 헤더가 포함됩니다:
X-Requests-Limit: 200
X-Requests-Remaining: 147
X-Requests-Reset: 1711116000
X-Requests-Reset-ISO: 2026-03-22T00:00:00Z
| 헤더 |
설명 |
X-Requests-Limit |
하루에 허용되는 총 요청 수 (예: Trader 티어의 경우 200) |
X-Requests-Remaining |
현재 날짜에 남은 요청 수 |
X-Requests-Reset |
할당량이 재설정되는 Unix 타임스탬프 |
X-Requests-Reset-ISO |
할당량 재설정 시간의 ISO 8601 타임스탬프 |
요청 전 할당량 확인하기
import requests
from datetime import datetime
def check_quota_before_request(api_key):
response = requests.head(
"https://api.smartmoneyapi.com/v1/whales/events",
headers={"Authorization": f"Bearer {api_key}"}
)
limit = int(response.headers.get("X-Requests-Limit", 0))
remaining = int(response.headers.get("X-Requests-Remaining", 0))
reset_unix = int(response.headers.get("X-Requests-Reset", 0))
reset_time = datetime.fromtimestamp(reset_unix)
percent_used = (limit - remaining) / limit * 100
print(f"Quota: {remaining}/{limit} requests ({percent_used:.1f}% used)")
print(f"Resets at: {reset_time}")
if remaining < 5:
print("WARNING: Approaching quota limit!")
return False
return True
# 요청 전 확인
if check_quota_before_request("sk_live_abc123xyz789"):
print("Safe to proceed with API calls")
일일 Rate Window
Rate limit은 24시간 롤링 윈도우로 적용됩니다. 할당량은 매일 UTC 자정(00:00 UTC)에 재설정됩니다. 정확한 재설정 시간은 X-Requests-Reset-ISO 헤더에서 확인할 수 있습니다.
예시: Trader 티어 (1,000 requests/day)
- Day 1 (3월 21일): 00:00 UTC에 200 요청 가능
- 10:30 UTC: 75 요청 사용, 125 남음
- 15:45 UTC: 100 추가 요청 사용, 25 남음
- 23:59 UTC: 여전히 25 요청 남음 (이월 불가)
- Day 2 (3월 22일, 00:00 UTC): 할당량이 200으로 재설정됨
최적화 전략
1. API 응답 캐싱
고래 포지션은 매초마다 변경되지 않습니다. 결과를 30-60초 동안 캐시하고 새 API 호출 대신 캐시된 데이터를 제공하세요.
import requests
import time
class CachedClient:
def __init__(self, api_key, cache_ttl=60):
self.api_key = api_key
self.cache_ttl = cache_ttl
self.cache = {}
self.cache_time = {}
def get_whale_positions(self, symbol):
cache_key = f"whales:{symbol}"
now = time.time()
# 신선한 캐시 데이터 반환
if cache_key in self.cache:
age = now - self.cache_time[cache_key]
if age < self.cache_ttl:
print(f"Served from cache (age: {age:.1f}s)")
return self.cache[cache_key]
# 새 데이터 가져오기
response = requests.get(
f"https://api.smartmoneyapi.com/v1/whales/events?symbol={symbol}",
headers={"Authorization": f"Bearer {self.api_key}"}
)
data = response.json()
self.cache[cache_key] = data
self.cache_time[cache_key] = now
return data
# 사용법: 60초 동안 캐시
client = CachedClient("sk_live_abc123xyz789", cache_ttl=60)
whales1 = client.get_whale_positions("BTCUSDT") # API 호출
whales2 = client.get_whale_positions("BTCUSDT") # 캐시에서
whales3 = client.get_whale_positions("BTCUSDT") # 캐시에서
2. 실시간 데이터에는 WebSocket 사용
WebSocket 연결은 rate limit에 포함되지 않고 즉시 업데이트를 제공합니다. 스트림을 구독하고 발생하는 업데이트를 수신하여 필요한 REST API 호출 수를 줄이세요.
3. 전략적으로 요청 일괄 처리
가능한 경우 각 심볼에 대해 개별 요청을 하는 대신 여러 심볼을 포함한 하나의 요청을 만드세요. 이렇게 하면 API 호출을 최대 10배까지 줄일 수 있습니다.
4. 요청 시 필터링 사용
필터(심볼, 거래소, 최소 포지션 크기)를 쿼리 매개변수에 적용하여 필요한 데이터만 정확히 가져오세요. 이후 처리가 필요 없습니다.
Rate Limit 오류 처리
지수 백오프로 재시도
import requests
import time
def request_with_retry(url, api_key, max_retries=5):
for attempt in range(max_retries):
try:
response = requests.get(
url,
headers={"Authorization": f"Bearer {api_key}"},
timeout=10
)
if response.status_code == 200:
return response.json()
elif response.status_code == 429:
# Rate limit 초과 - 지수 백오프
wait_time = min(2 ** attempt, 300) # 최대 5분
reset_time = response.headers.get("X-Requests-Reset-ISO")
print(f"Rate limited. Retrying in {wait_time}s (resets at {reset_time})")
time.sleep(wait_time)
elif response.status_code >= 500:
# 서버 오류 - 재시도
wait_time = 2 ** attempt
print(f"Server error {response.status_code}. Retrying in {wait_time}s")
time.sleep(wait_time)
else:
# 다른 오류 - 재시도 안 함
raise Exception(f"HTTP {response.status_code}: {response.text}")
except requests.exceptions.Timeout:
wait_time = 2 ** attempt
print(f"Timeout. Retrying in {wait_time}s")
time.sleep(wait_time)
raise Exception("Max retries exceeded")
# 사용법
data = request_with_retry(
"https://api.smartmoneyapi.com/v1/whales/events",
"sk_live_abc123xyz789"
)
print(data)
업그레이드 준비되었나요?
무료 티어로는 부족한가요? Trader나 Pro로 업그레이드하여 더 높은 할당량과 확인 점수, 온체인 데이터와 같은 고급 기능에 액세스하세요.
가격 보기
지금 API 사용 최적화하기
캐싱 구현, 실시간 데이터에 WebSocket 사용, rate limit을 우아하게 처리하세요.
문서 읽기