Topic: Exchange Rates - Add Australian RBA as Provider

The Reserve Bank of Australia (RBA) is Australia's central bank, and they supply an official exchange rate at https://www.rba.gov.au/rss/rss-cb-exchange-rates.xml.

I have made changes to the Exchange Rates function to include the RBA as a provider.

To use this, change the config file (config.php) so that:

$xr_providers = array("ECB", "YAHOO", "GOOGLE", "BLOOMBERG","RBA");
$dflt_xr_provider = 4;

Hope this helps

gl/includes/db/gl_db_rates.inc

@@ -170,6 +170,13 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
         $proto = 'https://';
         $contents=file_get_contents($proto.$site.$filename);
     }
+    elseif ($provider == 'RBA')
+    {
+        $filename = "/rss/rss-cb-exchange-rates.xml";
+        $site = "www.rba.gov.au";
+        $proto = 'https://';
+        $contents=file_get_contents($proto.$site.$filename);
+    }
     if (empty($contents)) {
         if (function_exists('curl_init'))
         {    // first check with curl as we can set short timeout;

@@ -240,6 +258,40 @@ function get_extern_rate($curr_b, $provider = 'ECB', $date)
         $val = getInnerStr($contents, '<span id="ctl00_M_lblToAmount">', '<');
         $val = str_replace (',', '', $val);
     }
+    elseif ($provider == 'RBA')
+    {
+        $data = new SimpleXMLElement($contents);
+        $data->registerXPathNamespace('ns', 'http://purl.org/rss/1.0/');
+        $data->registerXPathNamespace('cb', 'http://www.cbwiki.net/wiki/index.php/Specification_1.2/');
+
+        $val_a = 0;
+        $val_b = 0;
+        
+        for ($i = 0; $i < count($data->xpath('ns:item')); $i++) {
+            if ($curr_a == 'AUD')
+            {
+                $val_a = 1;
+            }
+            elseif ($curr_a == $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->targetCurrency )
+            {
+                $val_a = (float) $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->observation[0]->value;
+            }
+
+            if ($curr_b == 'AUD') {
+                $val_b = 1;
+            }
+            elseif ($curr_b == $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->targetCurrency )
+            {
+                $val_b = (float) $data->item[$i]->children('cb',TRUE)->statistics[0]->exchangeRate[0]->observation[0]->value;
+            }
+        }
+
+        if ($val_b) {
+            $val = $val_a / $val_b;
+        } else {
+            $val = 0;
+        }
+    }
     return $val;
 }  /* end function get_extern_rate */

Re: Exchange Rates - Add Australian RBA as Provider

@joe: ?