Skip to content

Commit

Permalink
open orders, cancel order, error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
stachon committed Apr 11, 2015
1 parent b50e09c commit c3344ec
Show file tree
Hide file tree
Showing 19 changed files with 1,076 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import com.xeiam.xchange.coinmate.dto.marketdata.CoinmateTicker;
import com.xeiam.xchange.coinmate.dto.marketdata.CoinmateTransactions;
import com.xeiam.xchange.coinmate.dto.marketdata.CoinmateTransactionsEntry;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateOpenOrders;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateOpenOrdersEntry;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateTransactionHistory;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateTransactionHistoryDataEntry;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateTransactionHistoryEntry;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.Order;
import com.xeiam.xchange.dto.account.AccountInfo;
Expand All @@ -41,14 +43,14 @@
import com.xeiam.xchange.dto.marketdata.Trade;
import com.xeiam.xchange.dto.marketdata.Trades;
import com.xeiam.xchange.dto.trade.LimitOrder;
import com.xeiam.xchange.dto.trade.OpenOrders;
import com.xeiam.xchange.dto.trade.UserTrade;
import com.xeiam.xchange.dto.trade.UserTrades;
import com.xeiam.xchange.dto.trade.Wallet;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
*
Expand Down Expand Up @@ -121,7 +123,7 @@ public static AccountInfo adaptAccountInfo(CoinmateBalance coinmateBalance) {
public static UserTrades adaptTradeHistory(CoinmateTransactionHistory coinmateTradeHistory) {
List<UserTrade> trades = new ArrayList<UserTrade>(coinmateTradeHistory.getData().size());

for (CoinmateTransactionHistoryDataEntry entry : coinmateTradeHistory.getData()) {
for (CoinmateTransactionHistoryEntry entry : coinmateTradeHistory.getData()) {
Order.OrderType orderType;
if (entry.getTransactionType().equals("BUY")) {
orderType = Order.OrderType.BID;
Expand All @@ -148,5 +150,38 @@ public static UserTrades adaptTradeHistory(CoinmateTransactionHistory coinmateTr

return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}

public static OpenOrders adaptOpenOrders(CoinmateOpenOrders coinmateOpenOrders) throws CoinmateException {

List<LimitOrder> ordersList = new ArrayList<LimitOrder>(coinmateOpenOrders.getData().size());

for (CoinmateOpenOrdersEntry entry : coinmateOpenOrders.getData()) {

Order.OrderType orderType;
//TODO
if ("BUY".equals(entry.getType())) {
orderType = Order.OrderType.BID;
} else if ("SELL".equals(entry.getType())) {
orderType = Order.OrderType.ASK;
} else {
throw new CoinmateException("Unknown order type");
}

// the api does not provide currency for open orders, so just assume the default BTC_USD pair
CurrencyPair currencyPair = CurrencyPair.BTC_USD;

LimitOrder limitOrder = new LimitOrder(
orderType,
entry.getAmount(),
currencyPair,
Long.toString(entry.getId()),
new Date(entry.getTimestamp()),
entry.getPrice());

ordersList.add(limitOrder);
}

return new OpenOrders(ordersList);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
package com.xeiam.xchange.coinmate;

import com.xeiam.xchange.coinmate.dto.account.CoinmateBalance;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateCancelOrderResponse;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateOpenOrders;
import com.xeiam.xchange.coinmate.dto.trade.CoinmateTransactionHistory;
import java.io.IOException;
import javax.ws.rs.Consumes;
Expand All @@ -46,7 +48,8 @@ public interface CoinmateAuthenticated extends Coinmate {

@POST
@Path("balances")
public CoinmateBalance getBalances(@FormParam("clientId") String clientId, @FormParam("signature") ParamsDigest signer,
public CoinmateBalance getBalances(@FormParam("clientId") String clientId,
@FormParam("signature") ParamsDigest signer,
@FormParam("nonce") SynchronizedValueFactory<Long> nonce) throws IOException;

@POST
Expand All @@ -57,4 +60,19 @@ public CoinmateTransactionHistory getTransactionHistory(@FormParam("clientId") S
@FormParam("offset") int offset,
@FormParam("limit") int limit,
@FormParam("sort") String sort) throws IOException;

@POST
@Path("openOrders")
public CoinmateOpenOrders getOpenOrders(@FormParam("clientId") String clientId,
@FormParam("signature") ParamsDigest signer,
@FormParam("nonce") SynchronizedValueFactory<Long> nonce,
@FormParam("currencyPair") String currencyPair) throws IOException;

@POST
@Path("cancelOrder")
public CoinmateCancelOrderResponse cancelOder(@FormParam("clientId") String clientId,
@FormParam("signature") ParamsDigest signer,
@FormParam("nonce") SynchronizedValueFactory<Long> nonce,
@FormParam("orderId") String orderId ) throws IOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License
*
* Copyright 2015 Coinmate.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.xeiam.xchange.coinmate;

import com.xeiam.xchange.exceptions.ExchangeException;

/**
*
* @author Martin Stachon
*/
public class CoinmateException extends ExchangeException {

public CoinmateException(String errorMessage) {
super(errorMessage);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* The MIT License
*
* Copyright 2015 Coinmate.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.xeiam.xchange.coinmate.dto.trade;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.xeiam.xchange.coinmate.dto.CoinmateBaseResponse;

/**
*
* @author Martin Stachon
*/
public class CoinmateCancelOrderResponse extends CoinmateBaseResponse<Boolean> {

public CoinmateCancelOrderResponse(@JsonProperty("error") boolean error,
@JsonProperty("errorMessage") String errorMessage,
@JsonProperty("data") Boolean data) {

super(error, errorMessage, data);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* The MIT License
*
* Copyright 2015 Coinmate.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.xeiam.xchange.coinmate.dto.trade;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.xeiam.xchange.coinmate.dto.CoinmateBaseResponse;

/**
*
* @author Martin Stachon
*/
public class CoinmateOpenOrders extends CoinmateBaseResponse<CoinmateOpenOrdersData> {

public CoinmateOpenOrders(@JsonProperty("error") boolean error,
@JsonProperty("errorMessage") String errorMessage,
@JsonProperty("data") CoinmateOpenOrdersData data) {

super(error, errorMessage, data);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* The MIT License
*
* Copyright 2015 Coinmate.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.xeiam.xchange.coinmate.dto.trade;

import java.util.ArrayList;

/**
*
* @author Martin Stachon
*/
public class CoinmateOpenOrdersData extends ArrayList<CoinmateOpenOrdersEntry> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* The MIT License
*
* Copyright 2015 Coinmate.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.xeiam.xchange.coinmate.dto.trade;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;

/**
*
* @author Martin Stachon
*/
public class CoinmateOpenOrdersEntry {

private final long id;
private final long timestamp;
private final String type;
private final BigDecimal price;
private final BigDecimal amount;

public CoinmateOpenOrdersEntry(@JsonProperty("id") long id,
@JsonProperty("timestamp") long timestamp,
@JsonProperty("type") String type,
@JsonProperty("price") BigDecimal price,
@JsonProperty("amount") BigDecimal amount) {

this.id = id;
this.timestamp = timestamp;
this.type = type;
this.price = price;
this.amount = amount;
}

/**
* @return the id
*/
public long getId() {
return id;
}

/**
* @return the timestamp
*/
public long getTimestamp() {
return timestamp;
}

/**
* @return the type
*/
public String getType() {
return type;
}

/**
* @return the price
*/
public BigDecimal getPrice() {
return price;
}

/**
* @return the amount
*/
public BigDecimal getAmount() {
return amount;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
*
* @author Martin Stachon
*/
public class CoinmateTransactionHistoryData extends ArrayList<CoinmateTransactionHistoryDataEntry> {
public class CoinmateTransactionHistoryData extends ArrayList<CoinmateTransactionHistoryEntry> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @author Martin Stachon
*/
public class CoinmateTransactionHistoryDataEntry {
public class CoinmateTransactionHistoryEntry {

private final long transactionId;
private final long timestamp;
Expand All @@ -46,7 +46,7 @@ public class CoinmateTransactionHistoryDataEntry {
private final String status;
private final long orderId; // ?

public CoinmateTransactionHistoryDataEntry(@JsonProperty("transactionId") long transactionId,
public CoinmateTransactionHistoryEntry(@JsonProperty("transactionId") long transactionId,
@JsonProperty("timestamp") long timestamp,
@JsonProperty("transactionType") String transactionType,
@JsonProperty("amount") BigDecimal amount,
Expand Down
Loading

0 comments on commit c3344ec

Please sign in to comment.