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
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));

26 comments:

  1. hi! how can i get oil prise by same method?

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete

  3. Calculate 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 .

    ReplyDelete
  4. 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.

    ReplyDelete
  5. hi 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

    ReplyDelete
  6. There are numerous kinds of currency converters on the web. The sorts vary by their planned purposes and the data they give. exchange rates widget

    ReplyDelete
  7. The 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

    ReplyDelete
  8. Hey. 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

    ReplyDelete
  9. A 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

    ReplyDelete
  10. I 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

    ReplyDelete
  11. I went over this website and 200 euros to usd
    I believe you have a lot of wonderful information, saved to my bookmarks

    ReplyDelete
  12. 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

    ReplyDelete
  13. There are numerous sorts of cash converter accessible and these will regularly cover you for an assortment of conditions. convert money

    ReplyDelete
  14. Thank you for taking the time to publish this information very useful! convert money online

    ReplyDelete
  15. In 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

    ReplyDelete
  16. Hi there! Nice stuff, do keep me posted when you post again something like this! convert currency

    ReplyDelete
  17. With 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

    ReplyDelete
  18. Howdy, I discovered your blog through Google while hunting down such kinda instructive post and your post looks extremely intriguing for me.
    binance

    ReplyDelete
  19. But others, they use the money to buy liabilities. Some have been destroyed by failure to properly handle money.소액결제현금화

    ReplyDelete
  20. Outstanding 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

    ReplyDelete
  21. Cryptocurrencies 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'.

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. You 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
  24. Your blogs are great. Are you also searching for Help with my Math assignment? we are the best solution for you. We are best known for delivering quality essay writing services to students without having to break the bank

    ReplyDelete
  25. I love it here. Keep sharing your good vibes. I love them Are you also searching for Cheap Nursing Writing Company? we are the best solution for you. We are best known for delivering cheap assignments to students without having to break the bank

    ReplyDelete

Blogroll

Popular Posts