我是雅虎财经API难民(他们停止他们的API服务)尝试切换到阿尔法华帝。 我修改了以前用于Yahoo Finance的以下代码,但我在Excel中遇到了#VALUE错误。阿尔法华帝:使用Excel VBA拉从CSV文件中的数据
以下作品的网址本身(它会打开一个CSV如果你输入到你的网页浏览器),所以我想我真正的问题在于提取的CSV正确的数据到我的Excel电子表格。任何人都可以提供帮助吗?
我试图从CSV提取第2行,第5列数据(最后的收盘价)。提前谢谢了!
Function StockClose(Ticker As String)
Dim URL As String, CSV As String, apikey As String, SCRows() As String, SCColumns() As String, pxClose As Double
apikey = "*censored*"
URL = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" & Ticker & "&outputsize=full&" & apikey & "&datatype=csv"
Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
xmlhttp.Open "GET", URL, False
xmlhttp.Send
CSV = xmlhttp.responseText
'split the CSV into rows
SCRows() = Split(CSV, Chr(10))
'split the relevant row into columns. 0 means 1st row, starting at index 0
SCColumns() = Split(SCRows(1), ",")
'6 means: 5th column; starting at index 0 - price close is in the 5th column
pxClose = SCColumns(6)
StockClose = pxClose
Set http = Nothing
End Function
样本数据的返回,如果我提取JSON而不是CSV:
{ “元数据”:{ “1信息”:“每日价格(开盘,高,低,“关闭”和“卷” “2.符号”:“SGD = X”, “3.最后刷新”:“2017-11-10”, “4.输出尺寸”:“全尺寸”, “5.时区”:“美国/东部” }, “时间序列(每日)”:{ “201 7-11-13“:{ ”1。打开“:”1.3588“, ”2。高“:”1.3612“, ”3。低“:”1.3581“, ”4。关闭“:”1.3587“, ”5。体积“:”0“ }, ”2017-11-10“:{ ”打开“:”1.3588“, ”2。高“:”1.3612“, ”3。低“:”1.3581“, ”4。关闭“:”1.3587“, ”5。卷“:‘0’ },
检查[这个答案](https://stackoverflow.com/a/43969543/2165759),它可以帮助你与雅虎财经的API来管理。 – omegastripes