use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class CoindealAdapters method adaptToUserTrades.
public static UserTrades adaptToUserTrades(List<CoindealTradeHistory> coindealTradeHistoryList) throws InvalidFormatException {
List<UserTrade> userTrades = new ArrayList<>();
for (CoindealTradeHistory coindealTradeHistory : coindealTradeHistoryList) {
CurrencyPair currencyPair = CurrencyPairDeserializer.getCurrencyPairFromString(coindealTradeHistory.getSymbol());
userTrades.add(new UserTrade.Builder().type((coindealTradeHistory.getSide().equals("BUY")) ? Order.OrderType.BID : Order.OrderType.ASK).originalAmount(coindealTradeHistory.getQuantity()).currencyPair(currencyPair).price(coindealTradeHistory.getPrice()).timestamp(DateUtils.fromRfc3339DateString(coindealTradeHistory.getTimestamp())).id(coindealTradeHistory.getId()).orderId(coindealTradeHistory.getOrderId()).feeAmount(coindealTradeHistory.getFee()).feeCurrency((coindealTradeHistory.getSide().equals("BUY") ? currencyPair.base : currencyPair.counter)).build());
}
return new UserTrades(userTrades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class LivecoinTradeServiceRaw method tradeHistory.
public List<UserTrade> tradeHistory(Date startTime, Date endTime, Integer limit, Long offset) throws IOException {
long end = DateUtils.toMillisNullSafe(endTime);
// Livecoin API limitation: 30 days max period
long start = Math.max(DateUtils.toMillisNullSafe(startTime), end - THIRTY_DAYS_MILLISECONDS);
List<Map> response = decorateApiCall(() -> service.transactions(apiKey, signatureCreator, String.valueOf(start), String.valueOf(end), "BUY,SELL", limit, offset)).withRetry(retry("transactions")).call();
List<UserTrade> resp = new ArrayList<>();
for (Map map : response) {
UserTrade fundingRecord = LivecoinAdapters.adaptUserTrade(map);
resp.add(fundingRecord);
}
return resp;
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class BitfinexAdapters method adaptTradeHistoryV2.
public static UserTrades adaptTradeHistoryV2(List<org.knowm.xchange.bitfinex.v2.dto.trade.Trade> trades) {
List<UserTrade> pastTrades = new ArrayList<>(trades.size());
for (org.knowm.xchange.bitfinex.v2.dto.trade.Trade trade : trades) {
OrderType orderType = trade.getExecAmount().signum() >= 0 ? OrderType.BID : OrderType.ASK;
BigDecimal amount = trade.getExecAmount().signum() == -1 ? trade.getExecAmount().negate() : trade.getExecAmount();
final BigDecimal fee = trade.getFee() != null ? trade.getFee().negate() : null;
pastTrades.add(new UserTrade.Builder().type(orderType).originalAmount(amount).currencyPair(adaptCurrencyPair(trade.getSymbol())).price(trade.getExecPrice()).timestamp(trade.getTimestamp()).id(trade.getId()).orderId(trade.getOrderId()).feeAmount(fee).feeCurrency(Currency.getInstance(trade.getFeeCurrency())).build());
}
return new UserTrades(pastTrades, TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class BitfinexAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(BitfinexTradeResponse[] trades, String symbol) {
List<UserTrade> pastTrades = new ArrayList<>(trades.length);
CurrencyPair currencyPair = adaptCurrencyPair(symbol);
for (BitfinexTradeResponse trade : trades) {
OrderType orderType = trade.getType().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
Date timestamp = convertBigDecimalTimestampToDate(trade.getTimestamp());
final BigDecimal fee = trade.getFeeAmount() == null ? null : trade.getFeeAmount().negate();
pastTrades.add(new UserTrade.Builder().type(orderType).originalAmount(trade.getAmount()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(timestamp).id(trade.getTradeId()).orderId(trade.getOrderId()).feeAmount(fee).feeCurrency(Currency.getInstance(trade.getFeeCurrency())).build());
}
return new UserTrades(pastTrades, TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class CryptopiaTradeServiceRaw method tradeHistory.
public List<UserTrade> tradeHistory(CurrencyPair currencyPair, Integer count) throws IOException {
CryptopiaBaseResponse<List<Map>> response = cryptopia.getTradeHistory(signatureCreator, new Cryptopia.GetTradeHistoryRequest(currencyPair == null ? null : currencyPair.toString(), count == null ? 100 : count));
List<UserTrade> results = new ArrayList<>();
for (Map map : response.getData()) {
Order.OrderType type = type(map);
BigDecimal amount = new BigDecimal(map.get("Amount").toString());
BigDecimal price = new BigDecimal(map.get("Rate").toString());
Date timestamp = CryptopiaAdapters.convertTimestamp(map.get("TimeStamp").toString());
String id = map.get("TradeId").toString();
BigDecimal fee = new BigDecimal(map.get("Fee").toString());
String orderId = id;
CurrencyPair pair = new CurrencyPair(map.get("Market").toString());
Currency feeCcy = pair.counter;
results.add(new UserTrade.Builder().type(type).originalAmount(amount).currencyPair(pair).price(price).timestamp(timestamp).id(id).orderId(orderId).feeAmount(fee).feeCurrency(feeCcy).build());
}
return results;
}
Aggregations