주식 각종 지표 업데이트

This commit is contained in:
2026-03-05 08:14:49 +09:00
parent fa696b0c90
commit b9aeb2ff3e
2 changed files with 124 additions and 2 deletions

View File

@@ -9,6 +9,10 @@ import {
deletePortfolio,
upsertCash,
deleteCash,
getFearAndGreed,
getVix,
getTreasury10Y,
getWTI,
} from '../../api';
import Loading from '../../components/Loading';
import './Stock.css';
@@ -91,6 +95,22 @@ const profitColorClass = (numericValue) => {
return '';
};
const getVixLabel = (vix) => {
if (vix < 12) return '극히 낮음 (안일 주의)';
if (vix < 20) return '정상 (안정적)';
if (vix < 30) return '주의 (불확실성 증가)';
if (vix < 40) return '높음 (극도의 공포)';
return '극단 (패닉)';
};
const getFgLabel = (score) => {
if (score <= 25) return '극단적 공포';
if (score <= 45) return '공포';
if (score <= 55) return '중립';
if (score <= 75) return '탐욕';
return '극단적 탐욕';
};
/* ── empty portfolio form ────────────────────────────────────────── */
const emptyPortfolioForm = {
@@ -153,6 +173,7 @@ const StockTrade = () => {
const [aiResult, setAiResult] = useState(null);
const [aiLoading, setAiLoading] = useState(false);
const [aiError, setAiError] = useState('');
const [marketCtx, setMarketCtx] = useState(null);
/* ────────────────────────────────────────────────────────────── */
/* AI 투자 (Balance) state */
@@ -228,6 +249,22 @@ const StockTrade = () => {
}
}, []);
/* 리포트 탭 진입 시 시장 컨텍스트(VIX, F&G, 국채, WTI) 한 번 로드 */
useEffect(() => {
if (activeTab !== TAB_REPORT || marketCtx !== null) return;
Promise.allSettled([getFearAndGreed(), getVix(), getTreasury10Y(), getWTI()])
.then(([fg, vix, t, w]) => {
const fgRaw = fg.status === 'fulfilled' ? fg.value : null;
const fgScore = fgRaw?.fear_and_greed?.score ?? fgRaw?.score;
setMarketCtx({
fg: fgScore != null ? Math.round(Number(fgScore)) : null,
vix: vix.status === 'fulfilled' ? (vix.value?.value ?? null) : null,
treasury: t.status === 'fulfilled' ? (t.value?.value ?? null) : null,
wti: w.status === 'fulfilled' ? (w.value?.value ?? null) : null,
});
});
}, [activeTab, marketCtx]);
/* Auto-refresh portfolio every 3 min (포트폴리오 탭 활성 시) */
useEffect(() => {
if (activeTab !== TAB_PORTFOLIO) return;
@@ -381,7 +418,11 @@ const StockTrade = () => {
)
.join('\n');
const prompt = `당신은 한국 주식 전문 투자 코치입니다. 아래 포트폴리오를 분석하여 JSON으로만 답하세요.
const marketText = marketCtx
? `\n[현재 시장 환경]\nVIX: ${marketCtx.vix != null ? `${marketCtx.vix} (${getVixLabel(marketCtx.vix)})` : '데이터 없음'}\nFear & Greed: ${marketCtx.fg != null ? `${marketCtx.fg}점 (${getFgLabel(marketCtx.fg)})` : '데이터 없음'}\n미국 10년물 국채: ${marketCtx.treasury != null ? `${marketCtx.treasury}%` : '데이터 없음'}\nWTI 유가: ${marketCtx.wti != null ? `$${marketCtx.wti}` : '데이터 없음'}`
: '';
const prompt = `당신은 한국 주식 전문 투자 코치입니다. 아래 포트폴리오와 시장 환경을 종합 분석하여 JSON으로만 답하세요.
분석 일자: ${today}
총 매입금액: ${formatNumber(portfolioSummary.total_buy)}
@@ -391,7 +432,7 @@ const StockTrade = () => {
총 자산: ${totalAssets != null ? formatNumber(totalAssets) + '원' : '미집계'}
보유 종목 수: ${portfolioHoldings.length}
보유 종목:
${holdingsText}
${holdingsText}${marketText}
반드시 아래 JSON 형식으로만 응답하세요 (코드블록 없이, 모든 텍스트는 한국어로):
{
@@ -1695,6 +1736,37 @@ ${holdingsText}
</div>
</div>
{/* 시장 컨텍스트 미니 패널 */}
{marketCtx && (
<div className="ai-market-ctx">
<span className="ai-market-ctx__label">시장 환경</span>
<div className="ai-market-ctx__chips">
{marketCtx.vix != null && (
<span className="ai-market-chip">
VIX&nbsp;<strong>{marketCtx.vix}</strong>
<em>{getVixLabel(marketCtx.vix)}</em>
</span>
)}
{marketCtx.fg != null && (
<span className="ai-market-chip">
F&amp;G&nbsp;<strong>{marketCtx.fg}</strong>
<em>{getFgLabel(marketCtx.fg)}</em>
</span>
)}
{marketCtx.treasury != null && (
<span className="ai-market-chip">
10년물&nbsp;<strong>{marketCtx.treasury}%</strong>
</span>
)}
{marketCtx.wti != null && (
<span className="ai-market-chip">
WTI&nbsp;<strong>${marketCtx.wti}</strong>
</span>
)}
</div>
</div>
)}
{/* API Key 설정 */}
<div className="ai-coach-settings">
<label>