bladx has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone,

For a self-induced project, (and for some personal snorts and giggles,) I have decided to embark on (attempting) to create a program that will help me figure out currency exchange rates of Japanese Yen, and US Dollars. (As I check up on the rates frequently, and being a Perl programmer, would like to create a small program that can quickly calculate the going exchange rates.)

My real question is for this project, (since I can do the other programming and putting together of this initial project,) is: Is there a way I can get information from official exchange rates from statistical web servers, and then use it in my program to get the current (and reliable,) going rate of USD <-> Japanese Yen and vice versa?

I appreciate any time spent to further my education here at pm.org.

Andy Summers

Replies are listed 'Best First'.
Re: Currency Exchange Rate Programming
by mitd (Curate) on Aug 27, 2001 at 02:42 UTC

    This will do the trick. I have only supplied the all important convert function. I leave to you to wrap what ever code you require around it.

    use LWP::Simple; ... sub convert { $_=get("http://www.oanda.com/converter/ classic?value=$amount&exch=$fc&expr=$tc"); s/^.*<!-- conversion result starts//s; s/<!-- conversion result ends.*$//s; s/<[^>]+>//g; s/[ \n]+/ /gs; print $_, "\n"; }

    mitd - Made in the dark.

      Thanks for the snippet, I need to learn me some LWP soon! Thanks again, I will begin work on this project, and let you know if I run into any problems.

      Andy Summers
Re: Currency Exchange Rate Programming
by Philgarr (Novice) on Aug 27, 2001 at 05:41 UTC

    You can use a SOAP service to get the data you need. After a quick Google search, I found a web service to do the work for you. You'll have to have SOAP::Lite installed, though. You can get it from CPAN if you don't. See www.soaplite.com for more info.

    Instead of just giving you the exchange rate, however, it gives you a string containing both the exchange rate and the time at which it was valid. You'll have to get the exchange rate off the end of the string. Since you said you wanted to "create a program," I'll leave that part as an exercise for the reader. :-)

    You'll want to use the currency codes USD and JPY for US dollars to Japanese yen. See the service home page for more currencies and service specifics.

    use SOAP::Lite; die "gimme some currency codes" unless @ARGV == 2; my ($from,$to) = @ARGV; my $rate_str = SOAP::Lite ->proxy('http://www.itfinity.net:8080/soap/exrates/default.asp') ->endpoint('http://www.itfinity.net:8008/soap/exrates/default.asp') ->uri('http://www.itfinity.net/soap/exrates/exrates.xsd') ->GetRate( SOAP::Data->type('string')->name( fromCurr => $from ), SOAP::Data->type('string')->name( ToCurr => $to ), ) ->result; print "$rate_str\n";

    hth,
    Philgarr
Re: Currency Exchange Rate Programming
by Jazz (Curate) on Aug 27, 2001 at 06:15 UTC
Re: Currency Exchange Rate Programming
by Masem (Monsignor) on Aug 27, 2001 at 02:41 UTC
    A quick google search shows several currency converter sites; some offer the rates on a table, some will email you the new rates daily. Any of these methods, along with tools like HTML::TableExtract will help you get the rates. But you'll need to read the various pages to make sure that such a use is an acceptable use by their user policy (A quick check at a few do not allow you to reuse their information).

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    It's not what you know, but knowing how to find it if you don't know that's important

Re: Currency Exchange Rate Programming
by Anonymous Monk on Aug 27, 2001 at 05:52 UTC
    Here's a URL that gives you only the number you're looking for. (That is, it doesn't give HTMl, just a number - No parsing required!)

    http://finance.yahoo.com/d/quotes.csv?s=USDJPY=X&f=l1&e=.csv

    Replace the six-letter string in uppercase with the currency symbols. You can play a little with the other parameters, too.
    --
    Jorge Gomez
Re: Currency Exchange Rate Programming
by derby (Abbot) on Aug 27, 2001 at 16:21 UTC
    Andy,

    Having done this for a major internet company, let me tell you while the actual coding of exchange rates is rather straightforward, what exchange rate to use can be a complicated beast.

    There is the interbank rate (nothing a joe monk would ever get), a typical credit card rate (normally interbank + 2%), a cash exchange rate (interbank + 4%), etc. Even then, some companies will not change their rates on a daily basis. They normally build in some type of buffer +-2% so their prices/costs don't look so volatile.

    I'd recommend checking out the following sites: Oanda (which has a perl client) and Pacific Exchange Rate Service (which is related to the IMF in some manner).