Xojo Plugin
Xojo Plugin
Finnhub API - Get Stock Quote
See more AI Examples
Demonstrates how to get a stock quote from the Finnhub API.Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Replace with your actual Finnhub API key.
Dim apiKey As String
apiKey = "YOUR_FINNHUB_API_KEY"
Dim symbol As String
symbol = "AAPL"
Dim http As New Chilkat.Http
// This is the URL without params.
Dim urlWithoutParams As String
urlWithoutParams = "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
System.DebugLog(http.LastErrorText)
Return
End If
Dim json As New Chilkat.JsonObject
success = resp.GetBodyJson(json)
Dim statusCode As Int32
statusCode = resp.StatusCode
System.DebugLog("response status code: " + Str(statusCode))
json.EmitCompact = False
System.DebugLog(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.
success = json.AddStringAt(0,"symbol",symbol)
// Rename members for clarification.
success = json.Rename("c","currentPrice")
success = json.Rename("d","change")
success = json.Rename("dp","percentChange")
success = json.Rename("h","high")
success = json.Rename("l","low")
success = json.Rename("o","open")
success = json.Rename("pc","prevClose")
success = json.Rename("t","unixTime")
System.DebugLog(json.Emit())
Else
System.DebugLog("Failed")
End If