대시보드 수정중
This commit is contained in:
@@ -267,6 +267,26 @@ const Dashboard = () => {
|
||||
setLiveQuote(null)
|
||||
}, [selectedStock])
|
||||
|
||||
// 실시간 평가손익/총자산 — livePrices 기반 매 틱마다 재계산
|
||||
const liveSummary = useMemo(() => {
|
||||
if (!portfolioSummary || !portfolio) return portfolioSummary
|
||||
const liveValue = portfolio.reduce((sum, s) => {
|
||||
const price = livePrices[s.stock_code] ?? Number(s.current_price || 0)
|
||||
return sum + price * Number(s.quantity || 0)
|
||||
}, 0)
|
||||
const totalInvestment = portfolio.reduce((sum, s) =>
|
||||
sum + Number(s.average_price || 0) * Number(s.quantity || 0), 0)
|
||||
const liveProfitLoss = liveValue - totalInvestment
|
||||
const liveProfitLossRate = totalInvestment > 0 ? (liveProfitLoss / totalInvestment) * 100 : 0
|
||||
return {
|
||||
...portfolioSummary,
|
||||
total_value: liveValue,
|
||||
total_profit_loss: liveProfitLoss,
|
||||
total_profit_loss_rate: liveProfitLossRate,
|
||||
total_assets: (portfolioSummary.available_cash || 0) + liveValue,
|
||||
}
|
||||
}, [portfolioSummary, portfolio, livePrices])
|
||||
|
||||
// 실시간 차트: 마지막 캔들에 live price 반영 (close/high/low)
|
||||
// livePrice가 selectedStock에 대해서만 변경될 때 재계산
|
||||
const livePrice = livePrices[selectedStock]
|
||||
@@ -488,7 +508,7 @@ const Dashboard = () => {
|
||||
|
||||
<main className="flex-1 p-4 max-w-[1920px] mx-auto w-full flex flex-col gap-4 overflow-hidden">
|
||||
<div className="flex-shrink-0">
|
||||
<PortfolioSummary summary={portfolioSummary} error={portfolioSummaryError} />
|
||||
<PortfolioSummary summary={liveSummary} error={portfolioSummaryError} />
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-12 gap-4 flex-1 min-h-0">
|
||||
|
||||
Reference in New Issue
Block a user