![]() |
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
(VBScript) 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.
Dim fso, outFile Set fso = CreateObject("Scripting.FileSystemObject") 'Create a Unicode (utf-16) output text file. Set outFile = fso.CreateTextFile("output.txt", True, True) success = 0 ' Replace with your actual Finnhub API key. apiKey = "YOUR_FINNHUB_API_KEY" symbol = "AAPL" set http = CreateObject("Chilkat.Http") ' This is the URL without params. urlWithoutParams = "https://finnhub.io/api/v1/quote" set req = CreateObject("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. set resp = CreateObject("Chilkat.HttpResponse") success = http.HttpReq(urlWithoutParams,req,resp) If (success = 0) Then outFile.WriteLine(http.LastErrorText) WScript.Quit End If set json = CreateObject("Chilkat.JsonObject") success = resp.GetBodyJson(json) statusCode = resp.StatusCode outFile.WriteLine("response status code: " & statusCode) json.EmitCompact = 0 outFile.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. 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") outFile.WriteLine(json.Emit()) Else outFile.WriteLine("Failed") End If outFile.Close |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.