Search in sources :

Example 6 with UserTrade

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) Currency(org.knowm.xchange.currency.Currency) OkexCurrency(org.knowm.xchange.okex.v5.dto.marketdata.OkexCurrency) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 7 with UserTrade

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);
}
Also used : TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) ArrayList(java.util.ArrayList) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) Map(java.util.Map) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 8 with UserTrade

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);
}
Also used : BTCMarketsTradeHistoryResponse(org.knowm.xchange.btcmarkets.dto.v3.trade.BTCMarketsTradeHistoryResponse) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Test(org.junit.Test)

Example 9 with UserTrade

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) BTCTradeOrder(org.knowm.xchange.btctrade.dto.trade.BTCTradeOrder) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 10 with UserTrade

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);
}
Also used : OrderDetail(org.knowm.xchange.coinsuper.dto.trade.OrderDetail) UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

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