views:

1011

answers:

4

Hi guys 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

+1  A: 

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

Jasarien
the yahoo finance dev site is a joke. All it has is this: http://developer.yahoo.com/finance/rss feeds...
norskben
What's wrong with using the RSS feeds to get the stock quotes?
Jasarien
+2  A: 

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.

mikecsh
awesome, thats on the right track of what I'm looking for. Have you seen any fuller code I can use?
norskben
I've written some code to do this, but it's really only about 5 lines long. If you look into the Apple documentation for NSURLRequest, NSArray and NSString you should find everything you need :)
mikecsh
from can we get finance rss feeds?. It seems yahoo finance rss feeds can be used only for non-commercial (not sure if thats gonna help for iphone apps)
Satish
A: 

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.

Brad Larson
Yeah I noticed that example before I asked the question. This is to what lead to me saying 'simple' ;) That example is pretty advanced (in my opinion).
norskben
A: 

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.

SpecialK