All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mobi.boilr.libdynticker.exchanges.BTERExchange Maven / Gradle / Ivy

Go to download

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 BTERExchange extends Exchange {

	public BTERExchange(long expiredPeriod) {
		super("Bter", expiredPeriod);
	}

	@Override
	protected List getPairsFromAPI() throws IOException {
		List pairs = new ArrayList();
		Iterator elements = readJsonFromUrl("http://data.bter.com/api/1/pairs").getElements();
		for(String[] split; elements.hasNext();) {
			split = elements.next().getTextValue().toUpperCase().split("_");
			pairs.add(new Pair(split[0], split[1]));
		}
		return pairs;
	}
	
	@Override
	protected String getTicker(Pair pair) throws IOException {
		JsonNode node = readJsonFromUrl("http://data.bter.com/api/1/ticker/" +
				pair.getCoin() + "_" + pair.getExchange());
		if(node.get("result").getTextValue().equals("true")) {
			return parseTicker(node, pair);
		} else {
			throw new IOException(node.get("message").getTextValue());
		}
	}


	@Override
	public String parseTicker(JsonNode node, Pair pair) throws IOException {
		JsonNode lastValueNode = node.get("last");
		if(lastValueNode.isTextual())
			return lastValueNode.getTextValue();
		else
			return lastValueNode.asText();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy