Skip to content

Instantly share code, notes, and snippets.

@zvineyard
Created November 8, 2015 04:33
Show Gist options
  • Save zvineyard/5b89eb9b329bf1c49935 to your computer and use it in GitHub Desktop.
Save zvineyard/5b89eb9b329bf1c49935 to your computer and use it in GitHub Desktop.
<?php
require 'yahoo-finance-api/lib/YahooFinance/YahooFinance.php';
$yf = new YahooFinance;
$quote = json_decode($yf->getQuotes(array('IDA', 'MCEP', 'UWTI')));
?>
<table>
<tr>
<td>Symbol</td>
<td>Price</td>
<td>Fifty Day</td>
<td>% Change</td>
</tr>
<?php
foreach($quote->query->results->quote as $stock)
{
if (substr($stock->PercentChange, 0, 1) === '+')
{
$color = "green";
}
else
{
$color = "red";
}
echo '<tr>';
echo '<td>' . $stock->symbol . '</td>';
echo '<td>' . number_format((float)$stock->LastTradePriceOnly, 2, '.', '') . '</td>';
echo '<td>' . number_format((float)$stock->FiftydayMovingAverage, 2, '.', '') . '</td>';
echo '<td style="color:'.$color.'">' . $stock->PercentChange . '</td>';
echo '</tr>';
}
?>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment