alphavantage
alphavantage copied to clipboard
Polished date (ISO string) can have incorrect timezone offset applied
On time series data returned from the API, the util.polish()
routine may apply an incorrect timezone offset to the date time string when compared to the data["Meta Data"]["6. Time Zone"]
attribute returned in the raw data.
Example
Tested on v2.3.0
Raw Response
Notice the time zone is US/Eastern
and that means the series key is 18th at 8pm Eastern time
{
"Meta Data": {
"1. Information": "Intraday (30min) open, high, low, close prices and volume",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2022-07-18 20:00:00",
"4. Interval": "30min",
"5. Output Size": "Full size",
"6. Time Zone": "US/Eastern"
},
"Time Series (30min)": {
"2022-07-18 20:00:00": {
"1. open": "254.6000",
"2. high": "255.2000",
"3. low": "254.6000",
"4. close": "255.0200",
"5. volume": "7262"
},
...
}
Polished Response Notice the series key is 18th at 7pm with a Zulu zone, or UTC. This will mean a 5 hour difference to the correct time of the data point.
{
"meta": {
"information": "Intraday (30min) open, high, low, close prices and volume",
"symbol": "MSFT",
"updated": "2022-07-18 20:00:00",
"interval": "30min",
"size": "Full size",
"zone": "US/Eastern"
},
"Time Series (30min)": {
"2022-07-18T19:00:00.000Z": {
"open": "254.6000",
"high": "255.2000",
"low": "254.6000",
"close": "255.0200",
"volume": "7262"
},
...
}
Ideally the ISO string should contain the offset to UTC, e.g. 2022-07-18T20:00:00.000-04:00
, so it can be correctly parsed.
Testing code
const alpha = require('alphavantage')({ key: 'mykey' });
alpha.data.intraday("MSFT", "full", "json", "30min").then((data) => {
console.log(`data: ${JSON.stringify(data, null, 4)}`);
console.log(`polish: ${JSON.stringify(alpha.util.polish(data), null, 4)}`);
}).catch((e) => {
console.log(`e ${JSON.stringify(e, null, 4)}`)
})
Brilliant