In this post, I will show you how to retrieve currency exchange rate from yahoo finance api by Java program. There are some apis for getting exchange rate - reuters, bloomberg, yahoo finance etc. If you don't have to get high-ratency realtime exchange rate, the most simple and free api - yahoo finance api - is enough. Okay, here is the actual code. The api returns exchange rate as a Rate object. package com.dukesoftware.exchangerate.api; import static java.lang.String.format; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URI; public class YahooExchangeRateApi implements ExchangeRateApi { // url for yahoo finance api private final static String URL_FORMAT = "http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=%s%s=X"; public Rate getRate(String ccy1, String ccy2) { assertNotNull(ccy1, ...
IT関連の技術やプログラミングを中心に記事を書いています。ハードウェアも好きなので、日々のちょっとしたお役立ち情報も投稿しています。