![]() |
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
(C++) 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.
#include <CkHttp.h> #include <CkHttpRequest.h> #include <CkHttpResponse.h> #include <CkJsonObject.h> void ChilkatSample(void) { bool success = false; // Replace with your actual Finnhub API key. const char *apiKey = "YOUR_FINNHUB_API_KEY"; const char *symbol = "AAPL"; CkHttp http; // This is the URL without params. const char *urlWithoutParams = "https://finnhub.io/api/v1/quote"; CkHttpRequest req; // Add params that will be sent in the URL. req.AddParam("symbol",symbol); req.AddParam("token",apiKey); req.put_HttpVerb("GET"); // Send the request to get the JSON response. CkHttpResponse resp; success = http.HttpReq(urlWithoutParams,req,resp); if (success == false) { std::cout << http.lastErrorText() << "\r\n"; return; } CkJsonObject json; resp.GetBodyJson(json); int statusCode = resp.get_StatusCode(); std::cout << "response status code: " << statusCode << "\r\n"; json.put_EmitCompact(false); std::cout << json.emit() << "\r\n"; // 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. json.AddStringAt(0,"symbol",symbol); // Rename members for clarification. json.Rename("c","currentPrice"); json.Rename("d","change"); json.Rename("dp","percentChange"); json.Rename("h","high"); json.Rename("l","low"); json.Rename("o","open"); json.Rename("pc","prevClose"); json.Rename("t","unixTime"); std::cout << json.emit() << "\r\n"; } else { std::cout << "Failed" << "\r\n"; } } |
||||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.