대시보드 수정및 전략수정중
This commit is contained in:
@@ -25,12 +25,21 @@ export const PortfolioSummary = ({ summary, error }: PortfolioSummaryProps) => {
|
||||
);
|
||||
}
|
||||
|
||||
const { total_assets, total_value, total_investment, total_profit_loss, total_profit_loss_rate, available_cash } = summary;
|
||||
const isProfit = total_profit_loss >= 0;
|
||||
const {
|
||||
total_assets,
|
||||
total_value, // 주식 평가금액
|
||||
total_investment, // 총 매입금액
|
||||
total_profit_loss,
|
||||
total_profit_loss_rate,
|
||||
available_cash, // 예수금 (현금)
|
||||
} = summary;
|
||||
const isProfit = (total_profit_loss ?? 0) >= 0;
|
||||
|
||||
const fmt = (v: number) => Math.round(v || 0).toLocaleString();
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6">
|
||||
{/* 총 자산 */}
|
||||
{/* 총 자산 (예수금 + 주식평가) */}
|
||||
<div className="bg-gray-800/50 backdrop-blur-sm border border-gray-700/50 p-5 rounded-xl">
|
||||
<div className="flex justify-between items-start mb-2">
|
||||
<p className="text-gray-400 text-sm font-medium">총 자산</p>
|
||||
@@ -39,25 +48,23 @@ export const PortfolioSummary = ({ summary, error }: PortfolioSummaryProps) => {
|
||||
</div>
|
||||
</div>
|
||||
<h3 className="text-2xl font-bold text-white mb-1">
|
||||
{Math.round(total_assets || 0).toLocaleString()}원
|
||||
{fmt(total_assets)}원
|
||||
</h3>
|
||||
<div className="flex flex-col gap-0.5 text-xs text-gray-400">
|
||||
<span>예수금: {Math.round(available_cash || 0).toLocaleString()}원</span>
|
||||
<span>평가금액: {Math.round(total_value || 0).toLocaleString()}원</span>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">예수금 + 주식평가</p>
|
||||
</div>
|
||||
|
||||
{/* 총 매입금액 */}
|
||||
{/* 예수금 (현금) */}
|
||||
<div className="bg-gray-800/50 backdrop-blur-sm border border-gray-700/50 p-5 rounded-xl">
|
||||
<div className="flex justify-between items-start mb-2">
|
||||
<p className="text-gray-400 text-sm font-medium">총 매입금액</p>
|
||||
<p className="text-gray-400 text-sm font-medium">예수금</p>
|
||||
<div className="p-2 bg-purple-500/10 rounded-lg text-purple-400">
|
||||
<Activity size={18} />
|
||||
</div>
|
||||
</div>
|
||||
<h3 className="text-2xl font-bold text-white mb-1">
|
||||
{Math.round(total_investment || 0).toLocaleString()}원
|
||||
{fmt(available_cash)}원
|
||||
</h3>
|
||||
<p className="text-xs text-gray-500">주식평가: {fmt(total_value)}원</p>
|
||||
</div>
|
||||
|
||||
{/* 총 평가손익 */}
|
||||
@@ -69,8 +76,9 @@ export const PortfolioSummary = ({ summary, error }: PortfolioSummaryProps) => {
|
||||
</div>
|
||||
</div>
|
||||
<h3 className={`text-2xl font-bold mb-1 ${isProfit ? 'text-red-400' : 'text-blue-400'}`}>
|
||||
{total_profit_loss > 0 ? '+' : ''}{Math.round(total_profit_loss || 0).toLocaleString()}원
|
||||
{(total_profit_loss ?? 0) > 0 ? '+' : ''}{fmt(total_profit_loss)}원
|
||||
</h3>
|
||||
<p className="text-xs text-gray-500">매입: {fmt(total_investment)}원</p>
|
||||
</div>
|
||||
|
||||
{/* 수익률 */}
|
||||
@@ -82,8 +90,9 @@ export const PortfolioSummary = ({ summary, error }: PortfolioSummaryProps) => {
|
||||
</div>
|
||||
</div>
|
||||
<h3 className={`text-2xl font-bold mb-1 ${isProfit ? 'text-red-400' : 'text-blue-400'}`}>
|
||||
{total_profit_loss_rate > 0 ? '+' : ''}{total_profit_loss_rate?.toFixed(2)}%
|
||||
{(total_profit_loss_rate ?? 0) > 0 ? '+' : ''}{(total_profit_loss_rate ?? 0).toFixed(2)}%
|
||||
</h3>
|
||||
<p className="text-xs text-gray-500">주식 매입 대비</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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