Skip to content

Commit

Permalink
Added exchanges: Atomic Trade, C-CEX, CoinMkt, Coins-E and Vircurex.
Browse files Browse the repository at this point in the history
  • Loading branch information
dllud committed Oct 16, 2014
1 parent ed9852a commit 7e4fdc6
Show file tree
Hide file tree
Showing 19 changed files with 625 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The main goal of libdynticker is to get the traded pairs dynamically. That way i
* [CaVirtEx](https://www.cavirtex.com)
* [CEX.IO](http://cex.io)
* [CHBTC](https://www.chbtc.com)
* [CoinMkt](https://coinmkt.com)
* [Huobi](https://www.huobi.com)
* [itBit](https://www.itbit.com)
* [Justcoin](https://justcoin.com)
Expand All @@ -35,16 +36,20 @@ The main goal of libdynticker is to get the traded pairs dynamically. That way i

### Altcoins
* [AllCoin](https://www.allcoin.com)
* [Atomic Trade](https://www.atomic-trade.com)
* [Bittrex](https://bittrex.com)
* [BlueTrade](https://bleutrade.com)
* [BTC38](http://www.btc38.com)
* [C-CEX](https://c-cex.com)
* [CCEDK](https://www.ccedk.com)
* [Coins-E](http://coins-e.com)
* [Cryptonit](https://cryptonit.net)
* [Cryptsy](https://cryptsy.com)
* [Coin-Swap](https://coin-swap.net)
* [HitBTC](https://hitbtc.com)
* [Mintpal](https://mintpal.com)
* [Poloniex](https://www.poloniex.com)
* [Vircurex](https://vircurex.com)
* [VoS](https://www.vaultofsatoshi.com)

### Bullion
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jdk.version>1.6</jdk.version>
<release.description>
\+ Added exchanges: BitBay, Bitcurex, BitMarket.pl, CCEDK, Crypto-Trade, Cryptonit, Justcoin and Paymium.
\+ Added exchanges: Atomic Trade, BitBay, Bitcurex, BitMarket.pl, C-CEX, CCEDK, CoinMkt, Coins-E, Crypto-Trade, Cryptonit, Justcoin, Paymium and Vircurex.
\* Corrected bugs in several exchanges which were listing inactive pairs.
</release.description>
</properties>
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/mobi/boilr/libdynticker/core/Exchange.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

/**
* Abstract template for Exchange
*
* @author andre
*
*/
public abstract class Exchange {

Expand All @@ -27,8 +24,6 @@ public Exchange(String name, long experiedPeriod) {
}

/**
*
*
* @param pair
* of exchange/coin
*
Expand All @@ -46,11 +41,11 @@ public double getLastValue(Pair pair) throws NumberFormatException, IOException

final public List<Pair> getPairs() throws IOException {
long currentTime = System.currentTimeMillis();
if (timestamp == null) {
if(timestamp == null) {
pairs = getPairsFromAPI();
timestamp = new Timestamp(currentTime);
return pairs;
} else if ((currentTime - getTimestamp().getTime()) < getExperiedPeriod()) {
} else if((currentTime - getTimestamp().getTime()) < getExperiedPeriod()) {
return pairs;
} else {
// TODO throw a custom exception where there is no internet connection. The exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package mobi.boilr.libdynticker.exchanges;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import mobi.boilr.libdynticker.core.Exchange;
import mobi.boilr.libdynticker.core.Pair;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

public class AtomicTradeExchange extends Exchange {

public AtomicTradeExchange(long experiedPeriod) {
super("Atomic Trade", experiedPeriod);
}

@Override
protected List<Pair> getPairsFromAPI() throws MalformedURLException, IOException {
List<Pair> pairs = new ArrayList<Pair>();
TypeReference<List<String>> typeRef = new TypeReference<List<String>>() {
};
URLConnection urlConnection = (new URL("https://www.atomic-trade.com/SimpleAPI?a=markets")).openConnection();
urlConnection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
urlConnection.connect();
List<String> symbols = (new ObjectMapper()).readValue(urlConnection.getInputStream(), typeRef);
String[] pairSplit;
for (String sym : symbols) {
pairSplit = sym.split("/");
pairs.add(new Pair(pairSplit[0], pairSplit[1]));
}
return pairs;
}

@Override
protected String getTicker(Pair pair) throws MalformedURLException, IOException {
// https://www.atomic-trade.com/GetPrices?c=BLC&p=BTC
URLConnection urlConnection = (new URL("https://www.atomic-trade.com/GetPrices?c="
+ pair.getCoin() + "&p=" + pair.getExchange())).openConnection();
urlConnection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
urlConnection.connect();
JsonNode node = (new ObjectMapper()).readTree(urlConnection.getInputStream());
if(node.get("error").getBooleanValue())
throw new MalformedURLException();
return parseJSON(node, pair);
}

@Override
public String parseJSON(JsonNode node, Pair pair) {
return node.get("price").getTextValue();
}

}
53 changes: 53 additions & 0 deletions src/main/java/mobi/boilr/libdynticker/exchanges/CCEXExchange.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package mobi.boilr.libdynticker.exchanges;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import mobi.boilr.libdynticker.core.Exchange;
import mobi.boilr.libdynticker.core.Pair;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

public class CCEXExchange extends Exchange {

public CCEXExchange(long experiedPeriod) {
super("C-CEX", experiedPeriod);
}

@Override
protected List<Pair> getPairsFromAPI() throws JsonProcessingException, MalformedURLException,
IOException {
List<Pair> pairs = new ArrayList<Pair>();
JsonNode node = (new ObjectMapper()).readTree(new URL("https://c-cex.com/t/pairs.json"));
TypeReference<List<String>> typeRef = new TypeReference<List<String>>() {
};
List<String> symbols = (new ObjectMapper()).readValue(node.get("pairs"), typeRef);
String[] pairSplit;
for (String sym : symbols) {
pairSplit = sym.toUpperCase().split("-");
pairs.add(new Pair(pairSplit[0], pairSplit[1]));
}
return pairs;
}

@Override
protected String getTicker(Pair pair) throws JsonProcessingException, MalformedURLException,
IOException {
// https://c-cex.com/t/btc-usd.json
JsonNode node = (new ObjectMapper()).readTree(new URL("https://c-cex.com/t/"
+ pair.getCoin().toLowerCase() + "-" + pair.getExchange().toLowerCase() + ".json"));
return parseJSON(node, pair);
}

@Override
public String parseJSON(JsonNode node, Pair pair) {
return node.get("ticker").get("lastprice").asText();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package mobi.boilr.libdynticker.exchanges;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import mobi.boilr.libdynticker.core.Exchange;
import mobi.boilr.libdynticker.core.Pair;

import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;

public class CoinMktExchange extends Exchange {
public static final long COINMKT_DELAY = 15000;
private Random random = new Random();

public CoinMktExchange(long experiedPeriod) {
super("CoinMkt", experiedPeriod);
}

@Override
protected List<Pair> getPairsFromAPI() throws JsonProcessingException, MalformedURLException,
IOException {
List<Pair> pairs = new ArrayList<Pair>();
JsonNode node = (new ObjectMapper()).readTree(new URL("https://api.coinmkt.com/v1/currency/pairs/" + random.nextInt()));
if(node.get("Code").getIntValue() < 0) {
throw new IOException(node.get("Err").getTextValue());
}
Iterator<JsonNode> elements = node.get("Pairs").getElements();
for (String[] pairSplit; elements.hasNext();) {
pairSplit = elements.next().get("Pair").getTextValue().split("_");
pairs.add(new Pair(pairSplit[0], pairSplit[1]));
}
return pairs;
}

@Override
protected String getTicker(Pair pair) throws JsonProcessingException, MalformedURLException,
IOException {
// https://api.coinmkt.com/v1/ticker/RANDOMKEY/DOGE_BTC/1
JsonNode node = (new ObjectMapper()).readTree(new URL("https://api.coinmkt.com/v1/ticker/"
+ random.nextInt() + "/" + pair.getCoin() + "_" + pair.getExchange() + "/1"));
if(node.get("Code").getIntValue() < 0) {
throw new IOException(node.get("Err").getTextValue());
}
return parseJSON(node, pair);
}

@Override
public String parseJSON(JsonNode node, Pair pair) {
return node.get("Last").asText();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package mobi.boilr.libdynticker.exchanges;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
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;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;

public class CoinsEExchange extends Exchange {

public CoinsEExchange(long experiedPeriod) {
super("Coins-E", experiedPeriod);
}

@Override
protected List<Pair> getPairsFromAPI() throws JsonProcessingException, MalformedURLException,
IOException {
List<Pair> pairs = new ArrayList<Pair>();
JsonNode node = (new ObjectMapper()).readTree(new URL("https://www.coins-e.com/api/v2/markets/list/"));
if(!node.get("status").getBooleanValue()) {
throw new IOException(node.get("message").getTextValue());
}
Iterator<JsonNode> elements = node.get("markets").getElements();
for (JsonNode element; elements.hasNext();) {
element = elements.next();
if(element.get("status").getTextValue().equals("healthy")) {
pairs.add(new Pair(element.get("c1").getTextValue(), element.get("c2").getTextValue()));
}
}
return pairs;
}

@Override
protected String getTicker(Pair pair) throws JsonProcessingException, MalformedURLException,
IOException {
// https://www.coins-e.com/api/v2/market/DRK_BTC/trades/
JsonNode node = (new ObjectMapper()).readTree(new URL("https://www.coins-e.com/api/v2/market/"
+ pair.getCoin() + "_" + pair.getExchange() + "/trades/"));
if(!node.get("status").getBooleanValue()) {
throw new IOException(node.get("message").getTextValue());
}
return parseJSON(node, pair);
}

@Override
public String parseJSON(JsonNode node, Pair pair) throws IOException {
node = node.get("trades");
if(!node.getElements().hasNext())
throw new IOException("Trades for " + pair + " are empty.");
return node.get(0).get("rate").getTextValue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ protected List<Pair> getPairsFromAPI() throws IOException {
JsonNode node = (new ObjectMapper()).readTree(uc.getInputStream()).get("result");
Iterator<String> fieldNames = node.getFieldNames();
String coin, exchange;
for(JsonNode jsonNode; fieldNames.hasNext();) {
for (JsonNode jsonNode; fieldNames.hasNext();) {
jsonNode = node.get(fieldNames.next());
coin = jsonNode.get("base").getTextValue().substring(1);
exchange = jsonNode.get("quote").getTextValue().substring(1);
pairs.add(new Pair(coin, exchange));
}

return pairs;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package mobi.boilr.libdynticker.exchanges;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
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;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;

public class VircurexExchange extends Exchange {

public VircurexExchange(long experiedPeriod) {
super("Vircurex", experiedPeriod);
}

@Override
protected List<Pair> getPairsFromAPI() throws JsonProcessingException, MalformedURLException,
IOException {
List<Pair> pairs = new ArrayList<Pair>();
URLConnection urlConnection = (new URL("https://api.vircurex.com/api/get_info_for_currency.json")).openConnection();
urlConnection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
urlConnection.connect();
JsonNode coinsNode = (new ObjectMapper()).readTree(urlConnection.getInputStream());
if(coinsNode.get("status").asBoolean())
throw new IOException(coinsNode.get("status_text").getTextValue());
Iterator<String> coins = coinsNode.getFieldNames();
String coin;
for (Iterator<String> exchanges; coins.hasNext();) {
coin = coins.next();
exchanges = coinsNode.get(coin).getFieldNames();
while (exchanges.hasNext()) {
pairs.add(new Pair(coin, exchanges.next()));
}
}
return pairs;
}

@Override
protected String getTicker(Pair pair) throws JsonProcessingException, MalformedURLException,
IOException {
// https://api.vircurex.com/api/get_last_trade.json?base=BTC&alt=EUR
URLConnection urlConnection = (new URL("https://api.vircurex.com/api/get_last_trade.json?base="
+ pair.getCoin() + "&alt=" + pair.getExchange())).openConnection();
urlConnection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
urlConnection.connect();
JsonNode node = (new ObjectMapper()).readTree(urlConnection.getInputStream());
if(node.get("status").asBoolean())
throw new IOException(node.get("status_text").getTextValue());
return parseJSON(node, pair);
}

@Override
public String parseJSON(JsonNode node, Pair pair) {
return node.get("value").getTextValue();
}

}
Loading

0 comments on commit 7e4fdc6

Please sign in to comment.