시장 주요 지표 참고 추가

This commit is contained in:
2026-03-05 02:45:45 +09:00
parent ccc9f7c634
commit c28bd9368c
4 changed files with 372 additions and 32 deletions

View File

@@ -156,16 +156,33 @@ export async function getFearAndGreed() {
return res.json();
}
// VIX 지수 (Yahoo Finance 공개 API)
export async function getVix() {
const res = await fetch('/ext/vix', { headers: { Accept: 'application/json' } });
// Yahoo Finance chart API 공통 파서
async function fetchYahooPrice(extPath) {
const res = await fetch(extPath, { headers: { Accept: 'application/json' } });
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
const price = data?.chart?.result?.[0]?.meta?.regularMarketPrice;
if (price === undefined || price === null) throw new Error('VIX 데이터 없음');
return { value: Math.round(price * 100) / 100 };
const meta = data?.chart?.result?.[0]?.meta;
const price = meta?.regularMarketPrice;
const prevClose = meta?.previousClose ?? meta?.chartPreviousClose;
if (price == null) throw new Error('데이터 없음');
const rounded = Math.round(price * 100) / 100;
const change = prevClose != null ? Math.round((price - prevClose) * 100) / 100 : null;
const changePercent = prevClose ? Math.round(((price - prevClose) / prevClose) * 10000) / 100 : null;
return { value: rounded, change, changePercent };
}
// VIX 지수 (Yahoo Finance 공개 API)
export function getVix() { return fetchYahooPrice('/ext/vix'); }
// 미국 10년물 국채 금리 (^TNX)
export function getTreasury10Y() { return fetchYahooPrice('/ext/treasury'); }
// WTI 원유 선물 (CL=F)
export function getWTI() { return fetchYahooPrice('/ext/wti'); }
// Brent 원유 선물 (BZ=F)
export function getBrent() { return fetchYahooPrice('/ext/brent'); }
// ── TODO API ─────────────────────────────────────────────────────────────────
export function getTodos() {