Skip to content

Commit

Permalink
Cancel Order fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
cymp committed Jul 6, 2018
1 parent 8b146a7 commit 076bd33
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
Expand Up @@ -10,6 +10,8 @@
import org.knowm.xchange.dto.trade.LimitOrder;
import org.knowm.xchange.dto.trade.OpenOrders;
import org.knowm.xchange.examples.gateio.GateioDemoUtils;
import org.knowm.xchange.gateio.Gateio;
import org.knowm.xchange.gateio.GateioUtils;
import org.knowm.xchange.gateio.dto.GateioOrderType;
import org.knowm.xchange.gateio.dto.trade.GateioOpenOrder;
import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders;
Expand All @@ -18,6 +20,7 @@
import org.knowm.xchange.gateio.service.GateioTradeServiceRaw;
import org.knowm.xchange.service.trade.TradeService;
import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair;
import org.knowm.xchange.utils.jackson.CurrencyPairDeserializer;

public class GateioTradeDemo {

Expand Down Expand Up @@ -93,7 +96,7 @@ private static void raw(GateioTradeServiceRaw tradeService)
GateioOrderStatus orderStatus = tradeService.getGateioOrderStatus(existingOrderId);
System.out.println(orderStatus);

boolean isCancelled = tradeService.cancelOrder(existingOrderId);
boolean isCancelled = tradeService.cancelOrder(existingOrderId, CurrencyPairDeserializer.getCurrencyPairFromString(openOrdersList.get(0).getCurrencyPair()));
System.out.println(isCancelled);
}

Expand Down
Expand Up @@ -54,6 +54,7 @@ GateioBaseResponse withdraw(
@Path("private/cancelorder")
GateioBaseResponse cancelOrder(
@FormParam("orderNumber") String orderNumber,
@FormParam("currencyPair") String currencyPair,
@HeaderParam("KEY") String apiKey,
@HeaderParam("SIGN") ParamsDigest signer,
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
Expand Down
Expand Up @@ -15,7 +15,6 @@
import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders;
import org.knowm.xchange.gateio.dto.trade.GateioTrade;
import org.knowm.xchange.service.trade.TradeService;
import org.knowm.xchange.service.trade.params.CancelOrderByIdParams;
import org.knowm.xchange.service.trade.params.CancelOrderParams;
import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair;
import org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair;
Expand Down Expand Up @@ -74,14 +73,15 @@ public String placeLimitOrder(LimitOrder limitOrder) throws IOException {

@Override
public boolean cancelOrder(String orderId) throws IOException {

return super.cancelOrder(orderId);
throw new NotAvailableFromExchangeException();
}

@Override
public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
if (orderParams instanceof CancelOrderByIdParams) {
return cancelOrder(((CancelOrderByIdParams) orderParams).getOrderId());
if (orderParams instanceof GateioCancelOrderParams) {
return cancelOrder(
((GateioCancelOrderParams) orderParams).getOrderId(),
((GateioCancelOrderParams) orderParams).getCurrencyPair());
} else {
return false;
}
Expand Down
Expand Up @@ -13,6 +13,8 @@
import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus;
import org.knowm.xchange.gateio.dto.trade.GateioPlaceOrderReturn;
import org.knowm.xchange.gateio.dto.trade.GateioTradeHistoryReturn;
import org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair;
import org.knowm.xchange.service.trade.params.CancelOrderByIdParams;

public class GateioTradeServiceRaw extends GateioBaseService {

Expand Down Expand Up @@ -85,10 +87,15 @@ public String placeGateioLimitOrder(
return handleResponse(orderId).getOrderId();
}

public boolean cancelOrder(String orderId) throws IOException {
public boolean cancelOrder(String orderId, CurrencyPair currencyPair) throws IOException {

GateioBaseResponse cancelOrderResult =
bter.cancelOrder(orderId, apiKey, signatureCreator, exchange.getNonceFactory());
bter.cancelOrder(
orderId,
GateioUtils.toPairString(currencyPair),
apiKey,
signatureCreator,
exchange.getNonceFactory());

return handleResponse(cancelOrderResult).isResult();
}
Expand Down Expand Up @@ -148,4 +155,25 @@ private String formatCurrencyPair(CurrencyPair currencyPair) {
"%s_%s", currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode())
.toLowerCase();
}

public static class GateioCancelOrderParams
implements CancelOrderByIdParams, CancelOrderByCurrencyPair {
public final CurrencyPair currencyPair;
public final String orderId;

public GateioCancelOrderParams(CurrencyPair currencyPair, String orderId) {
this.currencyPair = currencyPair;
this.orderId = orderId;
}

@Override
public String getOrderId() {
return orderId;
}

@Override
public CurrencyPair getCurrencyPair() {
return currencyPair;
}
}
}

0 comments on commit 076bd33

Please sign in to comment.