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);
}
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);
}
}
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);
}
}
Aggregations