From 7922655af4ae6bbc74a0ba4544bdbbfdc4765f98 Mon Sep 17 00:00:00 2001 From: mnsrulz Date: Sun, 10 Nov 2024 20:43:23 -0500 Subject: [PATCH] calculation of price at given date failed --- src/app/api/symbols/[symbol]/historical/route.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/api/symbols/[symbol]/historical/route.ts b/src/app/api/symbols/[symbol]/historical/route.ts index 9ff9e81..d4e620d 100644 --- a/src/app/api/symbols/[symbol]/historical/route.ts +++ b/src/app/api/symbols/[symbol]/historical/route.ts @@ -40,11 +40,11 @@ const getPriceAtDate = async (symbol: string, dt: string) => { const resp = await yf.historical(symbol, { interval: '1d', - period1: start, + period1: dayjs(start).add(-7, 'day').toDate(), //in case of weekend it somehow blanking out period2: new Date() }); - return resp.at(0)?.open.toFixed(2); + return resp.at(-1)?.close.toFixed(2); } function isUSMarketOpenedForToday(): boolean {