Search in sources :

Example 1 with CancelOrderParams

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

the class EXXTradeService method cancelOrder.

@Override
public boolean cancelOrder(CancelOrderParams cancelOrderParams) throws IOException {
    if (!(cancelOrderParams instanceof CancelOrderParams) && !(cancelOrderParams instanceof EXXCancelOrderByCurrencyPair)) {
        throw new ExchangeException("You need to provide the currency pair and the order id to cancel an order.");
    }
    EXXCancelOrderByCurrencyPair params = (EXXCancelOrderByCurrencyPair) cancelOrderParams;
    CurrencyPair currencyPair = params.getCurrencyPair();
    // etp_btc
    String currency = currencyPairFormat(currencyPair);
    return cancelExxOrder(params.getId(), currency);
}
Also used : CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) EXXCancelOrderByCurrencyPair(org.knowm.xchange.exx.dto.params.EXXCancelOrderByCurrencyPair) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) EXXCancelOrderByCurrencyPair(org.knowm.xchange.exx.dto.params.EXXCancelOrderByCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with CancelOrderParams

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

the class BinanceTradeDemo method generic.

public static void generic(Exchange exchange) throws IOException {
    CurrencyPair pair = CurrencyPair.EOS_ETH;
    TradeService tradeService = exchange.getTradeService();
    // Get open orders
    OpenOrders orders = tradeService.getOpenOrders(new DefaultOpenOrdersParamCurrencyPair(pair));
    LimitOrder order = orders.getOpenOrders().stream().collect(StreamUtils.singletonCollector());
    if (order != null) {
        System.out.println(order);
    }
    // Cancel order
    if (order != null) {
        List<Class> classList = Arrays.asList(exchange.getTradeService().getRequiredCancelOrderParamClasses());
        CancelOrderParams cancelParam = new DefaultCancelOrderParamId(order.getId());
        if (classList.contains(CancelOrderByCurrencyPair.class) && classList.contains(CancelOrderByIdParams.class)) {
            cancelParam = new DefaultCancelOrderByCurrencyPairAndIdParams(pair, order.getId());
        }
        exchange.getTradeService().cancelOrder(cancelParam);
    }
}
Also used : CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) BinanceTradeService(org.knowm.xchange.binance.service.BinanceTradeService) TradeService(org.knowm.xchange.service.trade.TradeService) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) DefaultCancelOrderByCurrencyPairAndIdParams(org.knowm.xchange.service.trade.params.DefaultCancelOrderByCurrencyPairAndIdParams) DefaultCancelOrderParamId(org.knowm.xchange.service.trade.params.DefaultCancelOrderParamId) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)

Example 3 with CancelOrderParams

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

the class OkexExchangeIntegration method testOrderActions.

@Test
public void testOrderActions() throws Exception {
    if (!API_KEY.isEmpty() && !SECRET_KEY.isEmpty() && !PASSPHRASE.isEmpty()) {
        ExchangeSpecification spec = ExchangeFactory.INSTANCE.createExchange(OkexExchange.class).getDefaultExchangeSpecification();
        spec.setApiKey(API_KEY);
        spec.setSecretKey(SECRET_KEY);
        spec.setExchangeSpecificParametersItem("passphrase", PASSPHRASE);
        final Exchange exchange = ExchangeFactory.INSTANCE.createExchange(spec);
        final OkexTradeService okexTradeService = (OkexTradeService) exchange.getTradeService();
        assertThat(exchange.getExchangeSpecification().getSslUri()).isEqualTo("https://www.okex.com");
        assertThat(exchange.getExchangeSpecification().getHost()).isEqualTo("okex.com");
        // Place a single order
        LimitOrder limitOrder = new LimitOrder(Order.OrderType.ASK, BigDecimal.TEN, TRX_USDT, null, new Date(), new BigDecimal(100));
        String orderId = okexTradeService.placeLimitOrder(limitOrder);
        log.info("Placed orderId: {}", orderId);
        // Amend the above order
        LimitOrder limitOrder2 = new LimitOrder(Order.OrderType.ASK, BigDecimal.TEN, TRX_USDT, orderId, new Date(), new BigDecimal(1000));
        String orderId2 = okexTradeService.changeOrder(limitOrder2);
        log.info("Amended orderId: {}", orderId2);
        // Get non-existent Order Detail
        Order failOrder = okexTradeService.getOrder(new DefaultQueryOrderParamInstrument(TRX_USDT, "2132465465"));
        log.info("Null Order: {}", failOrder);
        // Get Order Detail
        Order amendedOrder = okexTradeService.getOrder(new DefaultQueryOrderParamInstrument(TRX_USDT, orderId2));
        log.info("Amended Order: {}", amendedOrder);
        // Cancel that order
        boolean result = exchange.getTradeService().cancelOrder(new OkexTradeParams.OkexCancelOrderParams(TRX_USDT, orderId2));
        log.info("Cancellation result: {}", result);
        // Place batch orders
        List<String> orderIds = okexTradeService.placeLimitOrder(Arrays.asList(limitOrder, limitOrder, limitOrder));
        log.info("Placed batch orderIds: {}", orderIds);
        // Amend batch orders
        List<LimitOrder> amendOrders = new ArrayList<>();
        for (String id : orderIds) {
            amendOrders.add(new LimitOrder(Order.OrderType.ASK, BigDecimal.TEN, TRX_USDT, id, new Date(), new BigDecimal(1000)));
        }
        List<String> amendedOrderIds = okexTradeService.changeOrder(amendOrders);
        log.info("Amended batch orderIds: {}", amendedOrderIds);
        OpenOrders openOrders = okexTradeService.getOpenOrders();
        log.info("Open Orders: {}", openOrders);
        // Cancel batch orders
        List<CancelOrderParams> cancelOrderParams = new ArrayList<>();
        for (String id : orderIds) {
            cancelOrderParams.add(new OkexTradeParams.OkexCancelOrderParams(TRX_USDT, id));
        }
        List<Boolean> results = okexTradeService.cancelOrder(cancelOrderParams);
        log.info("Cancelled order results: {}", results);
    }
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) OkexTradeService(org.knowm.xchange.okex.v5.service.OkexTradeService) ArrayList(java.util.ArrayList) DefaultQueryOrderParamInstrument(org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Exchange(org.knowm.xchange.Exchange) OkexTradeParams(org.knowm.xchange.okex.v5.dto.trade.OkexTradeParams) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Test(org.junit.Test)

Aggregations

CancelOrderParams (org.knowm.xchange.service.trade.params.CancelOrderParams)3 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 Exchange (org.knowm.xchange.Exchange)1 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)1 BinanceTradeService (org.knowm.xchange.binance.service.BinanceTradeService)1 Order (org.knowm.xchange.dto.Order)1 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)1 EXXCancelOrderByCurrencyPair (org.knowm.xchange.exx.dto.params.EXXCancelOrderByCurrencyPair)1 OkexTradeParams (org.knowm.xchange.okex.v5.dto.trade.OkexTradeParams)1 OkexTradeService (org.knowm.xchange.okex.v5.service.OkexTradeService)1 TradeService (org.knowm.xchange.service.trade.TradeService)1 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)1 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)1 DefaultCancelOrderByCurrencyPairAndIdParams (org.knowm.xchange.service.trade.params.DefaultCancelOrderByCurrencyPairAndIdParams)1