-
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.
Showing
8 changed files
with
190 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
57 changes: 57 additions & 0 deletions
57
src/main/java/mobi/boilr/libdynticker/exchanges/OneBseExchange.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,57 @@ | ||
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.map.ObjectMapper; | ||
|
||
public class OneBseExchange extends Exchange { | ||
|
||
public OneBseExchange(long experiedPeriod) { | ||
super("1Bce", experiedPeriod); | ||
} | ||
|
||
@Override | ||
protected List<Pair> getPairsFromAPI() throws IOException { | ||
String url = "https://www.1bse.com/allprices.json"; | ||
List<Pair> pairs = new ArrayList<Pair>(); | ||
JsonNode node = new ObjectMapper().readTree(new URL(url)); | ||
|
||
if(node.get("success").getTextValue().equals("1")) { | ||
JsonNode ret = node.get("return"); | ||
Iterator<String> fieldNames = ret.getFieldNames(); | ||
String[] split; | ||
while(fieldNames.hasNext()) { | ||
split = fieldNames.next().split("_"); | ||
pairs.add(new Pair(split[0].toUpperCase(), split[1].toUpperCase())); | ||
} | ||
} | ||
else { | ||
throw new IOException("Could not retreive pairs from " + getName() + "."); | ||
} | ||
return pairs; | ||
} | ||
|
||
@Override | ||
protected String getTicker(Pair pair) throws IOException { | ||
String url = "https://www.1bse.com/allprices.json"; | ||
JsonNode node = new ObjectMapper().readTree(new URL(url)); | ||
if(node.get("success").getTextValue().equals("1")) | ||
return parseJSON(node, pair); | ||
else | ||
throw new MalformedURLException(); | ||
} | ||
|
||
@Override | ||
public String parseJSON(JsonNode node, Pair pair) throws IOException { | ||
return node.get("return").get(pair.getCoin().toLowerCase() + "_" + pair.getExchange().toLowerCase()).get("price").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
58 changes: 58 additions & 0 deletions
58
src/test/java/mobi/boilr/libdynticker/exchanges/OneBseExchangeTest.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.File; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import mobi.boilr.libdynticker.core.ExchangeTest; | ||
import mobi.boilr.libdynticker.core.Pair; | ||
|
||
import org.codehaus.jackson.JsonNode; | ||
import org.codehaus.jackson.map.ObjectMapper; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class OneBseExchangeTest extends ExchangeTest { | ||
|
||
@Override | ||
@Before | ||
public void setUp() throws Exception { | ||
testExchange = new OneBseExchange(1000); | ||
} | ||
|
||
@Override | ||
@After | ||
public void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
public void testParseJson() { | ||
try { | ||
Pair pair = new Pair("BTC", "USD"); | ||
JsonNode node = (new ObjectMapper().readTree(new File("src/test/json/1bse-ticker.json"))); | ||
String lastValue = testExchange.parseJSON(node, pair); | ||
Assert.assertEquals("373.4329", lastValue); | ||
} | ||
catch(IOException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetPairs() { | ||
List<Pair> pairs; | ||
try { | ||
pairs = testExchange.getPairs(); | ||
Assert.assertTrue(pairs.contains(new Pair("BTC", "USD"))); | ||
Assert.assertTrue(pairs.contains(new Pair("BTC", "EUR"))); | ||
Assert.assertFalse(pairs.contains(new Pair("InvalidCoin", "BTC"))); | ||
} | ||
catch(IOException e) { | ||
e.printStackTrace(); | ||
Assert.fail(); | ||
} | ||
} | ||
} |
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 @@ | ||
{"success":"1","return":{"btc_hkd":{"price":"2912.7759","status":"buy","volume":"41.15219"},"btc_usd":{"price":"373.4329","status":"buy","volume":"44.4239"},"btc_eur":{"price":"298.7423","status":"buy","volume":"43.99374"},"ltc_hkd":{"price":"30.3347","status":"sell","volume":"904.9875"},"ltc_usd":{"price":"3.8841","status":"sell","volume":"1187.86805"},"ltc_eur":{"price":"3.1063","status":"sell","volume":"1203.87942"},"ltc_btc":{"price":"0.01048","status":"sell","volume":"68.34239"},"btc_cny":{"price":"2315.2877","status":"buy","volume":"47.31296"},"btc_sgd":{"price":"485.4665","status":"buy","volume":"51.3111"},"ltc_cny":{"price":"24.1093","status":"sell","volume":"1080.84824"},"ltc_sgd":{"price":"5.0528","status":"sell","volume":"1175.59023"},"doge_hkd":{"price":"0.00198027","status":"buy","volume":"2671322.11903"},"doge_usd":{"price":"0.00025415","status":"buy","volume":"2971556.8088"},"doge_cny":{"price":"0.00157478","status":"buy","volume":"2614673.78244"},"doge_btc":{"price":"0.00000068","status":"unch","volume":"564027.06652"},"doge_ltc":{"price":"0.00006477","status":"unch","volume":"257682.21237"},"drk_hkd":{"price":"24.07645","status":"buy","volume":"3795.68269"},"drk_usd":{"price":"3.09151","status":"buy","volume":"3318.7443"},"drk_eur":{"price":"2.47095","status":"buy","volume":"3277.11109"},"drk_cny":{"price":"19.13641","status":"buy","volume":"3267.15913"},"drk_btc":{"price":"0.0068868","status":"unch","volume":"50.37416"},"drk_ltc":{"price":"0.79593986","status":"buy","volume":"40.67421"}}} |
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 @@ | ||
{"ticker":[{"buy":374.1,"contractId":20141024012,"high":386.51,"last":374.1,"low":372.35,"sell":374.66,"unitAmount":100.0,"volume":78810.0}]} |