I’ve been looking to create some stock related plugins for WordPress. As a first step I need to figure out how to access quote data. The Yahoo Quote Server appears to be the best bet. It has an api for acquiring both current and historical quotes and an array of attributes. The data is accessed via a url as seen in the example below. The ticker itself follows the s=. The f= portion is where paramters are supplied. 

Yahoo Quote Server Example

http://quote.yahoo.com/d/quotes.csv?s=goog&d=t&f=sl1d1t1c1ohgvj1pp2wern

A list of parameters

Symbol  s
Name  n
Volume  v
Average Daily Volume  a2
Last Trade (Price Only)  l1
Last Trade Size  k3
P/E Ratio  r
Dividend Yield  y
Market Capitalization  j1
50-day Moving Avg  m3
200-day Moving Avg  m4
Short Ratio  s7

 

CSV (comma separated values) Parsing

The data is returned in a csv file. As WordPress plugins are written in PHP, the built-in function fgetcsv (http://us3.php.net/fgetcsv) will work nicely.

<?php
$fp = fopen (“http://quote.yahoo.com/d/quotes.csv?s=goog&d=t&f=svl1&e=.csv”,”r”);
$stockData= fgetcsv ($fp, 1000, “,”)
?>

symbol: <?php echo $data[0] ?>
volume: <?php echo $data[1] ?>
last price: <?php echo $data[2] ?>

<?php
fclose ($fp);
?> 

Less useful, but worth pointing out, is Yahoo ICharts, which are thumbnail charts that may be directly referenced. Examples:
http://ichart.finance.yahoo.com/t?s=goog
http://ichart.finance.yahoo.com/v?s=goog 

Around the web
A complete list of parameters: http://dirk.eddelbuettel.com/code/yahooquote.html
A Java version: http://www.smartdataprocessing.com/lessons/l10.htm


Comments

2 Comments so far

  1. chuan on April 19, 2007 3:45 am

    i wonder what theme you are using?
    really like it.
    thank you

    chuan @canada

  2. Geek on April 19, 2007 11:50 am

    I started with ‘Blue Zinfandel Enhanced 2.0 by Brian Gardner’ and modified it a bit.

Name (required)

Email (required)

Website

Speak your mind