use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class GeminiAdaptersTest method testAdaptOrderResponseContainingTradesToOrder.
@Test
public void testAdaptOrderResponseContainingTradesToOrder() throws IOException {
InputStream resourceAsStream = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/example-get-order-data-trades-included.json");
GeminiOrderStatusResponse response = new ObjectMapper().readValue(resourceAsStream, GeminiOrderStatusResponse.class);
Order order = GeminiAdapters.adaptOrder(response);
assertEquals("54516439535", order.getId());
assertEquals("TESTID0", order.getUserReference());
assertEquals(new Date(1629872367328L), order.getTimestamp());
assertEquals(CurrencyPair.ETH_USD, order.getInstrument());
assertEquals(OrderType.ASK, order.getType());
assertEquals(new BigDecimal("0.001"), order.getOriginalAmount());
assertEquals(new BigDecimal("3206.00"), order.getAveragePrice());
assertEquals(new BigDecimal("0.001"), order.getCumulativeAmount());
assertEquals(new BigDecimal("0.000"), order.getRemainingAmount());
assertEquals(new BigDecimal("0.003206"), order.getFee());
assertEquals(Order.OrderStatus.FILLED, order.getStatus());
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class GeminiAdaptersTest method testAdaptLimitOrderPartiallyFilled.
@Test
public void testAdaptLimitOrderPartiallyFilled() throws IOException {
// Read in the JSON from the example resources
InputStream is = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/limit-order-partially-filled.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("400.00"));
assertThat(order.getCumulativeAmount()).isEqualTo(new BigDecimal("1"));
assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.PARTIALLY_FILLED);
assertThat(LimitOrder.class.isAssignableFrom(order.getClass()));
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class GeminiAdaptersTest method testAdaptOrdersToOpenOrdersFiltersByCurrencyPair.
@Test
public void testAdaptOrdersToOpenOrdersFiltersByCurrencyPair() {
GeminiOrderStatusResponse[] responsesToRetain = ArrayUtils.addAll(initOrderStatusResponses(SYMBOL), initOrderStatusResponses(SYMBOL));
GeminiOrderStatusResponse[] responses = ArrayUtils.addAll(initOrderStatusResponses("ETHBTC"), responsesToRetain);
OpenOrders orders = GeminiAdapters.adaptOrders(responses, CurrencyPair.BTC_USD);
assertEquals(orders.getOpenOrders().size(), responsesToRetain.length);
for (int i = 0; i < responsesToRetain.length; i++) {
LimitOrder order = orders.getOpenOrders().get(i);
long expectedTimestampMillis = new BigDecimal(responsesToRetain[i].getTimestamp()).multiply(new BigDecimal(1000L)).longValue();
Order.OrderType expectedOrderType = responsesToRetain[i].getSide().equalsIgnoreCase("buy") ? Order.OrderType.BID : Order.OrderType.ASK;
assertEquals(String.valueOf(responsesToRetain[i].getId()), order.getId());
assertEquals(responsesToRetain[i].getOriginalAmount(), order.getOriginalAmount());
assertEquals(responsesToRetain[i].getRemainingAmount(), order.getRemainingAmount());
assertEquals(responsesToRetain[i].getExecutedAmount(), order.getOriginalAmount().subtract(order.getRemainingAmount()));
assertEquals(GeminiAdapters.adaptCurrencyPair(SYMBOL), order.getInstrument());
assertEquals(expectedOrderType, order.getType());
assertEquals(expectedTimestampMillis, order.getTimestamp().getTime());
assertEquals(responsesToRetain[i].getPrice(), order.getLimitPrice());
}
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class GeminiAdaptersTest method testAdaptOrderResponseToOrder.
@Test
public void testAdaptOrderResponseToOrder() throws IOException {
InputStream resourceAsStream = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/example-get-order-data.json");
GeminiOrderStatusResponse response = new ObjectMapper().readValue(resourceAsStream, GeminiOrderStatusResponse.class);
Order order = GeminiAdapters.adaptOrder(response);
assertEquals("54323412782", order.getId());
assertEquals(new Date(1629770740526L), order.getTimestamp());
assertEquals(CurrencyPair.ETH_USD, order.getInstrument());
assertEquals(OrderType.ASK, order.getType());
assertEquals(new BigDecimal("0.001"), order.getOriginalAmount());
assertEquals(new BigDecimal("0.00"), order.getAveragePrice());
assertEquals(Order.OrderStatus.OPEN, order.getStatus());
assertEquals(BigDecimal.ZERO, order.getCumulativeAmount());
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class CoinbaseProAdaptersTest method testOrderStatusLimitOrderSettled.
@Test
public void testOrderStatusLimitOrderSettled() throws IOException {
final JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
final ObjectMapper mapper = factory.createObjectMapper();
final InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/order/example-limit-order-settled.json");
final CoinbaseProOrder coinbaseProOrder = mapper.readValue(is, CoinbaseProOrder.class);
final Order order = CoinbaseProAdapters.adaptOrder(coinbaseProOrder);
assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.FILLED);
assertThat(order.getId()).isEqualTo("b2cdd7fe-1f4a-495e-8b96-7a4be368f43c");
assertThat(order.getCurrencyPair()).isEqualTo((CurrencyPair.BTC_USD));
assertThat(order.getOriginalAmount()).isEqualByComparingTo(new BigDecimal("0.07060351"));
assertThat(order.getCumulativeAmount()).isEqualByComparingTo(new BigDecimal("0.07060351"));
assertThat(order.getRemainingAmount()).isEqualByComparingTo(BigDecimal.ZERO);
assertThat(LimitOrder.class.isAssignableFrom(order.getClass())).isTrue();
assertThat(order.getType()).isEqualTo(OrderType.ASK);
assertThat(order.getTimestamp()).isEqualTo(new Date(1515434144454L));
assertThat(order.getAveragePrice()).isEqualByComparingTo(new BigDecimal("1050.2618069699000000").divide(new BigDecimal("0.07060351"), new MathContext(8)));
}
Aggregations