- 예측 오버레이: 라인 시리즈 3개 (median/q10/q90) 를 단일 캔들 시리즈 하나로 합쳤다. 합성 OHLC: open=직전 close, close=point_close, high=ci_high, low=ci_low. 옅은 색 (up #fda4af / down #93c5fd) 으로 실 캔들과 시각 톤은 같고 명도만 낮춰 "어우러지되 미래"임이 보이게. - 예측 프리셋 단순화: 단기/중기/장기 + 직접입력 다 떼고 15일/30일/1년 3개로. 백엔드 horizon cap 30 → 252 로 확장 (1년 = 240 거래일). - PriceHero: 종목명/현재가/등락 큰 글씨 헤더. KR 관례대로 상승=빨강, 하락=파랑. - PeriodTabs: 1일/1주/1달/3달/1년/5년/최대 7탭. 기존 interval+days 이중 컨트롤 제거. 5년·최대 는 자동으로 주봉/월봉으로 폴백. - 차트 본체 캔들 색조도 KR 관례 (적/청) 로 통일. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
121 lines
3.8 KiB
TypeScript
121 lines
3.8 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import { useEffect, useMemo, useState } from "react";
|
|
import { MetricsPanel } from "../../components/MetricsPanel";
|
|
import { NewsList } from "../../components/NewsList";
|
|
import { PeriodTabs, periodSpec, type Period } from "../../components/PeriodTabs";
|
|
import { PredictionPanel } from "../../components/PredictionPanel";
|
|
import { PriceHero } from "../../components/PriceHero";
|
|
import { StockChart } from "../../components/StockChart";
|
|
import { api, type ChartPayload, type LatestPredictionResponse } from "../../lib/api";
|
|
|
|
export default function CodePage({ params }: { params: { code: string } }) {
|
|
const { code } = params;
|
|
const [chart, setChart] = useState<ChartPayload | null>(null);
|
|
const [prediction, setPrediction] = useState<LatestPredictionResponse | null>(null);
|
|
const [err, setErr] = useState<string | null>(null);
|
|
const [period, setPeriod] = useState<Period>("3M");
|
|
|
|
const spec = periodSpec(period);
|
|
const isIntraday = spec.interval === "10m";
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
setErr(null);
|
|
setChart(null);
|
|
|
|
const load = () => {
|
|
api
|
|
.getChart(code, spec.days, spec.interval)
|
|
.then((c) => {
|
|
if (alive) setChart(c);
|
|
})
|
|
.catch((e) => {
|
|
if (alive) setErr(e instanceof Error ? e.message : String(e));
|
|
});
|
|
};
|
|
load();
|
|
|
|
// 1일(10분봉) 모드만 60s 폴링 — 백엔드가 10분 내면 DB 만 읽음.
|
|
if (isIntraday) {
|
|
const h = window.setInterval(load, 60_000);
|
|
return () => {
|
|
alive = false;
|
|
window.clearInterval(h);
|
|
};
|
|
}
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [code, spec.days, spec.interval, isIntraday]);
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
api
|
|
.latestPrediction(code)
|
|
.then((r) => {
|
|
if (alive && r.found) setPrediction(r);
|
|
})
|
|
.catch(() => {
|
|
// 예측 이력 없음 — 무시
|
|
});
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [code]);
|
|
|
|
// 현재가/전일가 — ohlcv 끝 두 점에서 산출.
|
|
const { current, prev, asOf } = useMemo(() => {
|
|
if (!chart || !chart.ohlcv.length) return { current: null, prev: null, asOf: null };
|
|
const valid = chart.ohlcv.filter((p) => p.close != null);
|
|
if (!valid.length) return { current: null, prev: null, asOf: null };
|
|
const last = valid[valid.length - 1];
|
|
const prevPt = valid.length >= 2 ? valid[valid.length - 2] : null;
|
|
return {
|
|
current: last.close,
|
|
prev: prevPt?.close ?? null,
|
|
asOf: last.date,
|
|
};
|
|
}, [chart]);
|
|
|
|
return (
|
|
<main className="mx-auto max-w-5xl px-6 py-8">
|
|
<div className="mb-4 flex items-center justify-between gap-3">
|
|
<Link href="/" className="text-xs text-zinc-500 hover:text-zinc-300">
|
|
← 검색
|
|
</Link>
|
|
<PeriodTabs value={period} onChange={(id) => setPeriod(id)} />
|
|
</div>
|
|
|
|
{err && <div className="mb-4 text-sm text-red-400">차트 로딩 실패: {err}</div>}
|
|
|
|
{chart && (
|
|
<>
|
|
<PriceHero
|
|
name={chart.name}
|
|
code={chart.code}
|
|
market={chart.market}
|
|
current={current}
|
|
prev={prev}
|
|
asOf={asOf}
|
|
/>
|
|
<StockChart chart={chart} prediction={prediction} />
|
|
{isIntraday && chart.intraday_status && (
|
|
<div className="mt-2 text-right text-[11px] text-zinc-500">
|
|
실시간 10분봉 · 60초 갱신 · [{chart.intraday_status}]
|
|
</div>
|
|
)}
|
|
<div className="mt-6">
|
|
<PredictionPanel code={code} initial={prediction} onResult={setPrediction} />
|
|
</div>
|
|
<div className="mt-6 grid gap-6 md:grid-cols-2">
|
|
<MetricsPanel code={code} />
|
|
<NewsList code={code} />
|
|
</div>
|
|
</>
|
|
)}
|
|
</main>
|
|
);
|
|
}
|