![]() |
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
(Unicode 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 <C_CkHttpW.h> #include <C_CkHttpRequestW.h> #include <C_CkHttpResponseW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { BOOL success; const wchar_t *apiKey; const wchar_t *symbol; HCkHttpW http; const wchar_t *urlWithoutParams; HCkHttpRequestW req; HCkHttpResponseW resp; HCkJsonObjectW json; int statusCode; success = FALSE; // Replace with your actual Finnhub API key. apiKey = L"YOUR_FINNHUB_API_KEY"; symbol = L"AAPL"; http = CkHttpW_Create(); // This is the URL without params. urlWithoutParams = L"https://finnhub.io/api/v1/quote"; req = CkHttpRequestW_Create(); // Add params that will be sent in the URL. CkHttpRequestW_AddParam(req,L"symbol",symbol); CkHttpRequestW_AddParam(req,L"token",apiKey); CkHttpRequestW_putHttpVerb(req,L"GET"); // Send the request to get the JSON response. resp = CkHttpResponseW_Create(); success = CkHttpW_HttpReq(http,urlWithoutParams,req,resp); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkHttpResponseW_Dispose(resp); return; } json = CkJsonObjectW_Create(); CkHttpResponseW_GetBodyJson(resp,json); statusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"response status code: %d\n",statusCode); CkJsonObjectW_putEmitCompact(json,FALSE); wprintf(L"%s\n",CkJsonObjectW_emit(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. CkJsonObjectW_AddStringAt(json,0,L"symbol",symbol); // Rename members for clarification. CkJsonObjectW_Rename(json,L"c",L"currentPrice"); CkJsonObjectW_Rename(json,L"d",L"change"); CkJsonObjectW_Rename(json,L"dp",L"percentChange"); CkJsonObjectW_Rename(json,L"h",L"high"); CkJsonObjectW_Rename(json,L"l",L"low"); CkJsonObjectW_Rename(json,L"o",L"open"); CkJsonObjectW_Rename(json,L"pc",L"prevClose"); CkJsonObjectW_Rename(json,L"t",L"unixTime"); wprintf(L"%s\n",CkJsonObjectW_emit(json)); } else { wprintf(L"Failed\n"); } CkHttpW_Dispose(http); CkHttpRequestW_Dispose(req); CkHttpResponseW_Dispose(resp); CkJsonObjectW_Dispose(json); } |
||||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.