Search in sources :

Example 11 with Order

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

the class LgoStreamingTradeServiceTest method it_handles_order_changes.

@Test
public void it_handles_order_changes() throws IOException, ParseException {
    JsonNode snapshot = TestUtils.getJsonContent("/trade/order-changes-snapshot.json");
    JsonNode update = TestUtils.getJsonContent("/trade/order-changes-update.json");
    when(streamingService.subscribeChannel(anyString())).thenReturn(Observable.just(snapshot, update));
    Observable<Order> observable = service.getOrderChanges(CurrencyPair.BTC_USD);
    verify(streamingService).subscribeChannel("user-BTC-USD");
    Date date1 = dateFormat.parse("2019-07-23T15:36:14.304Z");
    Date date2 = dateFormat.parse("2019-07-18T12:24:21.891Z");
    Date date3 = dateFormat.parse("2019-07-24T08:37:19.116Z");
    LimitOrder order1 = createOrder(Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156389617430400001", date1, new BigDecimal("6000.0000"), Order.OrderStatus.NEW);
    LimitOrder order2 = createOrder(Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.NEW);
    LimitOrder order2Matched = createOrder(Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("0.40000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.PARTIALLY_FILLED);
    order2Matched.setFee(new BigDecimal("0.2388"));
    LimitOrder order2Matched2 = createOrder(Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("1.00000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.PARTIALLY_FILLED);
    order2Matched2.setFee(new BigDecimal("0.6988"));
    LimitOrder order2Filled = createOrder(Order.OrderType.ASK, new BigDecimal("1.00000000"), new BigDecimal("1.00000000"), CurrencyPair.BTC_USD, "156345266189100001", date2, new BigDecimal("6000.0000"), Order.OrderStatus.FILLED);
    order2Filled.setFee(new BigDecimal("0.6988"));
    LimitOrder order3Pending = createOrder(Order.OrderType.BID, new BigDecimal("2.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156395743911600001", date3, new BigDecimal("8000.0000"), Order.OrderStatus.PENDING_NEW);
    LimitOrder order3Open = createOrder(Order.OrderType.BID, new BigDecimal("2.00000000"), new BigDecimal("0.00000000"), CurrencyPair.BTC_USD, "156395743911600001", date3, new BigDecimal("8000.0000"), Order.OrderStatus.NEW);
    ArrayList<Order> orderChanges = Lists.newArrayList(observable.blockingIterable());
    assertThat(orderChanges).hasSize(7);
    assertThat(orderChanges.get(0)).usingRecursiveComparison().isEqualTo(order1);
    assertThat(orderChanges.get(1)).usingRecursiveComparison().isEqualTo(order2);
    assertThat(orderChanges.get(2)).usingRecursiveComparison().isEqualTo(order3Pending);
    assertThat(orderChanges.get(3)).usingRecursiveComparison().isEqualTo(order3Open);
    assertThat(orderChanges.get(4)).usingRecursiveComparison().isEqualTo(order2Matched);
    assertThat(orderChanges.get(5)).usingRecursiveComparison().isEqualTo(order2Matched2);
    assertThat(orderChanges.get(6)).usingRecursiveComparison().isEqualTo(order2Filled);
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) JsonNode(com.fasterxml.jackson.databind.JsonNode) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 12 with Order

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

the class DVChainAdapters method adaptOpenOrders.

public static OpenOrders adaptOpenOrders(List<DVChainTrade> orders) {
    List<LimitOrder> openOrders = new ArrayList<>(orders.size());
    for (DVChainTrade order : orders) {
        CurrencyPair currencyPair = new CurrencyPair(order.getAsset(), "USD");
        Order.OrderType orderType = order.getSide().equals("buy") ? Order.OrderType.BID : Order.OrderType.ASK;
        LimitOrder limitOrder = new LimitOrder(orderType, order.getQuantity(), order.getQuantity(), currencyPair, order.getId(), Date.from(order.getCreatedAt()), order.getLimitPrice());
        openOrders.add(limitOrder);
    }
    return new OpenOrders(openOrders);
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) DVChainTrade(org.knowm.xchange.dvchain.dto.trade.DVChainTrade) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 13 with Order

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

the class IndependentReserveTradeServiceIntegration method testGetTradeHistory.

@Test
public void testGetTradeHistory() throws Exception {
    Assume.assumeNotNull(exchange.getExchangeSpecification().getApiKey());
    UserTrades userTrades = tradeService.getTradeHistory(tradeService.createTradeHistoryParams());
    if (userTrades.getUserTrades().size() > 0) {
        UserTrade userTrade = userTrades.getUserTrades().get(0);
        String orderId = userTrade.getOrderId();
        Collection<Order> orders = tradeService.getOrder(orderId);
    }
}
Also used : Order(org.knowm.xchange.dto.Order) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Test(org.junit.Test)

Example 14 with Order

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

the class HuobiPrivateApiIntegration method getOrderTest.

@Test
public void getOrderTest() throws IOException {
    TradeService tradeService = exchange.getTradeService();
    Collection<Order> orders = tradeService.getOrder("2132866355");
    System.out.println(orders.toString());
    assertThat(orders).isNotNull();
}
Also used : 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) Test(org.junit.Test)

Example 15 with Order

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

the class BitfinexStreamingAdaptersTest method testMarketOrder.

@Test
public void testMarketOrder() {
    BitfinexWebSocketAuthOrder bitfinexWebSocketAuthOrder = new BitfinexWebSocketAuthOrder(// id,
    123123123L, // groupId,
    0L, // cid,
    456456456L, // symbol,
    "tBTCUSD", // mtsCreateamount
    1548674205259L, // mtsUpdate
    1548674205259L, // amount
    new BigDecimal("0.000"), // amountOrig
    new BigDecimal("0.004"), // type
    "MARKET", // typePrev
    null, // orderStatus
    "EXECUTED @ 3495.1(0.004)", // price
    new BigDecimal("3495.2"), // priceAvg
    new BigDecimal("3495.2"), // priceTrailing
    BigDecimal.ZERO, // priceAuxLimit
    BigDecimal.ZERO, // placedId
    0, // flags
    0);
    // TODO awaiting https://github.com/knowm/XChange/pull/2907 then I can add market order
    // support to XChange itself. In the meantime these are returned as limit orders.
    Order adaptedOrder = BitfinexStreamingAdapters.adaptOrder(bitfinexWebSocketAuthOrder);
    assertEquals("123123123", adaptedOrder.getId());
    assertEquals(Order.OrderType.BID, adaptedOrder.getType());
    assertEquals(new BigDecimal("3495.2"), adaptedOrder.getAveragePrice());
    assertEquals(new BigDecimal("0.004"), adaptedOrder.getCumulativeAmount());
    assertEquals(CurrencyPair.BTC_USD, adaptedOrder.getCurrencyPair());
    // TODO see above. should be:
    // assertEquals(Collections.singleton(BitfinexOrderFlags.MARGIN), adaptedOrder.getOrderFlags());
    assertEquals(new BigDecimal("0.004"), adaptedOrder.getOriginalAmount());
    assertEquals(new BigDecimal("0.000"), adaptedOrder.getRemainingAmount());
    assertEquals(OrderStatus.FILLED, adaptedOrder.getStatus());
    assertEquals(new Date(1548674205259L).getTime(), adaptedOrder.getTimestamp().getTime());
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) BitfinexWebSocketAuthOrder(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketAuthOrder) BitfinexWebSocketAuthOrder(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketAuthOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date) 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