fix(ledger): 修复历史净值双重汇率折算 bug 与汇率时间查询边界
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user