Search in sources :

Example 21 with Order

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());
}
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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 22 with Order

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()));
}
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 23 with Order

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());
    }
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) GeminiOrderStatusResponse(org.knowm.xchange.gemini.v1.dto.trade.GeminiOrderStatusResponse) OrderType(org.knowm.xchange.dto.Order.OrderType) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 24 with Order

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());
}
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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) GeminiWalletJSONTest(org.knowm.xchange.gemini.v1.dto.account.GeminiWalletJSONTest)

Example 25 with Order

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)));
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) Order(org.knowm.xchange.dto.Order) CoinbaseProOrder(org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) JacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory) CoinbaseProOrder(org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Date(java.util.Date) MathContext(java.math.MathContext) 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