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