use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class CoingiTradeService method getOrder.
@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
try {
Collection<Order> orders = new ArrayList<>();
for (String orderId : orderIds) {
CoingiGetOrderRequest request = new CoingiGetOrderRequest().setOrderId(orderId);
CoingiOrder coingiOrder;
coingiOrder = getCoingiOrder(request);
CurrencyPair currencyPair = CoingiAdapters.adaptCurrency(coingiOrder.getCurrencyPair());
Date date = new Date(coingiOrder.getTimestamp() * 1000);
Order order = new LimitOrder(coingiOrder.getType() == 0 ? Order.OrderType.BID : Order.OrderType.ASK, coingiOrder.getOriginalBaseAmount(), currencyPair, coingiOrder.getId(), date, coingiOrder.getPrice());
order.setOrderStatus(CoingiAdapters.adaptOrderStatus(coingiOrder.getStatus()));
orders.add(order);
}
return orders;
} catch (CoingiException e) {
throw CoingiErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.dto.Order 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.Order in project XChange by knowm.
the class CoinmateStreamingTradeService method getOrderChanges.
@Override
public Observable<Order> getOrderChanges(CurrencyPair currencyPair, Object... args) {
String channelName = "private-open_orders-" + coinmateStreamingService.getUserId() + "-" + CoinmateStreamingAdapter.getChannelPostfix(currencyPair);
ObjectReader reader = StreamingObjectMapperHelper.getObjectMapper().readerFor(CoinmateWebsocketOpenOrder.class);
return coinmateStreamingService.subscribeChannel(channelName, true).map((message) -> {
JsonNode payload = message.get("payload");
List<CoinmateWebsocketOpenOrder> websocketOpenOrders;
if (payload.isArray()) {
websocketOpenOrders = Arrays.asList(reader.readValue(payload, CoinmateWebsocketOpenOrder[].class));
} else {
websocketOpenOrders = Collections.singletonList(reader.readValue(payload, CoinmateWebsocketOpenOrder.class));
}
return CoinmateStreamingAdapter.adaptWebsocketOpenOrders(websocketOpenOrders, currencyPair);
}).concatMapIterable(OpenOrders::getAllOpenOrders);
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class BinanceTradeService method getOrder.
@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
try {
Collection<Order> orders = new ArrayList<>();
for (OrderQueryParams param : params) {
if (!(param instanceof OrderQueryParamCurrencyPair)) {
throw new ExchangeException("Parameters must be an instance of OrderQueryParamCurrencyPair");
}
OrderQueryParamCurrencyPair orderQueryParamCurrencyPair = (OrderQueryParamCurrencyPair) param;
if (orderQueryParamCurrencyPair.getCurrencyPair() == null || orderQueryParamCurrencyPair.getOrderId() == null) {
throw new ExchangeException("You need to provide the currency pair and the order id to query an order.");
}
orders.add(BinanceAdapters.adaptOrder(super.orderStatus(orderQueryParamCurrencyPair.getCurrencyPair(), BinanceAdapters.id(orderQueryParamCurrencyPair.getOrderId()), null)));
}
return orders;
} catch (BinanceException e) {
throw BinanceErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class CexIOAdapters method adaptOrder.
public static Order adaptOrder(CexIOOpenOrder cexIOOrder) {
OrderType orderType = cexIOOrder.type.equals("sell") ? OrderType.ASK : OrderType.BID;
BigDecimal originalAmount = new BigDecimal(cexIOOrder.amount);
CurrencyPair currencyPair = new CurrencyPair(cexIOOrder.symbol1, cexIOOrder.symbol2);
Date timestamp = new Date(cexIOOrder.time);
BigDecimal limitPrice = new BigDecimal(cexIOOrder.price);
Order.OrderStatus status = adaptOrderStatus(cexIOOrder);
BigDecimal cumulativeAmount = null;
try {
BigDecimal remains = new BigDecimal(cexIOOrder.remains);
cumulativeAmount = originalAmount.subtract(remains);
} catch (Exception e) {
}
return new LimitOrder(orderType, originalAmount, currencyPair, cexIOOrder.orderId, timestamp, limitPrice, null, cumulativeAmount, null, status);
}
Aggregations