Created
August 20, 2011 14:55
-
-
Save holydevil/1159200 to your computer and use it in GitHub Desktop.
YQL for Finance quotes
This file contains 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
<h2>Using YQL to Finance quotes</h2> | |
<?php | |
$BASE_URL = "https://query.yahooapis.com/v1/public/yql"; | |
// Form YQL query and build URI to YQL Web service | |
$yql_query = "select * from yahoo.finance.quotes where symbol in ('YHOO', 'APPL')"; | |
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&env=store://datatables.org/alltableswithkeys&format=json"; | |
//echo $yql_query_url; | |
// Make call with cURL | |
$session = curl_init($yql_query_url); | |
curl_setopt($session, CURLOPT_RETURNTRANSFER,true); | |
$json = curl_exec($session); | |
// Convert JSON to PHP object | |
$phpObj = json_decode($json); | |
// echo "count -> " . $phpObj->query->count; | |
for($i=0; $i < $phpObj->query->count; $i++) { | |
echo "Quote = " . $phpObj->query->results->quote[$i]->symbol . "<br />"; | |
} | |
echo "<pre>"; | |
//print_r($phpObj); | |
echo "</pre>" | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment