Skip to content

Commit

Permalink
fix getPriceAtDate to return approrpriate price data
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsrulz committed Nov 12, 2024
1 parent 63ae5cb commit aef80a2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/app/api/symbols/[symbol]/historical/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ const getPriceAtDate = async (symbol: string, dt: string) => {
return resp.pop()?.close?.toFixed(2);
}
}

//TODO: need to revisit this logic as it can potentially cause issues if market is still open since there might not be any close price available

const resp = await yf.historical(symbol, {
interval: '1d',
period1: dayjs(start).add(-7, 'day').toDate(), //in case of weekend it somehow blanking out
period2: new Date()
period2: dayjs(start).toDate()
});

return resp.at(-1)?.close.toFixed(2);
Expand Down

0 comments on commit aef80a2

Please sign in to comment.