5

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

oberbaum
  • 2,451
  • 7
  • 36
  • 52

5 Answers5

5

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.

Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31
mikecsh
  • 852
  • 7
  • 12
  • awesome, thats on the right track of what I'm looking for. Have you seen any fuller code I can use? – oberbaum Feb 15 '10 at 13:21
  • 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 Feb 15 '10 at 13:47
  • 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 Jul 21 '10 at 18:43
  • Up: is there an api limit to this request? X number of requests per IP Address perhaps? – anthoprotic Aug 14 '14 at 14:43
  • Not that I'm aware of but I wouldn't be that surprised if there is. – mikecsh Oct 24 '14 at 23:35
4

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.

Jasarien
  • 58,279
  • 31
  • 157
  • 188
Ken
  • 30,811
  • 34
  • 116
  • 155
2

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
  • 170,088
  • 45
  • 397
  • 571
  • 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). – oberbaum Feb 15 '10 at 21:29
1

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

Jasarien
  • 58,279
  • 31
  • 157
  • 188
1

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.

Brian Risk
  • 1,244
  • 13
  • 23
  • The only problem with using these API's is that they provide only open, low, high and close values for the day. But they don't provide the current value at a given time. – learn_develop Oct 03 '15 at 05:08