Bank Of Israel - Currency exchange rates
In this post (hebrew), Shlomo Goldberg, shows how we can receive currency exchange rates from Bank Of Israel website in C#. This is a great way to show how with a few lines of code we can get the rates with PowerShell.
We create a webclient object, use its DownloadString method and cast the result to XML using PowerShell's XML type shortcut and then we format the results:
$wc = New-Object System.Net.WebClient
$rates = [xml]$wc.DownloadString("http://www.bankisrael.gov.il/currency.xml")
$rates.CURRENCIES.CURRENCY | Format-Table -Auto Name,Country,CurrencyCode,Rate,Change,Unit
NAME COUNTRY CURRENCYCODE RATE CHANGE UNIT
---- ------- ------------ ---- ------ ----
Dollar USA USD 3.904 0.051 1
Pound Great Britain GBP 6.3672 -0.801 1
Yen Japan JPY 4.1685 0.26 100
Euro EMU EUR 5.5041 -0.256 1
Dollar Australia AUD 3.1259 -0.144 1
Dollar Canada CAD 3.4904 0.043 1
krone Denmark DKK 0.7393 -0.256 1
Krone Norway NOK 0.6108 -0.294 1
Rand South Africa ZAR 0.4821 -0.021 1
Krona Sweden SEK 0.4981 -0.678 1
Franc Switzerland CHF 3.6227 -0.519 1
Dinar Jordan JOD 5.5176 0.256 1
Pound Lebanon LBP 0.0259 0 10
Pound Egypt EGP 0.6995 0.057 1
Note: The 'Change' column represent the change in percents. We can change the column display by using a calculated property:
PS > $change = @{Name="Change";Expression={ $_.Change+"%"}}
PS > $rates.CURRENCIES.CURRENCY | FT -Auto Name,Country,CurrencyCode,Rate,$Change,Unit
NAME COUNTRY CURRENCYCODE RATE Change UNIT
---- ------- ------------ ---- ------ ----
Dollar USA USD 3.904 0.051% 1
Pound Great Britain GBP 6.3672 -0.801% 1
Yen Japan JPY 4.1685 0.26% 100
Euro EMU EUR 5.5041 -0.256% 1
Dollar Australia AUD 3.1259 -0.144% 1
Dollar Canada CAD 3.4904 0.043% 1
krone Denmark DKK 0.7393 -0.256% 1
Krone Norway NOK 0.6108 -0.294% 1
Rand South Africa ZAR 0.4821 -0.021% 1
Krona Sweden SEK 0.4981 -0.678% 1
Franc Switzerland CHF 3.6227 -0.519% 1
Dinar Jordan JOD 5.5176 0.256% 1
Pound Lebanon LBP 0.0259 0% 10
Pound Egypt EGP 0.6995 0.057% 1
EDIT: We can also use .NET custom numeric format strings to apply the percent sign and retain the original values (see the 'Section Separators and Conditional Formatting' section on MSDN):
$change = @{Name="Change";Expression={ "{0:0.### %;-0.### %;0}" -f ($_.Change/100) }}
You can specify other URLs to get information for specific date and/or currency code:
Get the previous day rates:
http://www.bankisrael.gov.il/heb.shearim/currprev.php
Use the following URL to get an xml file for USA Dollar only (use the curr parameter - currency code ):
http://www.bankisrael.gov.il/heb.shearim/currency.php?curr=01
Get exchange rates for a specific date (use the rdate parameter):
http://www.bankisrael.gov.il/heb.shearim/currency.php?rdate=20030505
Get exchange rates for a specific date and currency:
http://www.bankisrael.gov.il/heb.shearim/currency.php?rdate=20030505&curr=01
I should note that you need to get explicit permission to display the rates on your website. You can ask for permission here.