Search in sources :

Example 1 with UserTrade

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

the class BitstampTradeServiceIntegration method testGetTradeHistory.

@Test
public void testGetTradeHistory() throws IOException {
    final BitstampTradeHistoryParams tradeHistoryParams = (BitstampTradeHistoryParams) bitstampTradeService.createTradeHistoryParams();
    final List<UserTrade> userTrades = bitstampTradeService.getTradeHistory(tradeHistoryParams).getUserTrades();
    assertThat(userTrades).isNotNull();
    int numberOfLastTradesToLoad = 2;
    if (userTrades.size() >= numberOfLastTradesToLoad) {
        final UserTrade referenceTrade = userTrades.get(userTrades.size() - numberOfLastTradesToLoad);
        tradeHistoryParams.setStartId(referenceTrade.getId());
        final List<UserTrade> userTradesSinceTradeId = bitstampTradeService.getTradeHistory(tradeHistoryParams).getUserTrades();
        assertThat(userTradesSinceTradeId).hasSize(numberOfLastTradesToLoad);
    }
}
Also used : UserTrade(org.knowm.xchange.dto.trade.UserTrade) Test(org.junit.Test)

Example 2 with UserTrade

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

the class CoingiAdapters method adaptTradeHistory.

public static UserTrades adaptTradeHistory(CoingiOrdersList ordersList) {
    List<UserTrade> trades = new ArrayList<>();
    for (CoingiOrder o : ordersList.getList()) {
        final OrderType orderType = o.getType() == 0 ? OrderType.BID : OrderType.ASK;
        final CurrencyPair pair = new CurrencyPair(o.getCurrencyPair().get("base").toUpperCase(), o.getCurrencyPair().get("counter").toUpperCase());
        UserTrade trade = new UserTrade.Builder().type(orderType).originalAmount(o.getOriginalBaseAmount()).currencyPair(pair).price(o.getPrice()).timestamp(new Date(o.getTimestamp())).id(o.getId()).orderId(o.getId()).feeAmount(BigDecimal.ZERO).build();
        trades.add(trade);
    }
    return new UserTrades(trades, TradeSortType.SortByID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) CoingiOrder(org.knowm.xchange.coingi.dto.trade.CoingiOrder) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 3 with UserTrade

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

the class CoinmateStreamingTradeService method getUserTrades.

@Override
public Observable<UserTrade> getUserTrades(CurrencyPair currencyPair, Object... args) {
    String channelName = "private-user-trades-" + coinmateStreamingService.getUserId() + "-" + CoinmateStreamingAdapter.getChannelPostfix(currencyPair);
    ObjectReader reader = StreamingObjectMapperHelper.getObjectMapper().readerFor(new TypeReference<List<CoinmateWebSocketUserTrade>>() {
    });
    return coinmateStreamingService.subscribeChannel(channelName, true).map((message) -> {
        List<CoinmateWebSocketUserTrade> webSocketUserTrades = reader.readValue(message.get("payload"));
        return CoinmateStreamingAdapter.adaptWebSocketUserTrades(webSocketUserTrades, currencyPair);
    }).concatMapIterable(UserTrades::getUserTrades);
}
Also used : Arrays(java.util.Arrays) CoinmateWebsocketOpenOrder(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebsocketOpenOrder) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) StreamingObjectMapperHelper(info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) CoinmateWebSocketUserTrade(info.bitrich.xchangestream.coinmate.v2.dto.CoinmateWebSocketUserTrade) Order(org.knowm.xchange.dto.Order) List(java.util.List) JsonNode(com.fasterxml.jackson.databind.JsonNode) Observable(io.reactivex.Observable) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) TypeReference(com.fasterxml.jackson.core.type.TypeReference) StreamingTradeService(info.bitrich.xchangestream.core.StreamingTradeService) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) UserTrades(org.knowm.xchange.dto.trade.UserTrades) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) List(java.util.List)

Example 4 with UserTrade

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

the class BitbayTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    CurrencyPair currencyPair = null;
    if (params instanceof TradeHistoryParamCurrencyPair) {
        currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
    }
    List<Map> response = getBitbayTransactions(currencyPair);
    List<UserTrade> trades = BitbayAdapters.adaptTransactions(response);
    return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Map(java.util.Map) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 5 with UserTrade

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

the class BTCTurkTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    List<UserTrade> trades = new ArrayList<UserTrade>();
    List<BTCTurkUserTransactions> transactions = super.getBTCTurkUserTransactions();
    for (BTCTurkUserTransactions transaction : transactions) {
        if (transaction.getOperation().equals(BTCTurkOperations.trade))
            trades.add(new UserTrade.Builder().type(((transaction.getAmount().compareTo(BigDecimal.ZERO) > 0) ? OrderType.ASK : OrderType.BID)).originalAmount(transaction.getAmount()).price(transaction.getPrice()).timestamp(transaction.getDate()).id(transaction.getId()).feeAmount(transaction.getFee()).feeCurrency(transaction.getCurrency()).build());
    }
    long lastId = transactions.stream().map(t -> Long.parseLong(t.getId())).max(Long::compareTo).orElse(0L);
    return new UserTrades(trades, lastId, TradeSortType.SortByTimestamp);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BTCTurkUserTransactions(org.knowm.xchange.btcturk.dto.account.BTCTurkUserTransactions)

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