Click to See Complete Forum and Search --> : Real Time Currency rates
anothen
12-17-2010, 09:11 PM
I've been looking around the web
trying to find out how real time
rates of currency and stocks
are done. I've found widgets
and websites which do this,
I was wondering how, and if I'm
able to write this code for my own
web page.
donatello
12-18-2010, 08:24 AM
If you are looking for Euro rates the ECB has a feed. I use it on a site, you can see it here:
dollars to euro (http://www.dollarstoeuro.com/)
There was a wordpress plugin that showed a selectable rate and worked via AJAX but it stopped working... as you can see it is in the right sidebar. I don't really update this site as it does not get much traffic, so just left it out of sheer disgraceful laziness.
Here is the PHP script I use to scrape the rates...
There is a WordPress conditional tag in this script.
<!-- Currency Rates on home page only BEGIN -->
<?php if (is_front_page()) { ?><!-- Wordpress Conditional Tag BEGIN -->
<div class="forextable">
<?php
$page = file_get_contents("http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html");
//Above this line, ALL WORKS FINE! ////////////////////////////////////////////////////
// FOR you the $getpage should be the entire html you display on the page
$explodefirst = explode('<div class="tab">',$page);
$headerisgone = $explodefirst[1];
$explodesecond = explode('</div>',$headerisgone);
$endresult = $explodesecond[0];
$endresult = str_replace('href="eurofxref','target="_blank" rel="nofollow" href="http://www.ecb.int/stats/exchange/eurofxref/html/eurofxref', $endresult);
$endresult = str_replace('href="/rss','target="_blank" rel="nofollow" href="http://www.ecb.int/rss', $endresult);
print $endresult;
?>
</div></div>
<p> </p>
<?php } ?><!-- End of Wordpress conditional tag -->
<!-- Currency rates on home page only END -->
donatello
12-18-2010, 08:29 AM
I also had a screenscraper for Bloomberg, but they detect it and shut you off! There is a way to get stock quotes from Yahoo Finance... they seem to allow feeds.
A friend of mine uses it on his financial blog in a Wordpress plugin in the sidebar. Here's his site:
ETF Portfolios (http://www.etf-portfolios.com)
anothen
12-18-2010, 09:46 AM
thx donatello, I'll check into it.