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