Search in sources :

Example 26 with UserTrade

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

Example 27 with UserTrade

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

Example 28 with UserTrade

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal)

Example 29 with UserTrade

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);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BitfinexTradeResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 30 with UserTrade

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;
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Order(org.knowm.xchange.dto.Order) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Cryptopia(org.knowm.xchange.cryptopia.Cryptopia) Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) 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