fix(ledger): 彻底修复时光机汇率双标幻觉,同步市值与本金的 CNY 折算
This commit is contained in:
@@ -333,14 +333,18 @@ export async function reconstructPortfolioHistory() {
|
||||
const priceStrForMetrics = priceStr || assetLatestPriceMap.get(assetId) || '0';
|
||||
|
||||
const metrics = calculateAssetMetrics(assetTxs, priceStrForMetrics);
|
||||
|
||||
// 获取资产对人民币的汇率
|
||||
|
||||
// 1. 获取基础币种数据
|
||||
// 2. 获取当前资产的汇率 (必须确保能获取到,比如从 asset 表或 rateMap)
|
||||
const assetFxRate = new Big(getRate(baseCurrency, 'CNY') || '1');
|
||||
|
||||
// 统一汇率折算边界:calculateAssetMetrics 输出全部为 Base Currency,
|
||||
// 必须无例外地将所有金额字段乘以 fxRate 得到 CNY
|
||||
|
||||
// 3. 【核心修复】:市值和本金,必须双双乘以汇率!
|
||||
const posValueCny = new Big(metrics.marketValue).times(assetFxRate);
|
||||
const posCostCny = new Big(metrics.totalInvested).times(assetFxRate);
|
||||
|
||||
// 投入本金 = (市值 - 累计盈亏) * 汇率,确保逻辑自洽
|
||||
const posCostCny = new Big(metrics.marketValue)
|
||||
.minus(metrics.accumulatedPnl)
|
||||
.times(assetFxRate);
|
||||
|
||||
totalValueCny = totalValueCny.plus(posValueCny);
|
||||
totalCostCny = totalCostCny.plus(posCostCny);
|
||||
|
||||
Reference in New Issue
Block a user