gadicc / node-yahoo-finance2

Unofficial API for Yahoo Finance
https://www.npmjs.com/package/yahoo-finance2
MIT License
353 stars 58 forks source link

Incorrect timestamp in chart data #762

Closed NarendranKT closed 2 months ago

NarendranKT commented 2 months ago

Bug Report

BUG

I tried on getting past 7 days report of NIFTY50 stock OHLC data for plotting in chart but timestamp in the response data is fixed to JAN 20. Can you fix it or is there any solution pls reply back!

`try { const symbol = req.params.symbol

    const sevenDaysAgo = new Date(Date.now() - 1 * 24 * 60 * 60 * 1000)
    const query = symbol;
    console.log(sevenDaysAgo);
    const queryOptions = {
        period1: sevenDaysAgo,
        period2: Date.now(),
        interval: "1m",
        return: "object"
    };
    const chart = await yahooFinance.chart(query, queryOptions);

    res.json({
        chart
    })
} catch (error) {
    res.json(error.message);
}`

SAMPLE TRADING PREIOD

"tradingPeriods": { "pre": [ [ { "timezone": "IST", "start": "2024-04-03T03:45:00.000Z", "end": "2024-04-03T03:45:00.000Z", "gmtoffset": 19800 } ] ], "post": [ [ { "timezone": "IST", "start": "2024-04-03T10:00:00.000Z", "end": "2024-04-03T10:00:00.000Z", "gmtoffset": 19800 } ] ], "regular": [ [ { "timezone": "IST", "start": "2024-04-03T03:45:00.000Z", "end": "2024-04-03T10:00:00.000Z", "gmtoffset": 19800 } ] ] }

In this trading periods date were correct but timestamp data is set to Jan 20

Timestamp data example

"timestamp": [
      1712115900,
      1712115960,
      1712116020,
      1712116080,
      1712116140]

console.log(new Date(1712115900));
//OUTPUT : 1970-01-20T19:35:15.900Z

image

NarendranKT commented 2 months ago

sorry for inconvince, I forgot to multiply the timestamp with 1000.