Yahoo Finance – Parse Stock Currency

How to parse the stock currency in Yahoo Finance?

You can use the following script

This script will parse the currency out of a Yahoo Finance page.

mattionline:/home/stock# cat fetchcurrency.php
<?php

if($argv[1] != "") {

$symbol = $argv[1];

$url = "https://de.finance.yahoo.com/quote/".$symbol;

$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);

$dom = new DOMDocument();
@$dom->loadHTML($html);
$link = $dom->getElementById('quote-header-info');
preg_match('/Währung in (.*?)[+-]/', $link->textContent, $found);
$test = explode("Z", $found[1]);
$currency = $test[0];

echo $currency;

}

?>

Output of the script

If you pass the parameter (SOBA.DE) (which is the shortcode from Yahoo Finance for the AT&T company), you will get the EUR symbol as a result, because the symbol is from the German stock exchange XETRA (€).

https://de.finance.yahoo.com/quote/SOBA.DE/

If you pass the Calida Stock, you will receive the currency swiss francs (CHF).

mattionline:/home/stock# php -f fetchcurrency.php SOBA.DE
EUR
mattionline:/home/stock# php -f fetchcurrency.php CALN.SW
CHF
mattionline:/home/stock#

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben scrollen