2

我可以在 Alpha Vantage API 的结果中更改时区吗?这是输出的示例。它目前在美国东部时间。我想在 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'
    },
4

2 回答 2

3

欢迎来到 StackOverflow!

现在返回的时区是您将从 API 收到的唯一时区。但是,如果您使用 python 脚本提取数据。您始终可以将其转换为您选择的时区。

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))

您可以运行一种方法,在提取数据时将所有时间转换为您想要的任何时区

于 2019-11-01T15:42:55.343 回答
0

ts.get_daily('TSLA')应改为ts.get_intraday('TSLA').

于 2020-03-23T12:56:20.097 回答