Batch Operations
단일 배치 작업에서 여러 API 요청을 처리하세요. API 호출을 최대 90%까지 줄이고 대량 데이터 검색 및 분석 성능을 향상시킵니다.
Overview
배치 작업을 통해 단일 HTTP 요청으로 여러 API 요청을 보낼 수 있습니다. 이는 API 호출 횟수를 줄이고 지연 시간을 개선하며, 대량 데이터 검색, 여러 심볼 모니터링 또는 배치 분석 수행에 이상적입니다. 배치당 최대 100개의 요청을 보낼 수 있습니다.
Batch Request Format
POST to /v1/batch with an array of request objects:
{
"requests": [
{
"id": "req_1",
"method": "GET",
"path": "/v1/whales/events?symbol=BTCUSDT"
},
{
"id": "req_2",
"method": "GET",
"path": "/v1/whales/events?symbol=ETHUSDT"
},
{
"id": "req_3",
"method": "GET",
"path": "/v1/funding-rates?symbol=BTCUSDT"
}
]
}
Batch Response Format
요청 ID로 인덱싱된 단일 배치 응답 객체로 모든 응답을 받습니다:
{
"success": true,
"responses": {
"req_1": {
"status": 200,
"data": {
"total": 42,
"positions": [...]
}
},
"req_2": {
"status": 200,
"data": {
"total": 28,
"positions": [...]
}
},
"req_3": {
"status": 200,
"data": {...}
}
},
"timestamp": "2026-03-21T14:35:22Z"
}
Code Examples
Python: Batch Whale Positions for Multiple Symbols
import requests
def batch_fetch_whale_positions(api_key, symbols):
"""Fetch whale positions for multiple symbols in one batch"""
# Build batch requests
requests_list = []
for i, symbol in enumerate(symbols):
requests_list.append({
"id": f"req_{i+1}",
"method": "GET",
"path": f"/v1/whales/events?symbol={symbol}&limit=50"
})
# Send batch request
response = requests.post(
"https://api.smartmoneyapi.com/v1/batch",
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
},
json={"requests": requests_list}
)
batch_response = response.json()
# Process responses
results = {}
for symbol, response in zip(symbols, batch_response["responses"].values()):
if response["status"] == 200:
results[symbol] = response["data"]["positions"]
return results
# Usage: Fetch 5 symbols in one batch
symbols = ["BTCUSDT", "ETHUSDT", "SOLUSDT", "XRPUSDT", "ADAUSDT"]
positions = batch_fetch_whale_positions("sk_live_abc123xyz789", symbols)
print(f"Fetched positions for {len(positions)} symbols")
Benefits of Batch Operations
Reduced API Calls
100개의 요청을 하나의 배치로 보내면 100번의 API 호출 대신 1번의 호출로 처리됩니다. 대량 통합을 위한 엄청난 할당량 절약.
Improved Performance
100번의 HTTP 요청 대신 단일 왕복 요청. 대량 작업에 대한 낮은 지연 시간과 빠른 데이터 검색.
Atomic Transactions
배치 내 모든 요청이 함께 처리됩니다. 배치 작업 간 부분 실패가 없습니다.
Easier Error Handling
배치를 단위로 처리하면서 각 요청에 대한 개별 응답 상태를 처리합니다.
Use Cases
Monitoring multiple trading pairs: 50개의 심볼에 대한 고래 포지션을 하나의 배치 요청으로 가져옵니다.
Daily reporting: 관련 데이터(펀딩 레이트, 미결제약정, 청산)를 단일 배치로 수집합니다.
Portfolio analysis: 여러 심볼과 거래소 간 포지션을 효율적으로 분석합니다.
Webhook processing: 여러 웹훅 이벤트를 단일 API 호출로 배치 처리하여 분석합니다.