Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Objective-C Simplest Way to get a stock quote [closed]

Im wondering what is the simplest way to get the current price of a stock from say yahoo finance (or similar) in objective-C For the iPhone SDK.

Simple is the key, I am looking for current price, and days movement.

I havent had much luck finding an iPhone code example or library.

regards

like image 677
oberbaum Avatar asked Feb 15 '10 12:02

oberbaum


5 Answers

Use an NSURLRequest object to retrieve the data at this address:

http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv

Using [NSString stringWithFormat:] to change the AAPL to the stock ticker you want to use. The retrieved data is in CSV format so you will need to parse that to get the individual values you require. This can be done in this simple case using [NSString componentsSeparatedByString: @","] to retieve an array which you can parse using two loops.

like image 117
mikecsh Avatar answered Oct 20 '22 14:10

mikecsh


The simplest code snippet for this I know is along the lines of:

NSLog(@"%@", [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://download.finance.yahoo.com/d/quotes.csv?s=BP.L&f=sl1d1t1c1ohgv&e=.csv"]]);

It retrieves BP's share price in London and prints it to the console.

like image 44
SK9 Avatar answered Oct 20 '22 12:10

SK9


For a full code example of this, check out the AAPLot sample application in the Core Plot framework. It downloads stock data and plots it with open-high-low-close information, as well as trading volume.

like image 35
Brad Larson Avatar answered Oct 20 '22 14:10

Brad Larson


You could probably get a lot of your answers from the Yahoo Developer Network, in the Finance section.

like image 22
Jasarien Avatar answered Oct 20 '22 13:10

Jasarien


The Quandl Stock API is free and let's you retrieve Yahoo or Google finance data. In addition to CSV, it provides the data in some more modern formats like JSON and XML. Here's how to retrieve for CSV:

https://www.quandl.com/api/v1/datasets/WIKI/AAPL.csv

Here's the small change to retrieve in JSON format:

https://www.quandl.com/api/v1/datasets/WIKI/AAPL.json

No API key is needed, but getting an API key is free and allows you to make up to 5000 calls per hour.

Another big plus is that the same API can be used to retrieve fundamental data about companies.

like image 1
Brian Risk Avatar answered Oct 20 '22 14:10

Brian Risk