Search in sources :

Example 21 with UserTrade

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();
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Test(org.junit.Test)

Example 22 with UserTrade

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) CoinmateTradeHistoryEntry(org.knowm.xchange.coinmate.dto.trade.CoinmateTradeHistoryEntry) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date)

Example 23 with UserTrade

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) HitbtcUserTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcUserTrade) ArrayList(java.util.ArrayList) HitbtcOwnTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcOwnTrade) HitbtcUserTrade(org.knowm.xchange.hitbtc.v2.dto.HitbtcUserTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 24 with UserTrade

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);
}
Also used : InputStream(java.io.InputStream) RippleTradeHistoryParams(org.knowm.xchange.ripple.service.params.RippleTradeHistoryParams) RippleUserTrade(org.knowm.xchange.ripple.dto.trade.RippleUserTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) RippleUserTrade(org.knowm.xchange.ripple.dto.trade.RippleUserTrade) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RippleOrderTransaction(org.knowm.xchange.ripple.dto.trade.RippleOrderTransaction) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 25 with UserTrade

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

Aggregations

UserTrade (org.knowm.xchange.dto.trade.UserTrade)112 UserTrades (org.knowm.xchange.dto.trade.UserTrades)62 ArrayList (java.util.ArrayList)57 BigDecimal (java.math.BigDecimal)50 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)40 Date (java.util.Date)31 Test (org.junit.Test)25 OrderType (org.knowm.xchange.dto.Order.OrderType)19 List (java.util.List)14 Test (org.junit.jupiter.api.Test)14 TradeHistoryParams (org.knowm.xchange.service.trade.params.TradeHistoryParams)14 IOException (java.io.IOException)13 Currency (org.knowm.xchange.currency.Currency)13 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)13 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 TradeService (org.knowm.xchange.service.trade.TradeService)11 InputStream (java.io.InputStream)10 Order (org.knowm.xchange.dto.Order)10 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)10