Skip to content

Commit

Permalink
refactored for new webservice API
Browse files Browse the repository at this point in the history
  • Loading branch information
timmolter committed Aug 28, 2014
1 parent 405aef7 commit 5854c4e
Show file tree
Hide file tree
Showing 22 changed files with 1,613 additions and 658 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.xeiam.xchange.bitcoinium;

import java.io.IOException;

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
Expand All @@ -13,20 +16,21 @@
/**
* @author veken0m
*/
@Path("service")
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public interface Bitcoinium {

@GET
@Path("tickerupdate")
public BitcoiniumTicker getTicker(@QueryParam("pair") String pair, @QueryParam("apikey") String apikey);
@Path("ticker")
public BitcoiniumTicker getTicker(@QueryParam("pair") String pair, @HeaderParam("X-BITCOINIUM-API-KEY") String apikey) throws IOException;

@GET
@Path("orderbook")
public BitcoiniumOrderbook getDepth(@QueryParam("pair") String pair, @QueryParam("pricewindow") String pricewindow, @QueryParam("apikey") String apikey);
public BitcoiniumOrderbook getDepth(@QueryParam("pair") String pair, @QueryParam("orderbookwindow") String orderbookwindow, @HeaderParam("X-BITCOINIUM-API-KEY") String apikey) throws IOException;

@GET
@Path("tickerhistory")
public BitcoiniumTickerHistory getTickerHistory(@QueryParam("pair") String pair, @QueryParam("timewindow") String timewindow, @QueryParam("apikey") String apikey);
public BitcoiniumTickerHistory getTickerHistory(@QueryParam("pair") String pair, @QueryParam("historytimewindow") String historytimewindow, @HeaderParam("X-BITCOINIUM-API-KEY") String apikey)
throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import com.xeiam.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook;
import com.xeiam.xchange.bitcoinium.dto.marketdata.BitcoiniumOrderbook.CondensedOrder;
import com.xeiam.xchange.bitcoinium.dto.marketdata.BitcoiniumTicker;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.Order;
Expand All @@ -28,7 +29,7 @@ private BitcoiniumAdapters() {

/**
* Adapts a BitcoiniumTicker to a Ticker Object
*
*
* @param bitcoiniumTicker
* @return
*/
Expand All @@ -46,26 +47,26 @@ public static Ticker adaptTicker(BitcoiniumTicker bitcoiniumTicker, CurrencyPair

/**
* Adapts a BitcoiniumOrderbook to a OrderBook Object
*
*
* @param bitcoiniumOrderbook
* @param CurrencyPair currencyPair (e.g. BTC/USD)
* @return the XChange OrderBook
*/
public static OrderBook adaptOrderbook(BitcoiniumOrderbook bitcoiniumOrderbook, CurrencyPair currencyPair) {

List<LimitOrder> asks = createOrders(currencyPair, Order.OrderType.ASK, bitcoiniumOrderbook.getAskPriceList(), bitcoiniumOrderbook.getAskVolumeList());
List<LimitOrder> bids = createOrders(currencyPair, Order.OrderType.BID, bitcoiniumOrderbook.getBidPriceList(), bitcoiniumOrderbook.getBidVolumeList());
Date date = new Date(bitcoiniumOrderbook.getTimestamp()); // Note, this is the timestamp of the piggy-backed Ticker.
List<LimitOrder> asks = createOrders(currencyPair, Order.OrderType.ASK, bitcoiniumOrderbook.getAsks());
List<LimitOrder> bids = createOrders(currencyPair, Order.OrderType.BID, bitcoiniumOrderbook.getBids());
Date date = new Date(bitcoiniumOrderbook.getBitcoiniumTicker().getTimestamp()); // Note, this is the timestamp of the piggy-backed Ticker.
return new OrderBook(date, asks, bids);

}

public static List<LimitOrder> createOrders(CurrencyPair currencyPair, Order.OrderType orderType, List<BigDecimal> prices, List<BigDecimal> volumes) {
public static List<LimitOrder> createOrders(CurrencyPair currencyPair, Order.OrderType orderType, CondensedOrder[] condensedOrders) {

List<LimitOrder> limitOrders = new ArrayList<LimitOrder>();
for (int i = 0; i < prices.size(); i++) {
for (int i = 0; i < condensedOrders.length; i++) {

LimitOrder limitOrder = new LimitOrder(orderType, volumes.get(i), currencyPair, "", null, prices.get(i));
LimitOrder limitOrder = new LimitOrder(orderType, condensedOrders[i].getVolume(), currencyPair, "", null, condensedOrders[i].getPrice());
limitOrders.add(limitOrder);
}
return limitOrders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public void applySpecification(ExchangeSpecification exchangeSpecification) {
public ExchangeSpecification getDefaultExchangeSpecification() {

ExchangeSpecification exchangeSpecification = new ExchangeSpecification(this.getClass().getCanonicalName());
exchangeSpecification.setSslUri("https://bitcoinium.com");
exchangeSpecification.setHost("bitcoinium.com");
// exchangeSpecification.setPlainTextUri("http://173.10.241.154:9090");
exchangeSpecification.setPlainTextUri("http://127.0.0.1:9090");
// exchangeSpecification.setHost("173.10.241.154:9090");
exchangeSpecification.setHost("127.0.0.1:9090");
exchangeSpecification.setPort(9090);
exchangeSpecification.setExchangeName("Bitcoinium");
exchangeSpecification.setExchangeDescription("Bitcoinium Web Service provides compact and filtered data from various exchanges");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ private BitcoiniumUtils() {

public static final List<String> PRICE_WINDOW = Arrays.asList(

"2p", "5p", "10p", "20p", "50p", "100p"
"TWO_PERCENT", "FIVE_PERCENT", "TEN_PERCENT", "TWENTY_PERCENT", "FIFTY_PERCENT", "ONE_HUNDRED_PERCENT"

);
);

public static final List<String> TIME_WINDOW = Arrays.asList(

"10m", "1h", "3h", "12h", "24h", "3d", "7d", "30d", "2M"
"ONE_HOUR", "THREE_HOURS", "TWELVE_HOURS", "TWENTY_FOUR_HOURS", "THREE_DAYS", "SEVEN_DAYS", "THIRTY_DAYS", "TWO_MONTHS"

);
);

/**
* Creates a valid currency pair for Bitcoinium.com
*
*
* @param tradableIdentifier
* @param currency
* @param exchange
Expand All @@ -43,7 +43,7 @@ public static String createCurrencyPairString(String tradableIdentifier, String

/**
* Checks if a given PriceWindow is covered by this exchange
*
*
* @param priceWindow
* @return
*/
Expand All @@ -54,7 +54,7 @@ public static boolean isValidPriceWindow(String priceWindow) {

/**
* Checks if a given TimeWindow is covered by this exchange
*
*
* @param timeWindow
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.xeiam.xchange.bitcoinium.dto.marketdata;

import java.math.BigDecimal;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand All @@ -10,110 +9,67 @@
*/
public final class BitcoiniumOrderbook {

private final List<BigDecimal> askPrices;
private final List<BigDecimal> askVolumes;
private final List<BigDecimal> bidPrices;
private final List<BigDecimal> bidVolumes;
private final BigDecimal high;
private final BigDecimal low;
private final BigDecimal bid;
private final BigDecimal ask;
private final BigDecimal last;
private final BigDecimal volume;
private final long timestamp;
private final BitcoiniumTicker bitcoiniumTicker;
private final CondensedOrder[] bids;
private final CondensedOrder[] asks;

/**
* Constructor
*
* @param ap
* @param av
* @param bp
* @param bv
* @param last
* @param high
* @param low
* @param bid
* @param ask
* @param volume
* @param timestamp
*
* @param bitcoiniumTicker
* @param bids
* @param asks
*/
public BitcoiniumOrderbook(@JsonProperty("ap") List<BigDecimal> ap, @JsonProperty("av") List<BigDecimal> av, @JsonProperty("bp") List<BigDecimal> bp, @JsonProperty("bv") List<BigDecimal> bv,
@JsonProperty("l") BigDecimal last, @JsonProperty("h") BigDecimal high, @JsonProperty("lo") BigDecimal low, @JsonProperty("b") BigDecimal bid, @JsonProperty("a") BigDecimal ask,
@JsonProperty("v") BigDecimal volume, @JsonProperty("t") long timestamp) {

this.askPrices = ap;
this.askVolumes = av;
this.bidPrices = bp;
this.bidVolumes = bv;
this.last = last;
this.volume = volume;
this.high = high;
this.low = low;
this.bid = bid;
this.ask = ask;
this.timestamp = timestamp;
}

public List<BigDecimal> getAskPriceList() {

return this.askPrices;
}

public List<BigDecimal> getAskVolumeList() {

return this.askVolumes;
}

public List<BigDecimal> getBidPriceList() {

return this.bidPrices;
}
public BitcoiniumOrderbook(@JsonProperty("ticker") BitcoiniumTicker bitcoiniumTicker, @JsonProperty("bids") CondensedOrder[] bids, @JsonProperty("asks") CondensedOrder[] asks) {

public List<BigDecimal> getBidVolumeList() {

return this.bidVolumes;
this.bitcoiniumTicker = bitcoiniumTicker;
this.bids = bids;
this.asks = asks;
}

public BigDecimal getLast() {
public CondensedOrder[] getBids() {

return this.last;
return bids;
}

public long getTimestamp() {
public CondensedOrder[] getAsks() {

return this.timestamp;
return asks;
}

public BigDecimal getVolume() {
public BitcoiniumTicker getBitcoiniumTicker() {

return this.volume;
return bitcoiniumTicker;
}

public BigDecimal getHigh() {

return this.high;
}

public BigDecimal getLow() {
/**
* This class represents not just a single order in the orderbook, but a bunch of them condensed into one.
*/
public static final class CondensedOrder {

return this.low;
}
private final BigDecimal price;
private final BigDecimal volume;

public BigDecimal getBid() {
/**
* Constructor
*
* @param price
* @param volume
*/
public CondensedOrder(@JsonProperty("p") BigDecimal price, @JsonProperty("v") BigDecimal volume) {

return this.bid;
}
this.price = price;
this.volume = volume;
}

public BigDecimal getAsk() {
public BigDecimal getPrice() {

return this.ask;
}
return price;
}

@Override
public String toString() {
public BigDecimal getVolume() {

return "BitcoiniumOrderbook [askPrice=" + askPrices + ", askVolume=" + askVolumes + ", buyPrice=" + bidPrices + ", buyVolume=" + bidVolumes + ", high=" + high + ", low=" + low + ", bid=" + bid
+ ", ask=" + ask + ", last=" + last + ", volume=" + volume + ", timestamp=" + timestamp + "]";
return volume;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public final class BitcoiniumTicker {
private final BigDecimal low;
private final BigDecimal bid;
private final BigDecimal ask;
private final boolean isAllTimeHigh;
private final BigDecimal trades;

/**
* Constructor
*
*
* @param last
* @param timestamp
* @param volume
Expand All @@ -31,7 +31,7 @@ public final class BitcoiniumTicker {
* @param isAllTimeHigh
*/
public BitcoiniumTicker(@JsonProperty("l") BigDecimal last, @JsonProperty("t") long timestamp, @JsonProperty("v") BigDecimal volume, @JsonProperty("h") BigDecimal high,
@JsonProperty("lo") BigDecimal low, @JsonProperty("b") BigDecimal bid, @JsonProperty("a") BigDecimal ask, @JsonProperty("ath") String isAllTimeHigh) {
@JsonProperty("lo") BigDecimal low, @JsonProperty("b") BigDecimal bid, @JsonProperty("a") BigDecimal ask, @JsonProperty("tr") BigDecimal trades) {

this.last = last;
this.timestamp = timestamp;
Expand All @@ -40,7 +40,7 @@ public BitcoiniumTicker(@JsonProperty("l") BigDecimal last, @JsonProperty("t") l
this.low = low;
this.bid = bid;
this.ask = ask;
this.isAllTimeHigh = isAllTimeHigh.equals("T");
this.trades = trades;
}

public BigDecimal getLast() {
Expand Down Expand Up @@ -78,15 +78,15 @@ public BigDecimal getAsk() {
return this.ask;
}

public boolean isAllTimeHigh() {
public BigDecimal getTrades() {

return isAllTimeHigh;
return trades;
}

@Override
public String toString() {

return "BitcoiniumTicker [last=" + last + ", timestamp=" + timestamp + ", volume=" + volume + ", high=" + high + ", low=" + low + ", bid=" + bid + ", ask=" + ask + "]";
return "BitcoiniumTicker [last=" + last + ", timestamp=" + timestamp + ", volume=" + volume + ", high=" + high + ", low=" + low + ", bid=" + bid + ", ask=" + ask + ", trades=" + trades + "]";
}

}
Loading

0 comments on commit 5854c4e

Please sign in to comment.