Results 1 to 6 of 6

Thread: Free stock API?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    160

    Question Free stock API?

    Since many of the Windows 7 desktop gadgets no longer work, I wrote one to show me the current prices of my stock holdings. I use the twelvedata.com API for the data and my program is configured to access the API not more than several hundred times per day (which assumes my computer is on for the entire active stock day), so it is not terribly demanding.

    The API worked without issue for several years, but a while ago, it stopped showing the value for the indices DJI, IXIC, and SPX. Today (and I checked this by entering the API URL into my browser), the twelvedata.com API indicated that these index strings are not valid.

    Question: Can anyone suggest a free API that will provide the current-ish value for these indices about 50 times per day? Not sure that this is the proper forum in which this question should be asked, and if you have any ideas of better forums where this can be asked, please share.

  2. #2
    Fanatic Member
    Join Date
    Jul 2022
    Location
    Buford, Ga USA
    Posts
    630

    Re: Free stock API?

    according to Perplexity AI, these are options:

    A good free option is **API Ninjas Stock Price API**: it supports market index prices, including `^DJI`, and free users get 15-minute delayed data, which is usually enough for “current-ish” values about 50 times per day. If you need all three symbols in a single, simple feed, **Twelve Data** is another strong choice because it supports global indices with updates every 1 minute, though its free plan details are more constrained than the paid tiers. [api-ninjas](https://api-ninjas.com/api/stockprice)

    ## Best fit
    - **API Ninjas**: simplest if you want `^DJI`, `^IXIC`, and `^SPX`-style index lookups and can tolerate delayed quotes on the free plan. [api-ninjas](https://api-ninjas.com/api/stockprice)
    - **Twelve Data**: better if you want broader index coverage and more frequent updates, with an indices API designed for real-time/historical pricing. [twelvedata](https://twelvedata.com/indices)
    - **Alpha Vantage**: worth considering for general market data, but it is not the clearest match here for direct U.S. index quotes from the sources I checked. [alphavantage](https://www.alphavantage.co)

    ## Practical note
    For 50 requests per day, rate limits are usually not the issue; the bigger question is whether the provider returns the exact index symbols you want versus requiring a slightly different ticker or a related proxy such as an ETF. For your use case, I’d start with **API Ninjas** and verify that it returns the three indexes in the format you need. [twelvedata](https://twelvedata.com/indices)

    ## Symbol caveat
    Different APIs use different tickers for these indexes. In the sources I found, examples included `^DJI` for the Dow and `^GSPC` for the S&P 500, while Nasdaq Composite coverage depends on the provider’s symbol mapping. [financialdata](https://financialdata.net/index-quotes-api)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    160

    Re: Free stock API?

    Thanks. I will check out API Ninjas - am currently using Twelve Data and it does not provide the desired info.

  4. #4
    Fanatic Member
    Join Date
    Jul 2022
    Location
    Buford, Ga USA
    Posts
    630

    Re: Free stock API?

    You're welcome, hopefully it works out for you.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    160

    Re: Free stock API?

    Dumb question alert! Is there some way to pass the API_KEY via the url? Id not, would someone please point me to an example of how to pass the API_KEY.

    Thanks.

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,372

    Re: Free stock API?

    According to API Ninja's documentation (link), you need to set the X-Api-Key header.

    Here is an untested example:
    Code:
    Public Async Function GetStockPrice(ticker As String) As Task(Of String)
        If (String.IsNullOrWhitespace(ticker)) Then
            Throw ArgumentOutOfRangeException(NameOf(ticker))
        End If
    
        Dim baseUrl As String = "https://api.api-ninjas.com/v1/stockprice"
        Dim query As NameValueCollection = HttpUtility.ParseQueryString($"ticker={ticker}")
        Dim url As String = $"{baseUrl}?{query.ToString()}"
        Dim apiKey As String = "CHANGE ME"
    
        Using client As New HttpClient()
            Using request As New HttpRequestMessage(HttpMethod.Get, url)
                request.Headers.Add("X-Api-Key", apiKey)
    
                Using response As HttpResponseMessage = Await client.SendAsync(request)
                    response.EnsureSuccessStatusCode()
    
                    Dim responseBody As String = Await response.Content.ReadAsStringAsync()
                    Return responseBody
                End Using
            End Using
        End Using
    End Function
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width