![]() |
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
(PureBasic) 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.
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkHttpRequest.pb" Procedure ChilkatExample() success.i = 0 ; Replace with your actual Finnhub API key. apiKey.s = "YOUR_FINNHUB_API_KEY" symbol.s = "AAPL" http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; This is the URL without params. urlWithoutParams.s = "https://finnhub.io/api/v1/quote" req.i = CkHttpRequest::ckCreate() If req.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Add params that will be sent in the URL. CkHttpRequest::ckAddParam(req,"symbol",symbol) CkHttpRequest::ckAddParam(req,"token",apiKey) CkHttpRequest::setCkHttpVerb(req, "GET") ; Send the request to get the JSON response. resp.i = CkHttpResponse::ckCreate() If resp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckHttpReq(http,urlWithoutParams,req,resp) If success = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkHttpResponse::ckDispose(resp) ProcedureReturn EndIf json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodyJson(resp,json) statusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "response status code: " + Str(statusCode) CkJsonObject::setCkEmitCompact(json, 0) Debug CkJsonObject::ckEmit(json) ; 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 ; Add the symbol to the top of the result. CkJsonObject::ckAddStringAt(json,0,"symbol",symbol) ; Rename members for clarification. CkJsonObject::ckRename(json,"c","currentPrice") CkJsonObject::ckRename(json,"d","change") CkJsonObject::ckRename(json,"dp","percentChange") CkJsonObject::ckRename(json,"h","high") CkJsonObject::ckRename(json,"l","low") CkJsonObject::ckRename(json,"o","open") CkJsonObject::ckRename(json,"pc","prevClose") CkJsonObject::ckRename(json,"t","unixTime") Debug CkJsonObject::ckEmit(json) Else Debug "Failed" EndIf CkHttp::ckDispose(http) CkHttpRequest::ckDispose(req) CkHttpResponse::ckDispose(resp) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.