Zend Framework and Stock Quotes

by Naneau

While browsing I found this blog post by Greg Neutstaetter. I downloaded his code and tried to get it to work with the current version of the Zend Framework. There were only a few minor modifications that needed to be made for it to work, which tells you something about the stability of the framework. Take a look at the demo to see what it can do.

I have worked in some phpdoc comments, so editors with code assist will display nice hints. Not that you would need much hinting. The class works pretty straightforward. Take a look at greg’s blog for more info, about the symbols you can use for instance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Zend_Loader::loadClass('Gregphoto_Service_Yahoo_Stocks');
//load it
$stocks = new Gregphoto_Service_Yahoo_Stocks();
//create an instance

$stocks->addStocks(array('^DJI', 'NVDA', 'AMD', 'MSFT', 'GOOG'));
//add an array of stocks
$stocks->setSymbols(array('s','n','l1','c1'));
//symbols (information to be retrieved)

$stocks->setCacheLimit(60);
//it caches internally, this is the number of seconds
//before a new request will be made to yahoo
$stocks->setCacheDir('somedirectory');
//set a cache directory

$info = $stocks->getStockInfo();
//and get the info

foreach($info as $stock) {
    //resultset implements SeekableIterator
    echo $stock->c1;
}

Download my updated version.