Search in sources :

Example 96 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class GateioAdapterTest method testAdaptOpenOrders.

@Test
public void testAdaptOpenOrders() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = GateioAdapterTest.class.getResourceAsStream("/org/knowm/xchange/gateio/dto/trade/example-order-list-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    GateioOpenOrders openOrders = mapper.readValue(is, GateioOpenOrders.class);
    OpenOrders adaptedOpenOrders = GateioAdapters.adaptOpenOrders(openOrders, currencyPairs);
    List<LimitOrder> adaptedOrderList = adaptedOpenOrders.getOpenOrders();
    assertThat(adaptedOrderList).hasSize(2);
    LimitOrder adaptedOrder = adaptedOrderList.get(0);
    assertThat(adaptedOrder.getType()).isEqualTo(OrderType.ASK);
    assertThat(adaptedOrder.getOriginalAmount()).isEqualTo(new BigDecimal("100000"));
    assertThat(adaptedOrder.getCurrencyPair()).isEqualTo(CurrencyPair.ETH_BTC);
    assertThat(adaptedOrder.getId()).isEqualTo("0");
    assertThat(adaptedOrder.getLimitPrice()).isEqualTo(new BigDecimal("0.0693"));
}
Also used : GateioOpenOrders(org.knowm.xchange.gateio.dto.trade.GateioOpenOrders) InputStream(java.io.InputStream) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) GateioOpenOrders(org.knowm.xchange.gateio.dto.trade.GateioOpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 97 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class GateioAdapterTest method testAdaptOrderBook.

@Test
public void testAdaptOrderBook() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = GateioAdapterTest.class.getResourceAsStream("/org/knowm/xchange/gateio/dto/marketdata/example-depth-data.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    GateioDepth depth = mapper.readValue(is, GateioDepth.class);
    OrderBook orderBook = GateioAdapters.adaptOrderBook(depth, CurrencyPair.LTC_BTC);
    List<LimitOrder> asks = orderBook.getAsks();
    assertThat(asks).hasSize(3);
    LimitOrder ask = asks.get(0);
    assertThat(ask.getLimitPrice()).isEqualTo("0.1785");
    assertThat(ask.getOriginalAmount()).isEqualTo("1324.111");
    assertThat(ask.getType()).isEqualTo(OrderType.ASK);
    assertThat(ask.getTimestamp()).isNull();
    assertThat(ask.getCurrencyPair()).isEqualTo(CurrencyPair.LTC_BTC);
}
Also used : GateioDepth(org.knowm.xchange.gateio.dto.marketdata.GateioDepth) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) InputStream(java.io.InputStream) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 98 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class GeminiAdapters method adaptOrders.

public static OpenOrders adaptOrders(GeminiOrderStatusResponse[] activeOrders, CurrencyPair currencyPair) {
    List<LimitOrder> limitOrders = new ArrayList<>(activeOrders.length);
    for (GeminiOrderStatusResponse order : activeOrders) {
        CurrencyPair currentCurrencyPair = adaptCurrencyPair(order.getSymbol());
        if (currencyPair != null && !currentCurrencyPair.equals(currencyPair)) {
            continue;
        }
        OrderType orderType = order.getSide().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
        Date timestamp = convertBigDecimalTimestampToDate(new BigDecimal(order.getTimestamp()));
        OrderStatus status = OrderStatus.NEW;
        if (order.isCancelled()) {
            status = OrderStatus.CANCELED;
        } else if (order.getExecutedAmount().signum() > 0 && order.getExecutedAmount().compareTo(order.getOriginalAmount()) < 0) {
            status = OrderStatus.PARTIALLY_FILLED;
        } else if (order.getExecutedAmount().compareTo(order.getOriginalAmount()) == 0) {
            status = OrderStatus.FILLED;
        }
        LimitOrder limitOrder = new LimitOrder(orderType, order.getOriginalAmount(), currentCurrencyPair, String.valueOf(order.getId()), timestamp, order.getPrice(), order.getAvgExecutionPrice(), order.getExecutedAmount(), null, status);
        limitOrders.add(limitOrder);
    }
    return new OpenOrders(limitOrders);
}
Also used : OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 99 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class TradeServiceIntegration method placeLimitOrder.

private static void placeLimitOrder() throws IOException {
    Exchange exx = getExchange();
    TradeService tradeService = exx.getTradeService();
    try {
        // place a limit order
        LimitOrder limitOrder = new LimitOrder((OrderType.BID), new BigDecimal("1.0"), CurrencyPair.ETH_BTC, null, null, new BigDecimal("0.00050"));
        String limitOrderReturnValue = tradeService.placeLimitOrder(limitOrder);
        System.out.println("Order Id: " + limitOrderReturnValue);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Exchange(org.knowm.xchange.Exchange) EXXExchange(org.knowm.xchange.exx.EXXExchange) TradeService(org.knowm.xchange.service.trade.TradeService) IOException(java.io.IOException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal)

Example 100 with LimitOrder

use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.

the class LivecoinTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
    try {
        CurrencyPair pair = null;
        if (params instanceof OpenOrdersParamCurrencyPair) {
            pair = ((OpenOrdersParamCurrencyPair) params).getCurrencyPair();
        }
        LivecoinPaginatedResponse<LivecoinUserOrder> response = clientOrders(pair, "OPEN", null, null, null, null);
        if (response.getData() == null) {
            return new OpenOrders(Collections.emptyList());
        }
        return new OpenOrders(response.getData().stream().filter(this::isOrderOpen).map(LivecoinAdapters::adaptUserOrder).filter(order -> order instanceof LimitOrder).map(order -> (LimitOrder) order).collect(Collectors.toList()));
    } catch (LivecoinException e) {
        throw LivecoinErrorAdapter.adapt(e);
    }
}
Also used : LivecoinErrorAdapter(org.knowm.xchange.livecoin.LivecoinErrorAdapter) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) Date(java.util.Date) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ArrayList(java.util.ArrayList) Order(org.knowm.xchange.dto.Order) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) LivecoinExchange(org.knowm.xchange.livecoin.LivecoinExchange) Livecoin(org.knowm.xchange.livecoin.Livecoin) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ResilienceRegistries(org.knowm.xchange.client.ResilienceRegistries) LivecoinUserOrder(org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder) Collection(java.util.Collection) IOException(java.io.IOException) UserTrades(org.knowm.xchange.dto.trade.UserTrades) LivecoinAdapters(org.knowm.xchange.livecoin.LivecoinAdapters) Collectors(java.util.stream.Collectors) Trades(org.knowm.xchange.dto.marketdata.Trades) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) List(java.util.List) TradeService(org.knowm.xchange.service.trade.TradeService) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) LivecoinPaginatedResponse(org.knowm.xchange.livecoin.dto.LivecoinPaginatedResponse) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) LivecoinUserOrder(org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) LivecoinAdapters(org.knowm.xchange.livecoin.LivecoinAdapters)

Aggregations

LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)337 BigDecimal (java.math.BigDecimal)188 Test (org.junit.Test)122 Date (java.util.Date)110 ArrayList (java.util.ArrayList)95 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)90 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)89 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)77 Order (org.knowm.xchange.dto.Order)50 OrderType (org.knowm.xchange.dto.Order.OrderType)39 Exchange (org.knowm.xchange.Exchange)31 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)29 List (java.util.List)28 TradeService (org.knowm.xchange.service.trade.TradeService)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 IOException (java.io.IOException)20 Collectors (java.util.stream.Collectors)20 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)17 InputStream (java.io.InputStream)15 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)15