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);
}
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);
}
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);
}
}
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();
}
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());
}
Aggregations