![]() |
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
(AutoIt) 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.
Local $bSuccess = False ; Replace with your actual Finnhub API key. Local $sApiKey = "YOUR_FINNHUB_API_KEY" Local $symbol = "AAPL" $oHttp = ObjCreate("Chilkat.Http") ; This is the URL without params. Local $sUrlWithoutParams = "https://finnhub.io/api/v1/quote" $oReq = ObjCreate("Chilkat.HttpRequest") ; Add params that will be sent in the URL. $oReq.AddParam "symbol",$symbol $oReq.AddParam "token",$sApiKey $oReq.HttpVerb = "GET" ; Send the request to get the JSON response. $oResp = ObjCreate("Chilkat.HttpResponse") $bSuccess = $oHttp.HttpReq($sUrlWithoutParams,$oReq,$oResp) If ($bSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf $oJson = ObjCreate("Chilkat.JsonObject") $oResp.GetBodyJson($oJson) Local $iStatusCode = $oResp.StatusCode ConsoleWrite("response status code: " & $iStatusCode & @CRLF) $oJson.EmitCompact = False ConsoleWrite($oJson.Emit() & @CRLF) ; 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 ($iStatusCode = 200) Then ; Add the symbol to the top of the result. $oJson.AddStringAt(0,"symbol",$symbol) ; Rename members for clarification. $oJson.Rename("c","currentPrice") $oJson.Rename("d","change") $oJson.Rename("dp","percentChange") $oJson.Rename("h","high") $oJson.Rename("l","low") $oJson.Rename("o","open") $oJson.Rename("pc","prevClose") $oJson.Rename("t","unixTime") ConsoleWrite($oJson.Emit() & @CRLF) Else ConsoleWrite("Failed" & @CRLF) EndIf |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.