![]() |
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
(Objective-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.
#import <NSString.h> #import <CkoHttp.h> #import <CkoHttpRequest.h> #import <CkoHttpResponse.h> #import <CkoJsonObject.h> BOOL success = NO; // Replace with your actual Finnhub API key. NSString *apiKey = @"YOUR_FINNHUB_API_KEY"; NSString *symbol = @"AAPL"; CkoHttp *http = [[CkoHttp alloc] init]; // This is the URL without params. NSString *urlWithoutParams = @"https://finnhub.io/api/v1/quote"; CkoHttpRequest *req = [[CkoHttpRequest alloc] init]; // Add params that will be sent in the URL. [req AddParam: @"symbol" value: symbol]; [req AddParam: @"token" value: apiKey]; req.HttpVerb = @"GET"; // Send the request to get the JSON response. CkoHttpResponse *resp = [[CkoHttpResponse alloc] init]; success = [http HttpReq: urlWithoutParams request: req response: resp]; if (success == NO) { NSLog(@"%@",http.LastErrorText); return; } CkoJsonObject *json = [[CkoJsonObject alloc] init]; [resp GetBodyJson: json]; int statusCode = [resp.StatusCode intValue]; NSLog(@"%@%d",@"response status code: ",statusCode); json.EmitCompact = NO; NSLog(@"%@",[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) { // Add the symbol to the top of the result. [json AddStringAt: [NSNumber numberWithInt: 0] name: @"symbol" value: symbol]; // Rename members for clarification. [json Rename: @"c" newName: @"currentPrice"]; [json Rename: @"d" newName: @"change"]; [json Rename: @"dp" newName: @"percentChange"]; [json Rename: @"h" newName: @"high"]; [json Rename: @"l" newName: @"low"]; [json Rename: @"o" newName: @"open"]; [json Rename: @"pc" newName: @"prevClose"]; [json Rename: @"t" newName: @"unixTime"]; NSLog(@"%@",[json Emit]); } else { NSLog(@"%@",@"Failed"); } |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.