Any automation software to pull the data from fundamental explorer?

Discussion in 'Interactive Brokers' started by emk662, Feb 11, 2025.

  1. emk662

    emk662

    Hello, I like to get financial data such as total revenue from TWS Fundamental explorer. It used to have an API function that can work, but now that function is deprecated. I can manually open the fundamental explorer to get the data, but was wondering if it can be done using a software or a smart way, since I have a long list of stocks.

    Thanks.
     

  2. Have you tried the "Wall Street Horizon" methods?

    https://www.interactivebrokers.com/campus/ibkr-api-page/twsapi-doc/#wsh

    You will need to activate your subscription to the service first.
     
  3. ZBZB

    ZBZB

    Ask finchat.io
     
  4. emk662

    emk662

    Drawdown Addict likes this.
  5. Peter8519

    Peter8519

    You can download the total revenue data from yahoo finance using Excel VBA.
    Here is the Excel VBA script.

    Sub Scrape_Yahoo_Finance()

    Dim i As Integer
    Dim my_doc As Object
    Dim my_url As String
    Const yahoo_url = "https://finance.yahoo.com/quote/XXXXX/financials/"

    Dim XMLpage As New MSXML2.XMLHTTP60
    Dim HTMLdoc As New MSHTML.htmlDocument

    ThisWorkbook.Sheets("Sheet1").Columns("B:B").Clear
    ThisWorkbook.Sheets("Sheet1").Cells(1, 2) = "Total Revenue"
    i = 2

    While ThisWorkbook.Sheets("Sheet1").Cells(i, 1) <> ""
    my_url = Replace(yahoo_url, "XXXXX", ThisWorkbook.Sheets("Sheet1").Cells(i, 1))

    XMLpage.Open "GET", my_url, False
    XMLpage.send
    HTMLdoc.body.innerHTML = XMLpage.responseText
    my_doc = HTMLdoc.getElementsByClassName("tableBody yf-9ft13")

    ThisWorkbook.Sheets("Sheet1").Cells(i, 2) = my_doc.childNodes.Item(1).childNodes.Item(3).innerText

    i = i + 1
    Wend

    End Sub

    In the Excel VBA editor, go to Tools -> Reference and check the following.
    upload_2025-2-12_3-23-30.png

    In the Excel Sheet1, row 1,col1 = Ticker. From row2, col1 onwards is your ticker symbol.
    upload_2025-2-12_3-27-21.png
     
  6. emk662

    emk662

    Thanks so much.
     
  7. You might want to look into web scraping tools like Selenium or BeautifulSoup, but be sure to check Interactive Brokers' terms of service. Another option is third-party financial data APIs like Alpha Vantage, Yahoo Finance, or Finnhub, which might provide the data you need without manual work.
     
  8. Peter8519

    Peter8519

    I rerun the Excel macro and it has error. Here is the fully debugged script.

    Sub Finance_Stats()

    Dim i As Integer
    Dim my_doc As Object
    Dim my_url As String
    Const yahoo_url = "https://finance.yahoo.com/quote/XXXXX/financials/"

    Dim XMLpage As New MSXML2.XMLHTTP60
    Dim HTMLdoc As New MSHTML.htmlDocument

    ThisWorkbook.Sheets("Sheet1").Columns("B:C").Clear
    ThisWorkbook.Sheets("Sheet1").Cells(1, 2) = "Total Revenue"
    ThisWorkbook.Sheets("Sheet1").Cells(1, 3) = "Diluted EPS(TTM)"
    i = 2

    While ThisWorkbook.Sheets("Sheet1").Cells(i, 1) <> ""

    'Update URL with ticker symbol
    my_url = Replace(yahoo_url, "XXXXX", ThisWorkbook.Sheets("Sheet1").Cells(i, 1))

    XMLpage.Open "GET", my_url, False
    XMLpage.send

    'Wait till page fully loaded
    While XMLpage.Status <> 200
    Application.Wait (Now + TimeValue("0:00:01"))
    Wend

    HTMLdoc.body.innerHTML = XMLpage.responseText
    Set my_doc = HTMLdoc.getElementsByClassName("tableBody yf-9ft13")
    ThisWorkbook.Sheets("Sheet1").Cells(i, 2) = my_doc(0).ChildNodes.Item(1).ChildNodes.Item(3).innerText
    ThisWorkbook.Sheets("Sheet1").Cells(i, 3) = my_doc(0).ChildNodes.Item(25).ChildNodes.Item(2).innerText
    i = i + 1
    Wend

    End Sub
     
  9. emk662

    emk662

    Hello, thanks so much. Can you also show how to get the average earnings estimate (under analysis) for the current year?


     
  10. 2rosy

    2rosy

    python version.

    Code:
    import yfinance as yf
    
    yf.Ticker("MSFT").earnings_estimate
     
    #10     Feb 12, 2025