Created
December 28, 2009 22:48
-
-
Save henrik/265014 to your computer and use it in GitHub Desktop.
JavaScript to get currency exchange rates from Yahoo Finance as JSONP. No XHR!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get exchange rate as JSONP via YQL. | |
YQL Console: http://developer.yahoo.com/yql/console | |
Query (USD to SEK): select rate,name from csv where url='http://download.finance.yahoo.com/d/quotes?s=USDSEK%3DX&f=l1n' and columns='rate,name' | |
Example code: | |
<script type="text/javascript"> | |
function getRate(from, to) { | |
var script = document.createElement('script'); | |
script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D"+from+to+"%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate"); | |
document.body.appendChild(script); | |
} | |
function parseExchangeRate(data) { | |
var name = data.query.results.row.name; | |
var rate = parseFloat(data.query.results.row.rate, 10); | |
alert("Exchange rate " + name + " is " + rate); | |
} | |
getRate("SEK", "USD"); | |
getRate("USD", "SEK"); | |
</script> |
@kasimvali786
You can use this one
`https://finance.google.com/finance/converter?a=${amout}&from=${from}&to=${to}`
This might be too much to ask but can you post an example to convert USD to INR using the above URL ?
Looks like both APIs are not working.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Henrik,
Yes, I noticed that before comment, do you have any idea is there any link API URL to get the daily exchange rates.
Thanks in advanced.