fix(ledger): 修复历史净值双重汇率折算 bug 与汇率时间查询边界

This commit is contained in:
2026-05-02 17:22:32 +08:00
parent b76a6ef577
commit 7cdee75bb9
4 changed files with 18 additions and 9 deletions
+3 -5
View File
@@ -242,10 +242,10 @@ async function buildDailyRatesMap(targetDateStr: string): Promise<Record<string,
function getClosestRateForDate(currencyPair: string): string | null {
const records = ratesCache.get(currencyPair);
if (!records || records.length === 0) return null;
const targetDt = new Date(targetDateStr + 'T00:00:00Z');
const endOfDay = new Date(targetDateStr + 'T23:59:59.999');
let closest: RateRecord | null = null;
for (const rec of records) {
if (rec.fetchTime <= targetDt) {
if (rec.fetchTime <= endOfDay) {
closest = rec;
} else {
break;
@@ -395,9 +395,7 @@ export async function reconstructPortfolioHistory() {
const metrics = calculateAssetMetrics(assetTxs, priceStrForMetrics);
const posValueCny = new Big(metrics.marketValue).times(snapshotFxRate);
const posCostCny = new Big(metrics.marketValue)
.minus(metrics.accumulatedPnl)
.times(snapshotFxRate);
const posCostCny = new Big(metrics.accumulatedCost || '0');
totalValueCny = totalValueCny.plus(posValueCny);
totalCostCny = totalCostCny.plus(posCostCny);