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 -3
View File
@@ -48,10 +48,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;
@@ -222,7 +222,7 @@ export async function GET(req: Request) {
const fxNum = snapshotFxRate;
const calcMarketValueCny = holding.quantity.times(priceNum).times(fxNum);
const calcCostCny = holding.totalCost.times(fxNum);
const calcCostCny = holding.totalCost;
totalMarketValue = totalMarketValue.plus(calcMarketValueCny);
totalCost = totalCost.plus(calcCostCny);