问题描述
这是我从 Alpha Vantage API 获取 2 年日内数据的代码。
from alpha_vantage.timeseries import TimeSeries
import csv
import time
API_key = 'XXXXXXXXXXXXXXXXX'
ticker = 'AAPL'
ts = TimeSeries(key=API_key,output_format='csv')
for yr in range(2):
for mo in range(12):
data = ts.get_inTraday_extended(ticker,interval='15min',slice='year'+str(yr+1)+'month'+str(mo+1))
with open(ticker+'.csv','a',newline='') as write_csvfile:
writer = csv.writer(write_csvfile,dialect='excel')
for row in data[0]:
writer.writerow(row)
time.sleep(15)
我不认为起止时间是我的代码造成的。证券交易所的上午 4:00 - 晚上 20:00 的间隔时间正常吗?
解决方法
此 API 返回指定股票的日内时间序列,涵盖适用的延长交易时间(例如,美国市场东部时间上午 4:00 至晚上 8:00)。
我没有看到限制(核心)市场时间的切换,但您可以在检索后自己细分到市场时间。我使用 one of the accessor packages:
从 R(我更经常使用)得到相同的结果
renderPrint({
df_with_cluster <- cbind(svd_dimen_all_wide,cluster = km.res()$cluster)
df_with_cluster <- rownames_to_column(df_with_cluster,"country")
df_with_cluster <- df_with_cluster %>%
select(country,cluster,everything())
head(df_with_cluster)
})
第一个半小时是从04:00到04:30,用4:30时间戳汇总,前一天的最后一个是20:00h。数据集末尾相同(上周五):
### Comparison of Countries on Yes% of Bi Words
```{r}
renderPlot({
world_data %>%
left_join((df_with_cluster %>%
mutate(country_code = countrycode(country,"country.name","iso2c"))
),by = c("country_code")) %>%
filter(!is.na(cluster)) %>%
ggplot(aes(x = long,y = lat,group = group,fill = as.factor(cluster))) +
geom_polygon() +
theme_map() +
scale_fill_discrete() +
labs(fill = "cluster",title = "World Clusters based on UN voting",caption = "created by ViSa") +
theme(plot.title = element_text(face = "bold",size = 16))
})
```