To convert money from one currency to another currency, we need Currency Exchange Rate Value. Yahoo is providing an online API to get currency exchange rates. Here in below example I explained how to convert Money from one currency to other using Yahoo Finance API.
Steps to Convert Currency :
Yahoo Finance API :
Observe below GET request URL. You can see the query in q parameter. Here the Currency codes were paired. Click on below link to see output XML format.
Example :
If you want to get US dollar value in Indian rupees then you have to form below URL
http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDINR")&env=store://datatables.org/alltableswithkeys
Request to Yahoo Finance API and Get Response XML :
String url ="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDINR%22)&env=store://datatables.org/alltableswithkeys"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); //add request header con.setRequestProperty("User-Agent", USER_AGENT); // Send request int responseCode = con.getResponseCode(); System.out.println("\nSending 'GET' request to URL : " + url); System.out.println("Response Code : " + responseCode + "\n\n"); BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String outputLine; // reading output from Request StringBuffer response = new StringBuffer(); while ((outputLine = in.readLine()) != null) { response.append(outputLine); } in.close();
Convert XML Response to POJO class :
// Converting XML to JSON and then JSON to POJO Classes GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); QueryPojo mp = gson.fromJson(Utility.convertXMLtoJSON(response.toString()), QueryPojo.class);
Convert Currency With Exchange Rate :
String exchangeRate = mp.getQuery().getResults().getRate().getRate(); BigDecimal amountOne = new BigDecimal(amout); BigDecimal rate = new BigDecimal(exchangeRate); System.out.println(amountOne.multiply(rate));
hi! how can i get oil prise by same method?
ReplyDeleteThis comment has been removed by the author.
ReplyDeletespotify customer service
ReplyDeleteCalculate the live currency and foreign exchange rates with free currency converter. You can convert currencies instantly. I recmonded you Currency calculator app through this you get more results about Money converter .
I am looking for and I love to post a comment that "The content of your post is awesome" Great work Up to 10 VIP signals Daily with updates.
ReplyDeletehi was just seeing if you minded a comment. i like your website and the thme you picked is super. I will be back. exchange rates widget
ReplyDeleteThere are numerous kinds of currency converters on the web. The sorts vary by their planned purposes and the data they give. exchange rates widget
ReplyDeleteThe best projects return with full cash ensures on them and even empower you to demo exchange them inside the bounds of a sheltered practice record to see and guarantee that they perform a long time before you give them any genuine cash to contribute with to make the whole procedure hazard free. naked url with no anchor
ReplyDeleteHey. Very cool website!! Man .. Excellent .. Superb .. I’ll bookmark this website and take the feeds additionally…I’m glad to find a lot of helpful info here within the article. Thank you for sharing.. usd to eur
ReplyDeleteA currency converter is an exceptionally usd to aud convenient device for Forex world as well as just as every day life. When you travel, request merchandise over web it's important to discover current estimation of remote currency
ReplyDeleteI love significantly your own post! I look at all post is great. I discovered your personal content using bing search. Discover my webpage is a great one as you.I work to create several content this post. Once more you can thank you and keep it create! Enjoy! stock market
ReplyDeleteI went over this website and 200 euros to usd
ReplyDeleteI believe you have a lot of wonderful information, saved to my bookmarks
Just pure classic stuff from you here. I have never seen such a brilliantly written article in a long time. I am thankful to you that you produced this! Netflix Stock updates
ReplyDeleteThere are numerous sorts of cash converter accessible and these will regularly cover you for an assortment of conditions. convert money
ReplyDeleteThank you for taking the time to publish this information very useful! convert money online
ReplyDeleteIn addition, you likewise don't need to search for the closest cash changer to make sure you can perceive how much a Rupee costs in U.S. dollars. convert money
ReplyDeleteHi there! Nice stuff, do keep me posted when you post again something like this! convert currency
ReplyDeleteWith these free money making thoughts the way that your hazard diminishes for quite a while insofar as you're still in the exchange is the most significant piece of this technique.convert money online
ReplyDeleteHowdy, I discovered your blog through Google while hunting down such kinda instructive post and your post looks extremely intriguing for me.
ReplyDeletebinance
But others, they use the money to buy liabilities. Some have been destroyed by failure to properly handle money.소액결제현금화
ReplyDeleteOutstanding blog thanks for sharing such a wonderful blog with us ,after a long time came across such a knowledgeable blog. keep sharing such informative blogs with us. Neteller exchanger in india
ReplyDeleteCryptocurrencies are the latest 'big thing' in the digital world and Play games and win Ethereum have now been recognized as being part of the monetary system. In fact, enthusiasts have tagged it as 'the revolution of money'.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteYou have shared a magnificent post about exchange rates. I think his blog is very helpful for us. Thank you for providing such an informative post. Quick Pay Exchange Rate Today
ReplyDelete