use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class TradeServiceTest method tradeHistoryTest.
@Test
public void tradeHistoryTest() throws Exception {
stubFor(get(urlPathEqualTo("/v3/orders/closed")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBodyFile("orderhistory.json")));
TradeHistoryParams params = tradeService.createTradeHistoryParams();
UserTrades tradeHistory = tradeService.getTradeHistory(params);
assertThat(tradeHistory).isNotNull();
assertThat(tradeHistory.getUserTrades()).isNotEmpty();
UserTrade trade = tradeHistory.getUserTrades().get(0);
assertThat(trade).isNotNull();
assertThat(trade.getOriginalAmount()).isNotNull().isPositive();
assertThat(trade.getPrice()).isNotNull().isPositive();
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class CoinmateAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(CoinmateTradeHistory coinmateTradeHistory) {
List<UserTrade> trades = new ArrayList<>(coinmateTradeHistory.getData().size());
for (CoinmateTradeHistoryEntry entry : coinmateTradeHistory.getData()) {
UserTrade trade = new UserTrade.Builder().type(typeToOrderTypeOrNull(entry.getType())).originalAmount(entry.getAmount()).currencyPair(CoinmateUtils.getPair(entry.getCurrencyPair())).price(entry.getPrice()).timestamp(new Date(entry.getCreatedTimestamp())).id(Long.toString(entry.getTransactionId())).orderId(Long.toString(entry.getOrderId())).feeAmount(entry.getFee()).feeCurrency(CoinmateUtils.getPair(entry.getCurrencyPair()).counter).build();
trades.add(trade);
}
return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class HitbtcAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(List<HitbtcOwnTrade> tradeHistoryRaw) {
List<UserTrade> trades = new ArrayList<>(tradeHistoryRaw.size());
for (HitbtcOwnTrade hitbtcOwnTrade : tradeHistoryRaw) {
OrderType type = adaptOrderType(hitbtcOwnTrade.getSide().getValue());
CurrencyPair pair = adaptSymbol(hitbtcOwnTrade.symbol);
BigDecimal originalAmount = hitbtcOwnTrade.getQuantity();
Date timestamp = hitbtcOwnTrade.getTimestamp();
String id = Long.toString(hitbtcOwnTrade.getId());
String orderId = String.valueOf(hitbtcOwnTrade.getOrderId());
String clientOrderId = hitbtcOwnTrade.getClientOrderId();
UserTrade trade = new HitbtcUserTrade(type, originalAmount, pair, hitbtcOwnTrade.getPrice(), timestamp, id, orderId, hitbtcOwnTrade.getFee(), pair.counter, clientOrderId);
trades.add(trade);
}
return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class RippleAdaptersTest method adaptTrade_SellBTC_BuyXRP.
@Test
public void adaptTrade_SellBTC_BuyXRP() throws JsonParseException, JsonMappingException, IOException, ParseException {
final RippleExchange exchange = new RippleExchange();
final int roundingScale = exchange.getRoundingScale();
// Read the trade JSON from the example resources
final InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/ripple/dto/trade/example-trade-buyXRP-sellBTC.json");
final ObjectMapper mapper = new ObjectMapper();
final RippleOrderTransaction response = mapper.readValue(is, RippleOrderTransaction.class);
final RippleTradeHistoryParams params = new RippleTradeHistoryParams();
params.addPreferredBaseCurrency(Currency.BTC);
final UserTrade trade = RippleAdapters.adaptTrade(response, params, this, roundingScale);
assertThat(trade.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_XRP);
assertThat(trade.getFeeAmount()).isEqualTo("0.012");
assertThat(trade.getFeeCurrency()).isEqualTo(Currency.XRP);
assertThat(trade.getId()).isEqualTo("0000000000000000000000000000000000000000000000000000000000000000");
assertThat(trade.getOrderId()).isEqualTo("1010");
// Price = 1.0 / (0.000029309526038 * 0.998)
assertThat(trade.getPrice()).isEqualTo(new BigDecimal("34186.97411609205306550363511634115030681332485583111528").setScale(roundingScale, RoundingMode.HALF_UP));
assertThat(trade.getTimestamp()).isEqualTo(RippleExchange.ToDate("2000-00-00T00:00:00.000Z"));
// Quantity = 0.000029309526038 * 0.998
assertThat(trade.getOriginalAmount()).isEqualTo("0.000029250906985924");
assertThat(trade.getType()).isEqualTo(OrderType.ASK);
assertThat(trade).isInstanceOf(RippleUserTrade.class);
final RippleUserTrade ripple = (RippleUserTrade) trade;
assertThat(ripple.getBaseCounterparty()).isEqualTo("rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q");
// Transfer fee = 0.000029309526038 * 0.002
assertThat(ripple.getBaseTransferFee()).isEqualTo("0.000000058619052076");
assertThat(ripple.getBaseTransferFeeCurrency()).isEqualTo(Currency.BTC);
assertThat(ripple.getBaseTransferFeeCurrency()).isEqualTo(trade.getCurrencyPair().base);
assertThat(ripple.getCounterCounterparty()).isEmpty();
assertThat(ripple.getCounterTransferFee()).isZero();
assertThat(ripple.getCounterTransferFeeCurrency()).isEqualTo(Currency.XRP);
assertThat(ripple.getCounterTransferFeeCurrency()).isEqualTo(trade.getCurrencyPair().counter);
}
use of org.knowm.xchange.dto.trade.UserTrade 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);
}
Aggregations