2

正如标题所说,我正在寻找股票信息的替代来源,因为雅虎已经禁用了许多人一直在使用的 API。我一直在寻找的新来源可以在这里找到:https ://iextrading.com/developer/

我的问题是如何将数据实际输入 Excel...我正在考虑 VBA,因为这是我用来从 Yahoo 获取数据的方法。但是,我认为我想做的事情远远超出了我目前的能力......我还尝试使用 Excel 的 WEBSERVICE() 函数和以下 URL 来简单地查看价格: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
4

4 回答 4

3

这可能有点简单,但这是一个开始:

Sub IEX()
Dim Price As Single

    Price = Application.WebService("https://api.iextrading.com/1.0/stock/aapl/price")

End Sub
于 2017-11-16T16:21:25.650 回答
2

在一个单元格中使用股票代码(本例中为单元格 E3),在另一个单元格中输入以下内容:

=WEBSERVICE("https://api.iextrading.com/1.0/stock/" & E3 & "/quote/delayedPrice")

适用于 Office 365 的 Excel。

于 2018-01-05T00:41:36.500 回答
2

我想我已经基本解决了这个问题。这是任何有兴趣的人的代码。这可以直接替代使用 Yahoo Finance 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-16T21:12:13.580 回答
0

如果您不需要向后兼容 Yahoo,而只需要一个简单的报价,此 VBA 函数将报价功能添加到 Excel 函数列表中。

它没有经过修饰,但应该作为如何使用强大的 IEX API 的简单示例。使用 VBA 编辑器将其放入模块中:

Public Function tickerPrice(ticker As String)

Dim htmlCmd As String
Dim curlCmd As String
Dim shellCmd As String
Dim sResult As String

htmlCmd = "https://api.iextrading.com/1.0/stock/" & ticker & "/quote/delayedPrice"
curlCmd = "curl \""" & htmlCmd & "\"""
shellCmd = "do shell script "" " & curlCmd & " "" "

sResult = MacScript(shellCmd)

tickerPrice = Val(sResult)

End Function

打开工作簿时请务必启用宏,这样才能正常工作。(这在 2017 年使用 Mac Excel 2011 和 High Sierra 进行了测试。

于 2017-12-31T01:23:14.733 回答