2

Can I change the time zone in the result from Alpha Vantage API? Here is an example of the output. It's currently in EST. I'd like to get it in IST.

'Meta Data': {
    '1. Information': 'Intraday (1min) open, high, low, close prices and volume',
    '2. Symbol': 'BSE:------',
    '3. Last Refreshed': '2019-11-01',
    '4. Output Size': 'Compact',
    '5. Time Zone': 'US/Eastern
}

'Time Series (1min)': {
    '2019-11-01 00:08:59': {
      '1. open': '70.7500',
      '2. high': '70.7500',
      '3. low': '70.7500',
      '4. close': '70.7500',
      '5. volume': '0'
    },
Patrick Collins
  • 5,621
  • 3
  • 26
  • 64

2 Answers2

4

Welcome to StackOverflow!

Right now the time zone that is returned is the only time zone you will receive from the API. However, if you're pulling the data in with a python script. You can always convert it to your time zone of choice.

from alpha_vantage.timeseries import TimeSeries
from datetime import datetime
import pytz

ts = TimeSeries()

data, meta_data = ts.get_daily('TSLA')
format = '%Y-%m-%d %H:%M:%S'

datetime = datetime.strptime(meta_data['3. Last Refreshed'], format)
old_timezone = pytz.timezone(meta_data['5. Time Zone'])
new_timezone = pytz.timezone("Asia/Calcutta")

# returns datetime in the new timezone
my_timestamp_in_new_timezone = old_timezone.localize(datetime).astimezone(new_timezone) 
print(my_timestamp_in_new_timezone.strftime(format))

You could run a method that just converts all the times to whatever timezone you want when you pull the data

Patrick Collins
  • 5,621
  • 3
  • 26
  • 64
0

ts.get_daily('TSLA') should be changed to ts.get_intraday('TSLA').

dspencer
  • 4,297
  • 4
  • 22
  • 43
mnn0
  • 1