-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added exchanges: Atomic Trade, C-CEX, CoinMkt, Coins-E and Vircurex.
- Loading branch information
dllud
committed
Oct 16, 2014
1 parent
ed9852a
commit 7e4fdc6
Showing
19 changed files
with
625 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/mobi/boilr/libdynticker/exchanges/AtomicTradeExchange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
src/main/java/mobi/boilr/libdynticker/exchanges/CCEXExchange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/mobi/boilr/libdynticker/exchanges/CoinMktExchange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/mobi/boilr/libdynticker/exchanges/CoinsEExchange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/mobi/boilr/libdynticker/exchanges/VircurexExchange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.