正如标题所说,我正在寻找股票信息的替代来源,因为雅虎已经禁用了许多人一直在使用的API。我一直在查看的新源代码在这里找到:https://iextrading.com/developer/
我的问题是如何将数据实际导入到Excel中…我正在考虑通过VBA,因为这是我用来从雅虎获得数据的工具。然而,我认为我想要做的事情远远超出了我目前的能力……我也尝试过使用Excel的WEBSERVICE()函数来简单地查看价格:https://api.iextrading.com/1.0/stock/aapl/price,但这不起作用。据我所知,IEX已经为我们免费提供了大量的数据,我只是不知道如何访问它们。我之所以使用VBA,是因为我能够使用工作簿中的输入列表来显示报价器,并且能够将这种数据访问放在许多工作簿中。任何帮助都是非常感谢的。此外,任何关于我可以从哪里开始学习这一点的方向都同样受欢迎。谢谢。
更新:我的评论中提到的代码
Function StockPrice(ticker As String, item As String) As Double
Dim strURL As String, strCSV As Double, itemFound As Integer, tag As String
itemFound = 0
If item = "lastprice" Then
tag = "price"
itemFound = 1
ElseIf item = "pe" Then
tag = "peRatio"
itemFound = 1
End If
If itemFound = 1 Then
strURL = "https://api.iextrading.com/1.0/stock/" & ticker & "/" & tag
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
XMLHTTP.Open "GET", strURL, False
XMLHTTP.send
StockPrice = XMLHTTP.responseText
Set XMLHTTP = Nothing
Else
StockPrice = "Item Not Found"
End If
End Function
发布于 2017-11-17 05:12:14
我想我基本上解决了这个问题。这是任何感兴趣的人的代码。这是对那些使用雅虎财经的API的直接替代。
Function StockPrice(ticker As String, item As String)
Dim strURL As String, strCSV As Double, itemFound As Integer, tag As String
itemFound = 0
If item = "lastprice" Then
tag = "latestPrice"
itemFound = 1
ElseIf item = "pe" Then
tag = "peRatio"
itemFound = 1
ElseIf item = "company" Then
tag = "companyName"
itemFound = 1
ElseIf item = "sector" Then
tag = "sector"
itemFound = 1
ElseIf item = "open" Then
tag = "open"
itemFound = 1
ElseIf item = "yclose" Then
tag = "previousClose"
itemFound = 1
ElseIf item = "change" Then
tag = "change"
itemFound = 1
ElseIf item = "%change" Then
tag = "changePercent"
itemFound = 1
ElseIf item = "marketcap" Then
tag = "marketCap"
itemFound = 1
ElseIf item = "52high" Then
tag = "week52High"
itemFound = 1
ElseIf item = "52low" Then
tag = "week52Low"
itemFound = 1
End If
If itemFound = 1 Then
strURL = "https://api.iextrading.com/1.0/stock/" & ticker & "/quote/" & tag
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
XMLHTTP.Open "GET", strURL, False
XMLHTTP.send
StockPrice = XMLHTTP.responseText
Set XMLHTTP = Nothing
Else
StockPrice = "Item Not Found"
End If
End Function
IEX的功能比我在这里构建的功能多得多。只是没有足够的经验来构建它。点击这里查看这些功能:https://iextrading.com/developer/docs/
发布于 2017-11-17 00:21:26
这可能有点简单,但这是一个开始:
Sub IEX()
Dim Price As Single
Price = Application.WebService("https://api.iextrading.com/1.0/stock/aapl/price")
End Sub
发布于 2018-01-05 08:41:37
在一个单元格(本例中为单元格E3 )中使用记号符号,在另一个单元格中输入以下内容:
=WEBSERVICE("https://api.iextrading.com/1.0/stock/" & E3 & "/quote/delayedPrice")
适用于Office 365的Excel。
https://stackoverflow.com/questions/47333894
复制相似问题