use of org.knowm.xchange.dto.trade.StopOrder in project XChange by knowm.
the class KucoinTradeRawDemo method genericStopLimitOrder.
private static void genericStopLimitOrder(TradeService tradeService) throws Exception {
System.out.println("GENERIC STOP LIMIT ORDER...\n");
StopOrder stopOrder = new StopOrder.Builder(ORDER_TYPE, PAIR).limitPrice(STOP_LIMIT).stopPrice(STOP_PRICE).originalAmount(AMOUNT).build();
String uuid = tradeService.placeStopOrder(stopOrder);
System.out.println("Stop order successfully placed. ID=" + uuid);
// wait for order to propagate
Thread.sleep(3000);
OpenOrdersParamCurrencyPair orderParams = (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
orderParams.setCurrencyPair(PAIR);
OpenOrders openOrders = tradeService.getOpenOrders(orderParams);
Optional<? extends Order> found = openOrders.getHiddenOrders().stream().filter(o -> o.getId().equals(uuid)).findFirst();
if (!found.isPresent()) {
throw new AssertionError("Order not found on book");
}
if (!(found.get() instanceof StopOrder)) {
throw new AssertionError("Stop order not returned");
}
StopOrder returnedStopOrder = (StopOrder) found.get();
if (returnedStopOrder.getLimitPrice().compareTo(STOP_LIMIT) != 0) {
throw new AssertionError("Limit price mismatch: " + returnedStopOrder.getLimitPrice());
}
if (returnedStopOrder.getStopPrice().compareTo(STOP_PRICE) != 0) {
throw new AssertionError("Stop price mismatch: " + returnedStopOrder.getStopPrice());
}
System.out.println("Attempting to cancel order " + uuid);
boolean cancelled = tradeService.cancelOrder(uuid);
if (cancelled) {
System.out.println("Order successfully canceled.");
} else {
System.out.println("Order not successfully canceled.");
}
}
use of org.knowm.xchange.dto.trade.StopOrder in project XChange by knowm.
the class TradeServiceIntegration method testPlaceTestOrderTakeProfitLimitOrderShouldNotThrowAnyException.
@Test
public void testPlaceTestOrderTakeProfitLimitOrderShouldNotThrowAnyException() throws IOException {
final StopOrder takeProfitLimitOrder = sampleTakeProfitLimitOrder();
tradeService.placeTestOrder(TAKE_PROFIT_LIMIT, takeProfitLimitOrder, takeProfitLimitOrder.getLimitPrice(), takeProfitLimitOrder.getStopPrice());
}
use of org.knowm.xchange.dto.trade.StopOrder in project XChange by knowm.
the class TradeServiceIntegration method testPlaceTestOrderStopLossLimitOrderShouldNotThrowAnyException.
@Test
public void testPlaceTestOrderStopLossLimitOrderShouldNotThrowAnyException() throws IOException {
final StopOrder stopLimitOrder = sampleStopLimitOrder();
tradeService.placeTestOrder(STOP_LOSS_LIMIT, stopLimitOrder, stopLimitOrder.getLimitPrice(), stopLimitOrder.getStopPrice());
}
use of org.knowm.xchange.dto.trade.StopOrder in project XChange by knowm.
the class CoinbaseProAdaptersTest method testOrderStatusStopOrderNew.
@Test
public void testOrderStatusStopOrderNew() throws JsonParseException, JsonMappingException, IOException {
final JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
final ObjectMapper mapper = factory.createObjectMapper();
final InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/order/example-stop-order-new.json");
final CoinbaseProOrder coinbaseProOrder = mapper.readValue(is, CoinbaseProOrder.class);
final Order order = CoinbaseProAdapters.adaptOrder(coinbaseProOrder);
assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.NEW);
assertThat(order.getId()).isEqualTo("853a9989-7dd9-40f8-9392-64237a9eccc4");
assertThat(order.getCurrencyPair()).isEqualTo((CurrencyPair.BTC_EUR));
assertThat(order.getOriginalAmount()).isEqualByComparingTo(new BigDecimal("0.01"));
assertThat(order.getCumulativeAmount()).isEqualByComparingTo(BigDecimal.ZERO);
assertThat(order.getRemainingAmount()).isEqualByComparingTo(new BigDecimal("0.01"));
assertThat(order.getType()).isEqualTo(OrderType.ASK);
assertThat(order.getTimestamp()).isEqualTo(new Date(1515434144454L));
assertThat(order.getAveragePrice()).isEqualByComparingTo(BigDecimal.ZERO);
assertThat(StopOrder.class.isAssignableFrom(order.getClass())).isTrue();
StopOrder stop = (StopOrder) order;
assertThat(stop.getStopPrice()).isEqualByComparingTo("6364.31");
}
use of org.knowm.xchange.dto.trade.StopOrder in project XChange by knowm.
the class CoinbaseProAdaptersTest method assertStopOrderFilled.
private void assertStopOrderFilled(final Order order) {
assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.FILLED);
assertThat(order.getId()).isEqualTo("a9098e25-9d4d-4e2c-ab5e-8c057cc4cbee");
assertThat(order.getCurrencyPair()).isEqualTo((CurrencyPair.BTC_EUR));
assertThat(order.getOriginalAmount()).isEqualByComparingTo(new BigDecimal("0.08871972"));
assertThat(order.getCumulativeAmount()).isEqualByComparingTo(new BigDecimal("0.08871972"));
assertThat(order.getRemainingAmount()).isEqualByComparingTo(BigDecimal.ZERO);
assertThat(order.getType()).isEqualTo(OrderType.BID);
assertThat(order.getTimestamp()).isEqualTo(new Date(1515434144454L));
assertThat(order.getAveragePrice()).isEqualByComparingTo(new BigDecimal("639.3107535312").divide(new BigDecimal("0.08871972"), new MathContext(8)));
assertThat(StopOrder.class.isAssignableFrom(order.getClass())).isTrue();
StopOrder stop = (StopOrder) order;
assertThat(stop.getStopPrice()).isEqualByComparingTo("7205");
}
Aggregations