Created
November 8, 2015 04:33
-
-
Save zvineyard/5b89eb9b329bf1c49935 to your computer and use it in GitHub Desktop.
PHP example for https://github.com/zvineyard/yahoo-finance-api
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 | |
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