대시보드 수정및 전략수정중
This commit is contained in:
@@ -267,23 +267,37 @@ const Dashboard = () => {
|
||||
setLiveQuote(null)
|
||||
}, [selectedStock])
|
||||
|
||||
// 실시간 평가손익/총자산 — livePrices 기반 매 틱마다 재계산
|
||||
// 실시간 주식평가금액/손익 — livePrices tick 기반 재계산
|
||||
// total_assets = KIS API 기준값(예수금+주식+미수 등) 사용, 주식 평가분만 live 반영
|
||||
const liveSummary = useMemo(() => {
|
||||
if (!portfolioSummary || !portfolio) return portfolioSummary
|
||||
|
||||
// live 현재가 기반 주식 평가금액
|
||||
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
|
||||
|
||||
// 총 자산 = 예수금(KIS 기준) + 주식 평가금액(live)
|
||||
// KIS API total_assets가 있으면 그 예수금 부분만 분리해서 live 주식값 합산
|
||||
const availableCash = portfolioSummary.available_cash || 0
|
||||
const liveTotal = availableCash + liveValue
|
||||
|
||||
return {
|
||||
...portfolioSummary,
|
||||
total_value: liveValue,
|
||||
total_investment: totalInvestment,
|
||||
total_profit_loss: liveProfitLoss,
|
||||
total_profit_loss_rate: liveProfitLossRate,
|
||||
total_assets: (portfolioSummary.available_cash || 0) + liveValue,
|
||||
total_assets: liveTotal,
|
||||
}
|
||||
}, [portfolioSummary, portfolio, livePrices])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user