++ed by:
1 non-PAUSE user
Author image Bhavin Patel
and 1 contributors


Forex - Historic Foreign Exchange Rates from Open Exchange Rates




 use Forex;
 my $forex = new Forex( 'APP_ID' => $app_id, 'BASE' => 'USD');
 #__fetch and initialize daily rates from $from_date to $to_date in yyyy-mm-dd 
 $forex->get_rates_from ( $from_date, $to_date );

 #___ fetches rates for $date (yyyy-mm-dd)
 $forex->get_rates( $date );
 #___ fetches reates for today 
 #___ gives AUD on 2012-09-01 in USD Base currency
 $usd = $forex->get_rate_of ( 'AUD', '2012-09-01' );  
 if ($Forex::LASTERROR )
    { print "\n Something went wrong" , $oxr->last_error_message(); }  




new Forex()

returns new Forex object with defaults values for

OXR_HOME = 'http://openexchangerates.org',
API_HOOK = 'api',
APP_ID = 'temp-e091fc14b3884a516d6cc2c299a',
 my $oxe = new Forex( OXR_HOME => 'https://openexchangerates.org',
                      API_HOOK => 'api',
                      APP_ID   => 'temp-e091fc14b3884a516d6cc2c299a',
                      BASE     => 'AUD');

get_rate_of( $currency, <$date> )

This method returns forex rate for $currency on $date in BASE currency, $date should be in yyyy-mm-dd format.

my $AUD = $oxr->get_rate_of( 'AUD' , '2012-09-10' );

get_rates_from ( $from_date , $to_date )

downloads and fills CURRENCIES hash for $from_date to $to_date both dates should be in yyyy-mm-dd formate

get_rates ( <$day> )

downloads and fills in values for all currencies in the CURRENCIES hash for given $day $day should be in yyyy-mm-dd formate if $day is skipped , it uses todays date,


this method downloads and initializes all currency symbols from openexchangerates site. this method should be run before either get_rates or get_rates_from

base_currency( <$BASE_CURRENCY> )

sets BASE currency so that succeeding request will request the rates with base currency as specified by $BASE_CURRENCY. if the parameter is omitted it return the current BASE_CURRENCY value;

Note: you will have to flush the $CURRENCIES hash if you change the BASE currency. with flush_values()

oxr_home ( <$OXR_HOME> )

sets OXR_HOME parameter to $OXR_HOME value , if the parameter is omitted it returns the current value of the OXR_HOME. OXR_HOME value should cuntaion "http://" .

Note: you could you it to change the default "http://" to "https://" if you have enterprise APP_ID

app_id ( <$APP_ID> )

sets app_id for all succeeding requests. return current app_id if the parameter is omitted.


returns all the currencies in the currencies hash


returns last error object as returned by Open Exchange Rates API

last_error_message ()

returns last error message


on errors module sets $LASTERROR global variable which can be accessed by $Forex::LASTERROR. And error message can be accessed via last_error_message() or last_error()



please submit known issues or bugs to mail4bhavin@yahoo.com


Bhavin Patel

This Software is free to use , licensed under:

        The Artistic License 2.0 (GPL Compatible)