[eluser]guidorossi[/eluser]
Hi!
This is my first plugin for CI, so I want to show it and let me know if I'm working ok.
Is a Yahoo Finance stock data returner.
Code:
<?php
// Created by Guido Rossi http://guidorossi.com.ar
// Date: 04/feb/2008
// License: GPL
// Version: 1.0
class YahooFinance{
var $simbol;
function Yfapi($simbol){
$request = 'http://ar.finance.yahoo.com/d/quotes.csv?s='.$simbol.'&f=sl1d1t1c1ohgv';
$response = file_get_contents($request);
if ($response === false) {
die('Request failed');
}
else
{
$data = split(';', $response);
$simbolo = $data[0];
$ultimo = $data[1];
$fecha = $data[2];
$hora = $data[3];
$variac = $data[4];
$apertura = $data[5];
$volumen = $data[8];
$anterior = $ultimo - $variac;
$porce = ($ultimo * 100)/ $anterior;
$porcelargo = $porce - 100;
$porcent = round($porcelargo, 2);
$datafecha = split('/', $fecha);
$mes = $datafecha[0];
$dia = $datafecha[1];
$year = $datafecha[2];
$fechahora = ''.$dia.'/'.$mes.'/'.$year.' '.$hora.'';
$this->data = array("ultimo" => $ultimo, "variacion" => $variac, "volumen" => $volumen, "porcentaje" => $porcent, "fecha" => $fechahora);
}
if(!$data) {
return false;
}
return $this->data;
}
}
/*
Show array
echo '<pre>';
print_r($YahooFin->Yfapi('acin.ba'));
echo '</pre>';
*/
/*
Example
$YahooFin = new YahooFinance;
$dataarray = $YahooFin->Yfapi('acin.ba');
echo $dataarray['ultimo'];
*/
?>
This was coded for Yahoo Finance Argentina, but it can be easily adapted to Yahoo International.
You need to pass the yahoo finance symbol of the stock like $YahooFin->Yfapi('GOOG')
I hope it can help, and let me know any error