Search in sources :

Example 96 with Order

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

the class GeminiAdaptersTest method testAdaptLimitOrderUntouched.

@Test
public void testAdaptLimitOrderUntouched() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/limit-order-untouched.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    GeminiOrderStatusResponse geminiOrderStatusResponse = mapper.readValue(is, GeminiOrderStatusResponse.class);
    Order order = GeminiAdapters.adaptOrder(geminiOrderStatusResponse);
    assertThat(order.getId()).isEqualTo("44375901");
    assertThat(order.getAveragePrice()).isEqualTo(new BigDecimal("0.00"));
    assertThat(order.getCumulativeAmount()).isEqualTo(new BigDecimal("0"));
    assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
    assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.OPEN);
    assertThat(LimitOrder.class.isAssignableFrom(order.getClass()));
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) InputStream(java.io.InputStream) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 97 with Order

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

the class IndependentReserveTradeService method getOrder.

@Override
public Collection<Order> getOrder(OrderQueryParams... orderQueryParams) throws IOException {
    List<Order> res = new ArrayList<>();
    for (OrderQueryParams orderQueryParam : Arrays.asList(orderQueryParams)) {
        IndependentReserveOrderDetailsResponse orderDetailsResponse = getOrderDetails(orderQueryParam.getOrderId());
        res.add(IndependentReserveAdapters.adaptOrderDetails(orderDetailsResponse));
    }
    return res;
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) IndependentReserveOrderDetailsResponse(org.knowm.xchange.independentreserve.dto.trade.IndependentReserveOrderDetailsResponse) ArrayList(java.util.ArrayList) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams)

Example 98 with Order

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

the class LatokenTradeService method getOrder.

@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
    try {
        Collection<Order> orders = new ArrayList<>();
        // pair/status (via LatokenQueryOrderParams)
        for (OrderQueryParams param : params) {
            if (param instanceof OrderQueryParamCurrencyPair) {
                OrderQueryParamCurrencyPair orderQueryParamCurrencyPair = (OrderQueryParamCurrencyPair) param;
                CurrencyPair pair = orderQueryParamCurrencyPair.getCurrencyPair();
                if (pair == null) {
                    throw new ExchangeException("CurrencyPair must be provided to query an order.");
                }
                LatokenOrderStatus status = LatokenOrderStatus.active;
                Integer limit = null;
                if (param instanceof LatokenQueryOrderParams) {
                    LatokenQueryOrderParams latokenParam = (LatokenQueryOrderParams) param;
                    status = latokenParam.getStatus();
                    limit = latokenParam.getLimit();
                }
                List<LatokenOrder> latokenOrders = getLatokenOrders(pair, status, limit);
                latokenOrders.forEach(latokenOrder -> orders.add(LatokenAdapters.adaptOrder(this.exchange, latokenOrder)));
            } else {
                if (param.getOrderId() == null) {
                    throw new ExchangeException("OrderId must be provided to query an order.");
                }
                LatokenOrder latokenOrder = getLatokenOrder(param.getOrderId());
                orders.add(LatokenAdapters.adaptOrder(this.exchange, latokenOrder));
            }
        }
        return orders;
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenNewOrder(org.knowm.xchange.latoken.dto.trade.LatokenNewOrder) Order(org.knowm.xchange.dto.Order) LatokenTestOrder(org.knowm.xchange.latoken.dto.trade.LatokenTestOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) LatokenException(org.knowm.xchange.latoken.dto.LatokenException) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) ArrayList(java.util.ArrayList) LatokenOrderStatus(org.knowm.xchange.latoken.dto.trade.LatokenOrderStatus) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 99 with Order

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

the class PaymiumTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    Long offset = null;
    Integer limit = null;
    if (params instanceof TradeHistoryParamOffset) {
        final TradeHistoryParamOffset historyParamOffset = (TradeHistoryParamOffset) params;
        offset = historyParamOffset.getOffset();
    }
    if (params instanceof TradeHistoryParamLimit) {
        final TradeHistoryParamLimit historyParamLimit = (TradeHistoryParamLimit) params;
        limit = historyParamLimit.getLimit();
    }
    List<UserTrade> userTrades = new ArrayList();
    List<PaymiumOrder> orders = getPaymiumOrders(offset, limit);
    for (PaymiumOrder order : orders) {
        Order.OrderType orderType = null;
        Currency currencyFee = null;
        BigDecimal fee = null;
        switch(order.getDirection()) {
            case "buy":
                orderType = Order.OrderType.ASK;
                currencyFee = Currency.BTC;
                fee = order.getBtcFee();
                break;
            case "sell":
                orderType = Order.OrderType.BID;
                currencyFee = Currency.EUR;
                fee = order.getCurrencyFee();
                break;
        }
        UserTrade userTrade = new UserTrade.Builder().type(orderType).originalAmount(order.getTradedCurrency()).currencyPair(CurrencyPair.BTC_EUR).price(order.getPrice()).id(order.getUuid()).orderId(order.getUuid()).feeAmount(fee).feeCurrency(currencyFee).build();
        userTrades.add(userTrade);
    }
    return new UserTrades(userTrades, Trades.TradeSortType.SortByTimestamp);
}
Also used : Order(org.knowm.xchange.dto.Order) PaymiumOrder(org.knowm.xchange.paymium.dto.account.PaymiumOrder) TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Currency(org.knowm.xchange.currency.Currency) PaymiumOrder(org.knowm.xchange.paymium.dto.account.PaymiumOrder) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)

Example 100 with Order

use of org.knowm.xchange.dto.Order 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);
    }
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) OkexTradeService(org.knowm.xchange.okex.v5.service.OkexTradeService) ArrayList(java.util.ArrayList) DefaultQueryOrderParamInstrument(org.knowm.xchange.service.trade.params.orders.DefaultQueryOrderParamInstrument) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Exchange(org.knowm.xchange.Exchange) OkexTradeParams(org.knowm.xchange.okex.v5.dto.trade.OkexTradeParams) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Test(org.junit.Test)

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