Search in sources :

Example 1 with CancelOrderByCurrencyPair

use of org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair in project XChange by knowm.

the class BinanceTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams params) throws IOException {
    try {
        if (!(params instanceof CancelOrderByCurrencyPair) && !(params instanceof CancelOrderByIdParams)) {
            throw new ExchangeException("You need to provide the currency pair and the order id to cancel an order.");
        }
        CancelOrderByCurrencyPair paramCurrencyPair = (CancelOrderByCurrencyPair) params;
        CancelOrderByIdParams paramId = (CancelOrderByIdParams) params;
        super.cancelOrder(paramCurrencyPair.getCurrencyPair(), BinanceAdapters.id(paramId.getOrderId()), null, null);
        return true;
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : BinanceException(org.knowm.xchange.binance.dto.BinanceException) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)

Example 2 with CancelOrderByCurrencyPair

use of org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair in project XChange by knowm.

the class OkexTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
    if (!(orderParams instanceof CancelOrderByIdParams) || !(orderParams instanceof CancelOrderByCurrencyPair)) {
        throw new UnsupportedOperationException("Cancelling an order is only available for a single market and a single id.");
    }
    String id = ((CancelOrderByIdParams) orderParams).getOrderId();
    String instrumentId = OkexAdaptersV3.toSpotInstrument(((CancelOrderByCurrencyPair) orderParams).getCurrencyPair());
    OrderCancellationRequest req = OrderCancellationRequest.builder().instrumentId(instrumentId).build();
    OrderCancellationResponse o = spotCancelOrder(id, req);
    return true;
}
Also used : OrderCancellationRequest(org.knowm.xchange.okcoin.v3.dto.trade.OrderCancellationRequest) OrderCancellationResponse(org.knowm.xchange.okcoin.v3.dto.trade.OrderCancellationResponse) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)

Example 3 with CancelOrderByCurrencyPair

use of org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair in project XChange by knowm.

the class BithumbTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
    try {
        if (!(orderParams instanceof CancelOrderByIdParams && orderParams instanceof CancelOrderByCurrencyPair)) {
            throw new NotYetImplementedForExchangeException("Only CancelOrderByPairAndIdParams || (CancelOrderByIdParams && CancelOrderByCurrencyPair) supported");
        }
        String orderId = ((CancelOrderByIdParams) orderParams).getOrderId();
        CurrencyPair pair = ((CancelOrderByCurrencyPair) orderParams).getCurrencyPair();
        return cancelBithumbOrder(orderId, pair);
    } catch (BithumbException e) {
        throw BithumbErrorAdapter.adapt(e);
    }
}
Also used : BithumbException(org.knowm.xchange.bithumb.BithumbException) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 4 with CancelOrderByCurrencyPair

use of org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair in project XChange by knowm.

the class TradeServiceIntegration method changeOrder.

@Test
public void changeOrder() throws IOException {
    BigDecimal modifyPrice = new BigDecimal(302);
    BigDecimal endPrice = new BigDecimal(304);
    String orderId = tradeService.placeLimitOrder(order);
    LimitOrder order2 = new LimitOrder(order.getType(), order.getOriginalAmount(), order.getCurrencyPair(), orderId, order.getTimestamp(), modifyPrice);
    String orderId2 = tradeService.changeOrder(order2);
    LimitOrder order3 = new LimitOrder(order.getType(), order.getOriginalAmount(), order.getCurrencyPair(), orderId2, order.getTimestamp(), endPrice);
    String orderId3 = tradeService.changeOrder(order3);
    List<Order> orders = (List<Order>) tradeService.getOrder(orderId, orderId2, orderId3);
    Assert.assertEquals("Order response must contain 1 order", 3, orders.size());
    Assert.assertSame("Order 1 must be canceled", orders.get(0).getStatus(), Order.OrderStatus.CANCELED);
    Assert.assertSame("Order 2 must be canceled", orders.get(1).getStatus(), Order.OrderStatus.CANCELED);
    Assert.assertSame("Order 3 must be placed", orders.get(2).getStatus(), Order.OrderStatus.PENDING_NEW);
    Assert.assertEquals("Order 3 must have `endPrice` price", 0, ((LimitOrder) orders.get(2)).getLimitPrice().compareTo(endPrice));
    tradeService.cancelOrder((CancelOrderByCurrencyPair) () -> new CurrencyPair("BCH/USD"));
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) List(java.util.List) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 5 with CancelOrderByCurrencyPair

use of org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair in project XChange by knowm.

the class CoinsuperTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
    if (!(orderParams instanceof CancelOrderByCurrencyPair) && !(orderParams instanceof CancelOrderByIdParams)) {
        throw new ExchangeException("You need to provide the currency pair and the order id to cancel an order.");
    }
    // CancelOrderByCurrencyPair currencyPair = (CancelOrderByCurrencyPair) orderParams;
    CancelOrderByIdParams orderIdParam = (CancelOrderByIdParams) orderParams;
    // String orderId =
    // super.cancelOrder(
    // CoinsuperAdapters.toMarket(currencyPair.getCurrencyPair()),
    // orderIdParam.getOrderId());
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("orderNo", orderIdParam.getOrderId());
    return cancelCoinsuperOrder(parameters);
}
Also used : HashMap(java.util.HashMap) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)

Aggregations

CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)9 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)8 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)5 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)4 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)4 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)3 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)2 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (org.junit.Test)1 BinanceException (org.knowm.xchange.binance.dto.BinanceException)1 BithumbException (org.knowm.xchange.bithumb.BithumbException)1 OrderReference (org.knowm.xchange.dragonex.dto.trade.OrderReference)1 UserOrder (org.knowm.xchange.dragonex.dto.trade.UserOrder)1 Order (org.knowm.xchange.dto.Order)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)1 LivecoinException (org.knowm.xchange.livecoin.dto.LivecoinException)1