Skip to content

Instantly share code, notes, and snippets.

@PurwantoGZ
Created November 22, 2017 02:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PurwantoGZ/43f4ea8dc2727be61306d0f71c205731 to your computer and use it in GitHub Desktop.
Save PurwantoGZ/43f4ea8dc2727be61306d0f71c205731 to your computer and use it in GitHub Desktop.
Google Finance API
public function getQuetesv2($ticker)
{
$infoUrl='https://finance.google.com/finance?q=idx:'.$ticker.'&output=json';
$contents = str_replace('//','',file_get_contents($infoUrl));
$json = json_decode($contents, true);
if(!array_key_exists("results_type",$json)){
$data=$json[0];
$related=$data['related'];
echo $data['symbol']. '<br />';
echo $data['exchange']. '<br />';
echo $data['id']. '<br />';
echo $data['t']. '<br />';
echo $data['e']. '<br />';
echo $data['name']. '<br />';
echo $data['f_reuters_url']. '<br />';
echo $data['f_recent_quarter_date']. '<br />';
echo $data['f_annual_date']. '<br />';
echo $data['f_ttm_date']. '<br />';
echo $data['l']. '<br />';
echo $data['shares']. '<br />';
echo $related[0]['id']. '<br />';
foreach ($related as $a => $b) {
foreach ($b as $key => $value) {
echo $key.' : '.$value. '<br />';
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment