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
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.
You could probably get a lot of your answers from the Yahoo Developer Network, in the Finance section.
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:
Here's the small change to retrieve in JSON format:
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.
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.The simplest code snippet for this I know is along the lines of:
It retrieves BP's share price in London and prints it to the console.