WebSocket 환율 API
지원되는 통화쌍을 구독하고 지속적인 연결로 환율 업데이트를 받으세요. API 키는 서버에 보관하세요.
연결 시작
wss://api.exchangerate.dev/v1/stream에 연결하고 10초 안에 auth를 보낸 뒤 authenticated 후 subscribe를 보내세요.
연결 예시
이 서버 측 순서는 키를 인증하고 USD/EUR와 USD/JPY를 구독합니다.
// Node.js 22+ · run on your server · set EXCHANGERATE_API_KEY in the environment
const key = process.env.EXCHANGERATE_API_KEY;
if (!key) throw new Error("EXCHANGERATE_API_KEY is required");
let retries = 0;
let stopped = false;
function connect() {
const ws = new WebSocket("wss://api.exchangerate.dev/v1/stream");
ws.addEventListener("open", () => {
ws.send(JSON.stringify({ action: "auth", api_key: key }));
});
ws.addEventListener("message", ({ data }) => {
const frame = JSON.parse(String(data));
if (frame.type === "authenticated") {
retries = 0;
ws.send(JSON.stringify({ action: "subscribe", base: "USD", symbols: ["EUR", "JPY"] }));
} else if (frame.type === "snapshot" || frame.type === "update") {
if (frame.stale) return; // Keep the observation time; don't treat it as a fresh tick.
console.log(frame.base, frame.symbol, frame.rate, frame.effective_at);
} else if (frame.type === "state") {
console.log(frame.base, frame.symbol, frame.state); // stale or unavailable
} else if (frame.type === "error") {
console.error(frame.code, frame.message);
if (["invalid_api_key", "quota_exceeded", "connection_limit_exceeded", "subscription_limit_exceeded"].includes(frame.code)) {
stopped = true;
ws.close();
}
}
});
ws.addEventListener("close", () => {
if (stopped) return;
const delay = Math.min(30_000, 1_000 * 2 ** Math.min(retries++, 5));
setTimeout(connect, delay + Math.random() * 250);
});
}
connect();WebSocket 연결에는 인증이 필요합니다.
각 메시지 읽기
메시지에는 통화쌍, 환율, 관측 시각과 신선도 상태가 포함됩니다. unavailable과 stale을 명시적인 상태로 처리하세요.
{
"type": "update",
"base": "USD",
"symbol": "JPY",
"rate": "154.792",
"effective_at": "2026-09-15T02:59:44Z",
"source": "live",
"source_type": "market",
"market_session": "open",
"derived": false,
"stale": false
}지원 범위
현재 지원 범위 표에 있는 통화쌍만 구독할 수 있습니다. 교차쌍은 양쪽 레그의 최신 관측이 필요합니다.
AUD, CAD, CHF, EUR, GBP, JPY, MXN, NOK, NZD, PLN, SEK, SGD, USD, ZAR · 182 지원 통화쌍
업데이트는 지표 관측값입니다. 각 메시지의 상태와 관측 시각을 확인하세요.
현재 지원 범위 확인플랜 제한
연결 수와 연결당 통화쌍 수는 플랜에 따라 다릅니다. 승인된 연결 하나마다 월간 할당량 한 단위를 사용합니다.
| 플랜 | 연결 | 연결당 통화쌍 | 상업적 사용 |
|---|---|---|---|
| Free | 1 | 5 | 아니요 |
| Basic | 3 | 25 | 예 |
| Pro | 10 | 100 | 예 |
승인된 연결 하나마다 월간 할당량 한 단위를 사용합니다.
요금 보기상업적 사용
스트림에 의존하는 제품을 배포하기 전에 현재 플랜과 상업적 사용 조건을 확인하세요.
안전한 재연결
연결이 끊기면 잠시 기다린 뒤 다시 연결하고, 재인증하여 authenticated를 기다린 다음 다시 구독하세요. 키를 URL이나 공개 JavaScript에 넣지 마세요.
누락된 업데이트는 누락된 상태로 남으며 스트림은 값을 만들지 않습니다.
익명으로 연결할 수 있나요?
아니요. WebSocket 연결에는 API 키가 필요합니다. 지원되는 REST 엔드포인트에서는 익명으로 테스트할 수 있습니다.
모든 통화쌍을 스트리밍할 수 있나요?
아니요. WebSocket 지원 범위는 통화쌍별로 다릅니다. 표를 확인하고 지원되지 않는 구독을 명시적으로 처리하세요.