use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class OkexAdapters method adaptUserTrades.
public static UserTrades adaptUserTrades(List<OkexOrderDetails> okexTradeHistory) {
List<UserTrade> userTradeList = new ArrayList<>();
okexTradeHistory.forEach(okexOrderDetails -> {
userTradeList.add(new UserTrade.Builder().originalAmount(new BigDecimal(okexOrderDetails.getAmount())).instrument(new CurrencyPair(okexOrderDetails.getInstrumentId())).currencyPair(new CurrencyPair(okexOrderDetails.getInstrumentId())).price(new BigDecimal(okexOrderDetails.getAverageFilledPrice())).type(adaptOkexOrderSideToOrderType(okexOrderDetails.getSide())).id(okexOrderDetails.getOrderId()).orderId(okexOrderDetails.getOrderId()).timestamp(Date.from(Instant.ofEpochMilli(Long.parseLong(okexOrderDetails.getUpdateTime())))).feeAmount(new BigDecimal(okexOrderDetails.getFee())).feeCurrency(new Currency(okexOrderDetails.getFeeCurrency())).orderUserReference(okexOrderDetails.getClientOrderId()).build());
});
return new UserTrades(userTradeList, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class YoBitTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
Integer count = 1000;
if (params instanceof TradeHistoryParamLimit) {
count = ((TradeHistoryParamLimit) params).getLimit();
}
Long offset = 0L;
if (params instanceof TradeHistoryParamOffset) {
offset = ((TradeHistoryParamOffset) params).getOffset();
}
String market = null;
if (params instanceof TradeHistoryParamCurrencyPair) {
CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
market = YoBitAdapters.adaptCcyPairToUrlFormat(currencyPair);
}
Long fromTransactionId = null;
Long endTransactionId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
String startId = tradeHistoryParamsIdSpan.getStartId();
if (startId != null)
fromTransactionId = Long.valueOf(startId);
String endId = tradeHistoryParamsIdSpan.getEndId();
if (endId != null)
endTransactionId = Long.valueOf(endId);
}
String order = "DESC";
if (params instanceof TradeHistoryParamsSorted) {
order = ((TradeHistoryParamsSorted) params).getOrder().equals(TradeHistoryParamsSorted.Order.desc) ? "DESC" : "ASC";
}
Long fromTimestamp = null;
Long toTimestamp = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
Date startTime = tradeHistoryParamsTimeSpan.getStartTime();
if (startTime != null)
fromTimestamp = DateUtils.toUnixTimeNullSafe(startTime);
Date endTime = tradeHistoryParamsTimeSpan.getEndTime();
if (endTime != null)
toTimestamp = DateUtils.toUnixTimeNullSafe(endTime);
}
BaseYoBitResponse response = tradeHistory(count, offset, market, fromTransactionId, endTransactionId, order, fromTimestamp, toTimestamp);
List<UserTrade> trades = new ArrayList<>();
if (response.returnData != null) {
for (Object key : response.returnData.keySet()) {
Map tradeData = (Map) response.returnData.get(key);
trades.add(YoBitAdapters.adaptUserTrade(key, tradeData));
}
}
return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class BTCMarketsAdaptersTest method shouldAdaptTradeHistoryResponse.
@Test
public void shouldAdaptTradeHistoryResponse() throws IOException {
final BTCMarketsTradeHistoryResponse response = parse(BTCMarketsTradeHistoryResponse.class, "v3");
final UserTrade userTrade = BTCMarketsAdapters.adaptTradeHistory(response);
assertThat(userTrade.getId()).isEqualTo("36014819");
assertThat(userTrade.getTimestamp().getTime()).isEqualTo(1561479439000L);
assertThat(userTrade.getPrice()).isEqualTo("0.67");
assertThat(userTrade.getOriginalAmount()).isEqualTo("1.50533262");
assertThat(userTrade.getType()).isEqualTo(Order.OrderType.ASK);
assertThat(userTrade.getFeeAmount()).isEqualTo("0.00857285");
assertThat(userTrade.getFeeCurrency()).isEqualTo(Currency.AUD);
assertThat(userTrade.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_AUD);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class BTCTradeAdapters method adaptTrades.
public static UserTrades adaptTrades(BTCTradeOrder[] btcTradeOrders, BTCTradeOrder[] btcTradeOrderDetails) {
List<UserTrade> trades = new ArrayList<>();
for (int i = 0; i < btcTradeOrders.length; i++) {
BTCTradeOrder order = btcTradeOrders[i];
CurrencyPair currencyPair = adaptCurrencyPair(order.getCoin());
if (currencyPair != null) {
BTCTradeOrder orderDetail = btcTradeOrderDetails[i];
for (org.knowm.xchange.btctrade.dto.trade.BTCTradeTrade trade : orderDetail.getTrades()) {
trades.add(adaptTrade(order, trade, currencyPair));
}
}
}
return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class CoinsuperAdapters method adaptTradeHistory.
/**
* Adapt the user's trades
*
* @param CoinsuperUserTransaction
* @return
*/
public static UserTrades adaptTradeHistory(CoinsuperResponse<List<OrderDetail>> OrderDetails) {
List<UserTrade> trades = new ArrayList<>();
long lastTradeId = 0;
for (OrderDetail orderDetail : OrderDetails.getData().getResult()) {
OrderType orderType = OrderType.BID;
if (orderDetail.getAction().equals("SELL")) {
orderType = OrderType.ASK;
}
UserTrade trade = new UserTrade.Builder().type(orderType).originalAmount(orderDetail.getAmount().abs()).currencyPair(new CurrencyPair(orderDetail.getSymbol())).price(orderDetail.getPriceLimit().abs()).timestamp(new Date()).id(Long.toString(orderDetail.getOrderNo())).orderId(Long.toString(orderDetail.getOrderNo())).feeAmount(BigDecimal.valueOf(orderDetail.getFee())).feeCurrency(Currency.getInstance(orderDetail.getSymbol().toUpperCase())).build();
lastTradeId = orderDetail.getOrderNo();
trades.add(trade);
}
return new UserTrades(trades, lastTradeId, TradeSortType.SortByID);
}
Aggregations