Created
November 20, 2009 13:22
-
-
Save dogmatic69/239498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Created by Guido Rossi <[email protected]> | |
// Date: 28/03/2008 | |
// License: GNU General Public License v3 | |
// Version: 1.1 | |
class YahooFinance{ | |
var $simbol; | |
function Yfapi($simbol, $local="download"){ | |
$separador = ','; | |
if($local == 'ar'){ | |
$separador = ';'; | |
} | |
$file = 'http://'.$local.'.finance.yahoo.com/d/quotes.csv?s='.$simbol.'&f=sl1d1t1c1ohgv&e=.csv'; | |
$handle = fopen($file, "r"); | |
$data = fgetcsv($handle, 4096, $separador); | |
fclose($handle); | |
if ($handle === false) { | |
return False; | |
} | |
else | |
{ | |
$simbolo = $data[0]; | |
$ultimo = $data[1]; | |
$fecha = $data[2]; | |
$horario = $data[3]; | |
$variac = $data[4]; | |
$apertura = $data[5]; | |
$maximo = $data[6]; | |
$minimo = $data[7]; | |
$volumen = $data[8]; | |
if($fecha == "N/A") { | |
return False; | |
} | |
$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 $horario"; | |
$datos = array('simbolo' => $simbolo, 'ultimo' => $ultimo, 'variacion' => $variac, 'volumen' => $volumen, 'porcentaje' => $porcent, 'fecha' => $fechahora, 'anterior' => $anterior, 'maximo' => $maximo, 'minimo' => $minimo); | |
$this->simbolo = $datos['simbolo']; | |
$this->ultimo = $datos['ultimo']; | |
$this->anterior = $datos['anterior']; | |
$this->porcentaje = $datos['porcentaje']; | |
$this->variacion = $datos['variacion']; | |
$this->volumen = $datos['volumen']; | |
$this->fecha = $datos['fecha']; | |
$this->maximo = $datos['maximo']; | |
$this->minimo = $datos['minimo']; | |
return True; | |
} | |
} | |
function getSimbolo(){ | |
return $this->simbolo; | |
} | |
function getUltimo(){ | |
return $this->ultimo; | |
} | |
function getFecha(){ | |
return $this->fecha; | |
} | |
function getAnterior(){ | |
return $this->anterior; | |
} | |
function getPorcentaje(){ | |
return $this->porcentaje; | |
} | |
function getVariacion(){ | |
return $this->variacion; | |
} | |
function getVolumen(){ | |
return $this->volumen; | |
} | |
function getMaximo(){ | |
return $this->maximo; | |
} | |
function getMinimo(){ | |
return $this->minimo; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment