feat: 组合详情页支持多币种实时汇率换算,统一转换为组合本位币显示
This commit is contained in:
parent
ba60dbc72c
commit
35222fbf26
@ -214,7 +214,8 @@ public class PortfolioService : IPortfolioService
|
|||||||
.Where(pos => pos.PortfolioId == id)
|
.Where(pos => pos.PortfolioId == id)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// 获取每个持仓的实时价格并计算
|
// 获取每个持仓的实时价格并转换为组合本位币
|
||||||
|
string targetCurrency = portfolio.Currency ?? "CNY";
|
||||||
decimal totalPortfolioValue = 0;
|
decimal totalPortfolioValue = 0;
|
||||||
decimal totalCost = 0;
|
decimal totalCost = 0;
|
||||||
decimal totalTodayProfit = 0;
|
decimal totalTodayProfit = 0;
|
||||||
@ -238,9 +239,14 @@ public class PortfolioService : IPortfolioService
|
|||||||
double profitRate = cost > 0 ? (double)(profit / cost * 100) : 0;
|
double profitRate = cost > 0 ? (double)(profit / cost * 100) : 0;
|
||||||
decimal todayProfit = previousClose > 0 ? pos.Shares * (currentPrice - previousClose) : 0;
|
decimal todayProfit = previousClose > 0 ? pos.Shares * (currentPrice - previousClose) : 0;
|
||||||
|
|
||||||
totalPortfolioValue += positionValue;
|
// 转换为组合本位币
|
||||||
totalCost += cost;
|
decimal positionValueInTarget = await _exchangeRateService.ConvertAmountAsync(positionValue, pos.Currency, targetCurrency);
|
||||||
totalTodayProfit += todayProfit;
|
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
|
positionItems.Add(new PositionItem
|
||||||
{
|
{
|
||||||
@ -251,13 +257,13 @@ public class PortfolioService : IPortfolioService
|
|||||||
amount = (int)pos.Shares,
|
amount = (int)pos.Shares,
|
||||||
averagePrice = (double)pos.AvgPrice,
|
averagePrice = (double)pos.AvgPrice,
|
||||||
currentPrice = (double)currentPrice,
|
currentPrice = (double)currentPrice,
|
||||||
totalValue = (double)positionValue,
|
totalValue = (double)positionValueInTarget,
|
||||||
profit = (double)profit,
|
profit = (double)(positionValueInTarget - costInTarget),
|
||||||
profitRate = profitRate,
|
profitRate = profitRate,
|
||||||
changeAmount = (double)todayProfit,
|
changeAmount = (double)todayProfitInTarget,
|
||||||
ratio = 0, // 后面统一计算比例
|
ratio = 0, // 后面统一计算比例
|
||||||
deviationRatio = 0, // 后续实现
|
deviationRatio = 0, // 后续实现
|
||||||
currency = pos.Currency
|
currency = targetCurrency
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +280,7 @@ public class PortfolioService : IPortfolioService
|
|||||||
{
|
{
|
||||||
id = portfolio.Id,
|
id = portfolio.Id,
|
||||||
name = portfolio.Name,
|
name = portfolio.Name,
|
||||||
currency = portfolio.Currency,
|
currency = targetCurrency,
|
||||||
status = portfolio.Status,
|
status = portfolio.Status,
|
||||||
strategy = new StrategyInfo
|
strategy = new StrategyInfo
|
||||||
{
|
{
|
||||||
@ -287,7 +293,7 @@ public class PortfolioService : IPortfolioService
|
|||||||
todayProfit = (double)totalTodayProfit,
|
todayProfit = (double)totalTodayProfit,
|
||||||
historicalChange = totalReturnRate,
|
historicalChange = totalReturnRate,
|
||||||
dailyVolatility = 0, // 后续实现
|
dailyVolatility = 0, // 后续实现
|
||||||
todayProfitCurrency = portfolio.Currency,
|
todayProfitCurrency = targetCurrency,
|
||||||
logicModel = "HFEA 风险平价逻辑",
|
logicModel = "HFEA 风险平价逻辑",
|
||||||
logicModelStatus = "监控中",
|
logicModelStatus = "监控中",
|
||||||
logicModelDescription = "目标权重 季度调仓",
|
logicModelDescription = "目标权重 季度调仓",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user