mobi.boilr.libdynticker.exchanges.LocalBitcoinsExchange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of libdynticker Show documentation
Show all versions of libdynticker Show documentation
Java library to retrieve trading pairs and last value from cryptocurrency and bullion exchanges.
The newest version!
package mobi.boilr.libdynticker.exchanges;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import mobi.boilr.libdynticker.core.Exchange;
import mobi.boilr.libdynticker.core.Pair;
import org.codehaus.jackson.JsonNode;
public final class LocalBitcoinsExchange extends Exchange {
public LocalBitcoinsExchange(long expiredPeriod) {
super("LocalBitcoins", expiredPeriod);
}
@Override
protected List getPairsFromAPI() throws IOException {
JsonNode node = readJsonFromUrl("https://localbitcoins.com/bitcoinaverage/ticker-all-currencies/");
List pairs = new ArrayList();
Iterator exchanges = node.getFieldNames();
while(exchanges.hasNext()) {
// LocalBitcoins only deals with BTC to others currencies
pairs.add(new Pair("BTC", exchanges.next()));
}
return pairs;
}
@Override
protected String getTicker(Pair pair) throws IOException {
JsonNode node = readJsonFromUrl("https://localbitcoins.com/bitcoinaverage/ticker-all-currencies/");
if(node.has(pair.getExchange().toUpperCase())) {
return parseTicker(node, pair);
} else {
throw new IOException();
}
}
@Override
public String parseTicker(JsonNode node, Pair pair) throws IOException {
return node.get(pair.getExchange()).get("rates").get("last").getTextValue();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy