Search in sources :

Example 6 with Order

use of org.knowm.xchange.dto.Order in project XChange by knowm.

the class OkexTradeService method getOrder.

public Order getOrder(OrderQueryParams orderQueryParams) throws IOException {
    Order result = null;
    if (orderQueryParams instanceof OrderQueryParamInstrument) {
        Instrument instrument = ((OrderQueryParamInstrument) orderQueryParams).getInstrument();
        String orderId = orderQueryParams.getOrderId();
        List<OkexOrderDetails> orderResults = getOkexOrder(OkexAdapters.adaptInstrumentId(instrument), orderId).getData();
        if (!orderResults.isEmpty()) {
            result = OkexAdapters.adaptOrder(orderResults.get(0));
        }
    } else {
        throw new IOException("OrderQueryParams must implement OrderQueryParamInstrument interface.");
    }
    return result;
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OkexOrderDetails(org.knowm.xchange.okex.v5.dto.trade.OkexOrderDetails) OpenOrdersParamInstrument(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamInstrument) CancelOrderByInstrument(org.knowm.xchange.service.trade.params.CancelOrderByInstrument) TradeHistoryParamInstrument(org.knowm.xchange.service.trade.params.TradeHistoryParamInstrument) OrderQueryParamInstrument(org.knowm.xchange.service.trade.params.orders.OrderQueryParamInstrument) Instrument(org.knowm.xchange.instrument.Instrument) IOException(java.io.IOException) OrderQueryParamInstrument(org.knowm.xchange.service.trade.params.orders.OrderQueryParamInstrument)

Example 7 with Order

use of org.knowm.xchange.dto.Order in project XChange by knowm.

the class BankeraTradeService method getOrder.

@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
    List<Order> orders = new ArrayList<>();
    for (String orderId : orderIds) {
        BankeraOrder order = getUserOrder(orderId);
        orders.add(BankeraAdapters.adaptOrder(order));
    }
    return orders;
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BankeraOrder(org.knowm.xchange.bankera.dto.trade.BankeraOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) ArrayList(java.util.ArrayList) BankeraOrder(org.knowm.xchange.bankera.dto.trade.BankeraOrder)

Example 8 with Order

use of org.knowm.xchange.dto.Order in project XChange by knowm.

the class TradeServiceIntegrationTransactionsCreateOrder method getOrder.

// getOrder(String... orderIds)
// trades
private static void getOrder() throws IOException {
    String apiKey = "00af0b38-11fb-4aab-bf19-45edd44a4adc";
    String secretKey = "fa3f0510-155f-4567-a3b3-3f386080efa3";
    Exchange coinsuper = ExchangeFactory.INSTANCE.createExchange(CoinsuperExchange.class);
    ExchangeSpecification exchangeSpecification = coinsuper.getExchangeSpecification();
    exchangeSpecification.setApiKey(apiKey);
    exchangeSpecification.setSecretKey(secretKey);
    coinsuper.applySpecification(exchangeSpecification);
    TradeService tradeService = coinsuper.getTradeService();
    try {
        String orderNoList = "1608661340536594433,1608661662038384641";
        Collection<Order> openOrders = tradeService.getOrder(orderNoList);
        System.out.printf("Open Orders for %s: %s%n", orderNoList, openOrders);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : CoinsuperExchange(org.knowm.xchange.coinsuper.CoinsuperExchange) Exchange(org.knowm.xchange.Exchange) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) TradeService(org.knowm.xchange.service.trade.TradeService) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) IOException(java.io.IOException)

Example 9 with Order

use of org.knowm.xchange.dto.Order in project XChange by knowm.

the class ExmoTradeServiceRaw method openOrders.

public List<LimitOrder> openOrders() {
    Map<String, List<Map<String, String>>> map = exmo.userOpenOrders(signatureCreator, apiKey, exchange.getNonceFactory());
    List<LimitOrder> openOrders = new ArrayList<>();
    for (String market : map.keySet()) {
        CurrencyPair currencyPair = adaptMarket(market);
        for (Map<String, String> order : map.get(market)) {
            Order.OrderType type = ExmoAdapters.adaptOrderType(order);
            BigDecimal amount = new BigDecimal(order.get("quantity"));
            String id = order.get("order_id");
            BigDecimal price = new BigDecimal(order.get("price"));
            Date created = DateUtils.fromUnixTime(Long.valueOf(order.get("created")));
            openOrders.add(new LimitOrder(type, amount, currencyPair, id, created, price));
        }
    }
    return openOrders;
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 10 with Order

use of org.knowm.xchange.dto.Order in project XChange by knowm.

the class OkCoinTradeService method cancelUpToThreeOrders.

/**
 * Cancel a batch of up to three orders (maximum allowed by the exchange).
 *
 * @param limitOrders orders to cancel
 * @return (id, result) mappings
 */
public Map<LimitOrder, Boolean> cancelUpToThreeOrders(List<LimitOrder> limitOrders) throws IOException {
    Set<Long> ordersToCancel = limitOrders.stream().map(Order::getId).map(Long::parseLong).collect(Collectors.toSet());
    if (ordersToCancel.isEmpty() || ordersToCancel.size() > 3) {
        throw new UnsupportedOperationException("Can only batch cancel 1 to 3 orders. " + ordersToCancel.size() + " orders provided.");
    }
    CurrencyPair currencyPair = limitOrders.get(0).getCurrencyPair();
    boolean valid = limitOrders.stream().allMatch(order -> order.getCurrencyPair().equals(currencyPair));
    if (!valid) {
        throw new UnsupportedOperationException("Can only batch cancel orders with the same currency pair.");
    }
    OkCoinBatchTradeResult okCoinBatchTradeResult = cancelUpToThreeOrders(ordersToCancel, OkCoinAdapters.adaptSymbol(currencyPair));
    Map<String, Boolean> requestResults = new HashMap<>(ordersToCancel.size());
    if (okCoinBatchTradeResult.getSuccess() != null) {
        Arrays.stream(okCoinBatchTradeResult.getSuccess().split(BATCH_DELIMITER)).forEach(id -> requestResults.put(id, Boolean.TRUE));
    }
    if (okCoinBatchTradeResult.getError() != null) {
        Arrays.stream(okCoinBatchTradeResult.getError().split(BATCH_DELIMITER)).forEach(id -> requestResults.put(id, Boolean.FALSE));
    }
    Map<LimitOrder, Boolean> results = new HashMap<>(limitOrders.size());
    requestResults.forEach((id, result) -> limitOrders.stream().filter(order -> order.getId().equals(id)).findAny().ifPresent(limitOrder -> results.put(limitOrder, requestResults.get(id))));
    return results;
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) StopOrder(org.knowm.xchange.dto.trade.StopOrder) Arrays(java.util.Arrays) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) OrderType(org.knowm.xchange.dto.Order.OrderType) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) HashMap(java.util.HashMap) Exchange(org.knowm.xchange.Exchange) ArrayList(java.util.ArrayList) Order(org.knowm.xchange.dto.Order) Map(java.util.Map) OkCoinTradeResult(org.knowm.xchange.okcoin.dto.trade.OkCoinTradeResult) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) Set(java.util.Set) IOException(java.io.IOException) UserTrades(org.knowm.xchange.dto.trade.UserTrades) DefaultTradeHistoryParamPaging(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPaging) Collectors(java.util.stream.Collectors) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) List(java.util.List) OkCoinAdapters(org.knowm.xchange.okcoin.OkCoinAdapters) TradeService(org.knowm.xchange.service.trade.TradeService) OkCoinOrderResult(org.knowm.xchange.okcoin.dto.trade.OkCoinOrderResult) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) OkCoinMoreTradeResult(org.knowm.xchange.okcoin.dto.trade.result.OkCoinMoreTradeResult) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) OkCoinBatchTradeResult(org.knowm.xchange.okcoin.dto.trade.result.OkCoinBatchTradeResult) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) HashMap(java.util.HashMap) OkCoinBatchTradeResult(org.knowm.xchange.okcoin.dto.trade.result.OkCoinBatchTradeResult) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

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