iPhone Objective-C Simplest Way to get a stock quo

2020-05-28 12:15发布

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

5条回答
ら.Afraid
2楼-- · 2020-05-28 12:48

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.

查看更多
一纸荒年 Trace。
3楼-- · 2020-05-28 12:51

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

查看更多
我只想做你的唯一
4楼-- · 2020-05-28 12:56

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.

查看更多
姐就是有狂的资本
5楼-- · 2020-05-28 13:04

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.

查看更多
三岁会撩人
6楼-- · 2020-05-28 13:05

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.

查看更多
登录 后发表回答