Yahoo provides YQL(Yahoo Query Language) platform that enables you to query , filter and combine data . These queries syntax is just like SQL queries.
So the query used to get fresh exchange rate from yahoo is
select * from yahoo.finance.xchange where pair in ("USDINR")
This query would return usd to inr exchange rate along with the date and time this instance of exchange rate was created and other useless information which can be avoided.
And if you want to get multiple exchange rates at once , then you can manipulate the query like:-
select * from yahoo.finance.xchange where pair in ("USDINR","USDEUR","USDNGN","USDCAD")
Just like that you can implement it for all combinations you want.
So now you would be like ” OK I have the query , so how do i get the damn exchange rates”, well you could do that by making http request using get method, if you don’t know how to do that well then you cal follow the following blog for doing that in java , groovy . For others please try to find that out yourself.
https://hprog99.wordpress.com/2014/11/03/send-http-postget-request-in-java/
So the complete url that you would sending request to is
https://query.yahooapis.com/v1/public/yql?q=
select * from yahoo.finance.xchange where pair in ('USDINR','USDEUR','USDNGN','USDCAD')&format=json&env=store://datatables.org/alltableswithkeys&callback=
Again you could manipulate the query depending upon which currency pairs are you interested in .
Also before making http request , you would need to encode the url with UTF-8, so after encoding the url with UTF-8 it should look something like
https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%27USDINR%27%2C%27USDEUR%27%2C%27USDNGN%27%2C%27USDCAD%27)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
And you would get the following json as reponse
{"query":{"count":4,"created":"2015-06-11T05:43:15Z","lang":"en-US","results":{"rate":[{"id":"USDINR","Name":"USD/INR","Rate":"63.8550","Date":"6/11/2015","Time":"6:43am","Ask":"63.8600","Bid":"63.8550"},{"id":"USDEUR","Name":"USD/EUR","Rate":"0.8846","Date":"6/11/2015","Time":"6:43am","Ask":"0.8847","Bid":"0.8846"},{"id":"USDNGN","Name":"USD/NGN","Rate":"198.9500","Date":"6/11/2015","Time":"6:43am","Ask":"199.0000","Bid":"198.9500"},{"id":"USDCAD","Name":"USD/CAD","Rate":"1.2277","Date":"6/11/2015","Time":"6:43am","Ask":"1.2278","Bid":"1.2277"}]}}}
If you have any doubts or suggestions then please post them in comments.