package mobi.boilr.libdynticker.exchanges; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import mobi.boilr.libdynticker.core.Exchange; import mobi.boilr.libdynticker.core.Pair; import org.codehaus.jackson.JsonNode; public final class LakeBTCExchange extends Exchange { private static final List<Pair> pairs; static { List<Pair> tempPairs = new ArrayList<Pair>(); tempPairs.add(new Pair("BTC", "USD")); tempPairs.add(new Pair("BTC", "CNY")); pairs = Collections.unmodifiableList(tempPairs); } public LakeBTCExchange(long expiredPeriod) { super("LakeBTC", expiredPeriod); } @Override protected List<Pair> getPairsFromAPI() throws IOException { return pairs; } @Override protected String getTicker(Pair pair) throws IOException { if(!pairs.contains(pair)) throw new IOException("Invalid pair: " + pair); JsonNode node = readJsonFromUrl("https://www.lakebtc.com/api_v1/ticker"); return parseTicker(node, pair); } @Override public String parseTicker(JsonNode node, Pair pair) throws IOException { return node.get(pair.getExchange()).get("last").asText(); } }