Search in sources :

Example 1 with Order

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);
    }
}
Also used : CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) CoingiException(org.knowm.xchange.coingi.dto.CoingiException) CoingiGetOrderRequest(org.knowm.xchange.coingi.dto.trade.CoingiGetOrderRequest) ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 2 with Order

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.");
    }
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KucoinExamplesUtils(org.knowm.xchange.examples.kucoin.KucoinExamplesUtils) OrderCancelResponse(org.knowm.xchange.kucoin.dto.response.OrderCancelResponse) OrderType(org.knowm.xchange.dto.Order.OrderType) UUID(java.util.UUID) Exchange(org.knowm.xchange.Exchange) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BigDecimal(java.math.BigDecimal) Order(org.knowm.xchange.dto.Order) TradeService(org.knowm.xchange.service.trade.TradeService) Optional(java.util.Optional) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) KucoinTradeServiceRaw(org.knowm.xchange.kucoin.KucoinTradeServiceRaw) OrderCreateApiRequest(org.knowm.xchange.kucoin.dto.request.OrderCreateApiRequest) OrderCreateResponse(org.knowm.xchange.kucoin.dto.response.OrderCreateResponse) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) StopOrder(org.knowm.xchange.dto.trade.StopOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)

Example 3 with Order

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);
}
Also used : Arrays(java.util.Arrays) CoinmateWebsocketOpenOrder(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) StreamingObjectMapperHelper(info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CoinmateWebSocketUserTrade(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebSocketUserTrade) Order(org.knowm.xchange.dto.Order) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) Observable(io.reactivex.Observable) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) TypeReference(com.fasterxml.jackson.core.type.TypeReference) StreamingTradeService(info.bitrich.xchangestream.core.StreamingTradeService) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) CoinmateWebsocketOpenOrder(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders)

Example 4 with Order

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);
    }
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) BinanceNewOrder(org.knowm.xchange.binance.dto.trade.BinanceNewOrder) BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BinanceException(org.knowm.xchange.binance.dto.BinanceException) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) ArrayList(java.util.ArrayList) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams)

Example 5 with Order

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);
}
Also used : CexIOArchivedOrder(org.knowm.xchange.cexio.dto.trade.CexIOArchivedOrder) Order(org.knowm.xchange.dto.Order) CexIOFullOrder(org.knowm.xchange.cexio.dto.trade.CexIOFullOrder) CexIOOpenOrder(org.knowm.xchange.cexio.dto.trade.CexIOOpenOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CexIOOrder(org.knowm.xchange.cexio.dto.trade.CexIOOrder) OrderType(org.knowm.xchange.dto.Order.OrderType) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) InvalidFormatException(com.fasterxml.jackson.databind.exc.InvalidFormatException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

Order (org.knowm.xchange.dto.Order)102 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)84 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)53 BigDecimal (java.math.BigDecimal)51 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)38 ArrayList (java.util.ArrayList)37 Test (org.junit.Test)34 Date (java.util.Date)32 StopOrder (org.knowm.xchange.dto.trade.StopOrder)30 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)22 OrderType (org.knowm.xchange.dto.Order.OrderType)19 InputStream (java.io.InputStream)16 List (java.util.List)15 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)12 UserTrades (org.knowm.xchange.dto.trade.UserTrades)11 TradeService (org.knowm.xchange.service.trade.TradeService)11 IOException (java.io.IOException)10 Map (java.util.Map)10 CoinbaseProOrder (org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder)10