问题
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:
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.
回答2:
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.
回答3:
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.
回答4:
You could probably get a lot of your answers from the Yahoo Developer Network, in the Finance section.
回答5:
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.
来源:https://stackoverflow.com/questions/2265955/iphone-objective-c-simplest-way-to-get-a-stock-quote