Search in sources :

Example 1 with DefaultJacksonObjectMapperFactory

use of si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory 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)

Example 2 with DefaultJacksonObjectMapperFactory

use of si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory in project XChange by knowm.

the class CoinbaseProAdaptersTest method testOrderStatusStopOrderNew.

@Test
public void testOrderStatusStopOrderNew() throws JsonParseException, JsonMappingException, IOException {
    final JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
    final ObjectMapper mapper = factory.createObjectMapper();
    final InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/order/example-stop-order-new.json");
    final CoinbaseProOrder coinbaseProOrder = mapper.readValue(is, CoinbaseProOrder.class);
    final Order order = CoinbaseProAdapters.adaptOrder(coinbaseProOrder);
    assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.NEW);
    assertThat(order.getId()).isEqualTo("853a9989-7dd9-40f8-9392-64237a9eccc4");
    assertThat(order.getCurrencyPair()).isEqualTo((CurrencyPair.BTC_EUR));
    assertThat(order.getOriginalAmount()).isEqualByComparingTo(new BigDecimal("0.01"));
    assertThat(order.getCumulativeAmount()).isEqualByComparingTo(BigDecimal.ZERO);
    assertThat(order.getRemainingAmount()).isEqualByComparingTo(new BigDecimal("0.01"));
    assertThat(order.getType()).isEqualTo(OrderType.ASK);
    assertThat(order.getTimestamp()).isEqualTo(new Date(1515434144454L));
    assertThat(order.getAveragePrice()).isEqualByComparingTo(BigDecimal.ZERO);
    assertThat(StopOrder.class.isAssignableFrom(order.getClass())).isTrue();
    StopOrder stop = (StopOrder) order;
    assertThat(stop.getStopPrice()).isEqualByComparingTo("6364.31");
}
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) StopOrder(org.knowm.xchange.dto.trade.StopOrder) 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) Test(org.junit.Test)

Example 3 with DefaultJacksonObjectMapperFactory

use of si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory in project XChange by knowm.

the class CoinbaseProAdaptersTest method testOrderStatusLimitOrderFilled.

@Test
public void testOrderStatusLimitOrderFilled() throws IOException {
    JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
    ObjectMapper mapper = factory.createObjectMapper();
    InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/order/example-limit-order-filled.json");
    CoinbaseProOrder coinbaseProOrder = mapper.readValue(is, CoinbaseProOrder.class);
    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(new BigDecimal("0.00000000"));
    assertThat(order.getFee()).isEqualTo(new BigDecimal("2.6256545174247500"));
    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)

Example 4 with DefaultJacksonObjectMapperFactory

use of si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory in project XChange by knowm.

the class CoinbaseProAdaptersTest method testTradeHistoryAdapter.

@Test
public void testTradeHistoryAdapter() throws IOException {
    JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
    ObjectMapper mapper = factory.createObjectMapper();
    InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/trade/example-fills.json");
    List<CoinbaseProFill> fills = mapper.readValue(is, new TypeReference<List<CoinbaseProFill>>() {
    });
    UserTrades trades = CoinbaseProAdapters.adaptTradeHistory(fills);
    assertThat(trades.getUserTrades()).hasSize(1);
    UserTrade trade = trades.getUserTrades().get(0);
    assertThat(trade.getId()).isEqualTo("470768");
    assertThat(trade.getCurrencyPair()).isEqualTo(CurrencyPair.ETH_BTC);
    assertThat(trade.getPrice()).isEqualTo("0.05915000");
    assertThat(trade.getOriginalAmount()).isEqualTo("0.01000000");
    assertThat(trade.getOrderId()).isEqualTo("b4b3bbb1-e0e3-4532-9413-23123448ce35");
    assertThat(trade.getTimestamp().getTime()).isEqualTo(1493623910243L);
    assertThat(trade.getFeeAmount()).isEqualTo("0.0000017745000000");
    assertThat(trade.getType()).isEqualTo(OrderType.BID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) 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) CoinbaseProFill(org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProFill) List(java.util.List) UserTrade(org.knowm.xchange.dto.trade.UserTrade) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with DefaultJacksonObjectMapperFactory

use of si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory in project XChange by knowm.

the class CoinbaseProAdaptersTest method testOrderStatusStopOrderFilled.

@Test
public void testOrderStatusStopOrderFilled() throws JsonParseException, JsonMappingException, IOException {
    final JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
    final ObjectMapper mapper = factory.createObjectMapper();
    final InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/order/example-stop-order-filled.json");
    final CoinbaseProOrder coinbaseProOrder = mapper.readValue(is, CoinbaseProOrder.class);
    final Order order = CoinbaseProAdapters.adaptOrder(coinbaseProOrder);
    assertStopOrderFilled(order);
}
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) Test(org.junit.Test)

Aggregations

DefaultJacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory)19 Test (org.junit.Test)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 InputStream (java.io.InputStream)15 JacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory)15 ByteArrayInputStream (java.io.ByteArrayInputStream)10 SequenceInputStream (java.io.SequenceInputStream)10 CoinbaseProOrder (org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProOrder)9 Order (org.knowm.xchange.dto.Order)8 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)8 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)8 StopOrder (org.knowm.xchange.dto.trade.StopOrder)8 BigDecimal (java.math.BigDecimal)6 Date (java.util.Date)6 Method (java.lang.reflect.Method)4 PoloniexException (org.knowm.xchange.poloniex.dto.PoloniexException)4 InvocationResult (si.mazi.rescu.InvocationResult)4 RestMethodMetadata (si.mazi.rescu.RestMethodMetadata)4 JacksonResponseReader (si.mazi.rescu.serialization.jackson.JacksonResponseReader)4 MathContext (java.math.MathContext)3