![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Finnhub API - Get Stock QuoteSee more AI ExamplesDemonstrates how to get a stock quote from the Finnhub API.Note: This example requires Chilkat v11.4.0 or greater.
integer li_rc integer li_Success string ls_ApiKey string ls_Symbol oleobject loo_Http string ls_UrlWithoutParams oleobject loo_Req oleobject loo_Resp oleobject loo_Json integer li_StatusCode li_Success = 0 // Replace with your actual Finnhub API key. ls_ApiKey = "YOUR_FINNHUB_API_KEY" ls_Symbol = "AAPL" loo_Http = create oleobject li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if // This is the URL without params. ls_UrlWithoutParams = "https://finnhub.io/api/v1/quote" loo_Req = create oleobject li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest") // Add params that will be sent in the URL. loo_Req.AddParam("symbol",ls_Symbol) loo_Req.AddParam("token",ls_ApiKey) loo_Req.HttpVerb = "GET" // Send the request to get the JSON response. loo_Resp = create oleobject li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse") li_Success = loo_Http.HttpReq(ls_UrlWithoutParams,loo_Req,loo_Resp) if li_Success = 0 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_Req destroy loo_Resp return end if loo_Json = create oleobject li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Resp.GetBodyJson(loo_Json) li_StatusCode = loo_Resp.StatusCode Write-Debug "response status code: " + string(li_StatusCode) loo_Json.EmitCompact = 0 Write-Debug loo_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 li_StatusCode = 200 then // Add the symbol to the top of the result. loo_Json.AddStringAt(0,"symbol",ls_Symbol) // Rename members for clarification. loo_Json.Rename("c","currentPrice") loo_Json.Rename("d","change") loo_Json.Rename("dp","percentChange") loo_Json.Rename("h","high") loo_Json.Rename("l","low") loo_Json.Rename("o","open") loo_Json.Rename("pc","prevClose") loo_Json.Rename("t","unixTime") Write-Debug loo_Json.Emit() else Write-Debug "Failed" end if destroy loo_Http destroy loo_Req destroy loo_Resp destroy loo_Json |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.