Search in sources :

Example 1 with CoinbaseProFill

use of org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProFill 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 2 with CoinbaseProFill

use of org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProFill in project XChange by knowm.

the class CoinbaseProAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(List<CoinbaseProFill> coinbaseExFills) {
    List<UserTrade> trades = new ArrayList<>(coinbaseExFills.size());
    for (CoinbaseProFill fill : coinbaseExFills) {
        CurrencyPair currencyPair = new CurrencyPair(fill.getProductId().replace('-', '/'));
        trades.add(new UserTrade.Builder().type("buy".equals(fill.getSide()) ? OrderType.BID : OrderType.ASK).originalAmount(fill.getSize()).currencyPair(currencyPair).price(fill.getPrice()).timestamp(parseDate(fill.getCreatedAt())).id(String.valueOf(fill.getTradeId())).orderId(fill.getOrderId()).feeAmount(fill.getFee()).feeCurrency(currencyPair.counter).build());
    }
    return new UserTrades(trades, TradeSortType.SortByID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) CoinbaseProFill(org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProFill) UserTrade(org.knowm.xchange.dto.trade.UserTrade) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

CoinbaseProFill (org.knowm.xchange.coinbasepro.dto.trade.CoinbaseProFill)2 UserTrade (org.knowm.xchange.dto.trade.UserTrade)2 UserTrades (org.knowm.xchange.dto.trade.UserTrades)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 DefaultJacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory)1 JacksonObjectMapperFactory (si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory)1