From 35222fbf26c00bd5cdb3f954321a7aae4ea486c3 Mon Sep 17 00:00:00 2001 From: claw_bot Date: Tue, 10 Mar 2026 03:33:58 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=84=E5=90=88=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E6=94=AF=E6=8C=81=E5=A4=9A=E5=B8=81=E7=A7=8D=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E6=B1=87=E7=8E=87=E6=8D=A2=E7=AE=97=EF=BC=8C=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E8=BD=AC=E6=8D=A2=E4=B8=BA=E7=BB=84=E5=90=88=E6=9C=AC?= =?UTF-8?q?=E4=BD=8D=E5=B8=81=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AssetManager.Services/PortfolioService.cs | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/AssetManager.Services/PortfolioService.cs b/AssetManager.Services/PortfolioService.cs index 9c8f6a7..bcaf145 100644 --- a/AssetManager.Services/PortfolioService.cs +++ b/AssetManager.Services/PortfolioService.cs @@ -214,7 +214,8 @@ public class PortfolioService : IPortfolioService .Where(pos => pos.PortfolioId == id) .ToList(); - // 获取每个持仓的实时价格并计算 + // 获取每个持仓的实时价格并转换为组合本位币 + string targetCurrency = portfolio.Currency ?? "CNY"; decimal totalPortfolioValue = 0; decimal totalCost = 0; decimal totalTodayProfit = 0; @@ -238,9 +239,14 @@ public class PortfolioService : IPortfolioService double profitRate = cost > 0 ? (double)(profit / cost * 100) : 0; decimal todayProfit = previousClose > 0 ? pos.Shares * (currentPrice - previousClose) : 0; - totalPortfolioValue += positionValue; - totalCost += cost; - totalTodayProfit += todayProfit; + // 转换为组合本位币 + decimal positionValueInTarget = await _exchangeRateService.ConvertAmountAsync(positionValue, pos.Currency, targetCurrency); + decimal costInTarget = await _exchangeRateService.ConvertAmountAsync(cost, pos.Currency, targetCurrency); + decimal todayProfitInTarget = await _exchangeRateService.ConvertAmountAsync(todayProfit, pos.Currency, targetCurrency); + + totalPortfolioValue += positionValueInTarget; + totalCost += costInTarget; + totalTodayProfit += todayProfitInTarget; positionItems.Add(new PositionItem { @@ -251,13 +257,13 @@ public class PortfolioService : IPortfolioService amount = (int)pos.Shares, averagePrice = (double)pos.AvgPrice, currentPrice = (double)currentPrice, - totalValue = (double)positionValue, - profit = (double)profit, + totalValue = (double)positionValueInTarget, + profit = (double)(positionValueInTarget - costInTarget), profitRate = profitRate, - changeAmount = (double)todayProfit, + changeAmount = (double)todayProfitInTarget, ratio = 0, // 后面统一计算比例 deviationRatio = 0, // 后续实现 - currency = pos.Currency + currency = targetCurrency }); } @@ -274,7 +280,7 @@ public class PortfolioService : IPortfolioService { id = portfolio.Id, name = portfolio.Name, - currency = portfolio.Currency, + currency = targetCurrency, status = portfolio.Status, strategy = new StrategyInfo { @@ -287,7 +293,7 @@ public class PortfolioService : IPortfolioService todayProfit = (double)totalTodayProfit, historicalChange = totalReturnRate, dailyVolatility = 0, // 后续实现 - todayProfitCurrency = portfolio.Currency, + todayProfitCurrency = targetCurrency, logicModel = "HFEA 风险平价逻辑", logicModelStatus = "监控中", logicModelDescription = "目标权重 季度调仓",