Sample code for 30+ languages & platforms
VB.NET Requires Chilkat v11.4.0+

Finnhub API - Get Stock Quote

See more AI Examples

Demonstrates how to get a stock quote from the Finnhub API.

Chilkat VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  Replace with your actual Finnhub API key.
Dim apiKey As String = "YOUR_FINNHUB_API_KEY"
Dim symbol As String = "AAPL"

Dim http As New Chilkat.Http

'  This is the URL without params.
Dim urlWithoutParams As String = "https://finnhub.io/api/v1/quote"

Dim req As New Chilkat.HttpRequest

'  Add params that will be sent in the URL.
req.AddParam("symbol",symbol)
req.AddParam("token",apiKey)

req.HttpVerb = "GET"

'  Send the request to get the JSON response.
Dim resp As New Chilkat.HttpResponse
success = http.HttpReq(urlWithoutParams,req,resp)
If (success = False) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


Dim json As New Chilkat.JsonObject
resp.GetBodyJson(json)

Dim statusCode As Integer = resp.StatusCode
Debug.WriteLine("response status code: " & statusCode)

json.EmitCompact = False
Debug.WriteLine(json.Emit())

'  Sample result:

'  {
'    "c": 248.8,
'    "d": -4.09,
'    "dp": -1.6173,
'    "h": 255.493,
'    "l": 248.07,
'    "o": 253.9,
'    "pc": 252.89,
'    "t": 1774641600
'  }

If (statusCode = 200) Then
    '  Add the symbol to the top of the result.
    json.AddStringAt(0,"symbol",symbol)

    '  Rename members for clarification.
    json.Rename("c","currentPrice")
    json.Rename("d","change")
    json.Rename("dp","percentChange")
    json.Rename("h","high")
    json.Rename("l","low")
    json.Rename("o","open")
    json.Rename("pc","prevClose")
    json.Rename("t","unixTime")

    Debug.WriteLine(json.Emit())

Else
    Debug.WriteLine("Failed")
End If