Search in sources :

Example 11 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class ExmoTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    Integer limit = 10000;
    Long offset = 0L;
    List<CurrencyPair> currencyPairs = new ArrayList<>();
    if (params instanceof ExmoTradeHistoryParams) {
        ExmoTradeHistoryParams exmoTradeHistoryParams = (ExmoTradeHistoryParams) params;
        currencyPairs.addAll(exmoTradeHistoryParams.getCurrencyPairs());
    } else if (params instanceof TradeHistoryParamCurrencyPair) {
        TradeHistoryParamCurrencyPair tradeHistoryParamCurrencyPair = (TradeHistoryParamCurrencyPair) params;
        currencyPairs.add(tradeHistoryParamCurrencyPair.getCurrencyPair());
    }
    if (params instanceof TradeHistoryParamLimit) {
        limit = ((TradeHistoryParamLimit) params).getLimit();
    }
    if (params instanceof TradeHistoryParamOffset) {
        offset = ((TradeHistoryParamOffset) params).getOffset();
    }
    List<UserTrade> trades = trades(limit, offset, currencyPairs);
    return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : ExmoUserTrades(org.knowm.xchange.exmo.dto.trade.ExmoUserTrades) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) ArrayList(java.util.ArrayList) ExmoTradeHistoryParams(org.knowm.xchange.exmo.dto.trade.ExmoTradeHistoryParams) UserTrade(org.knowm.xchange.dto.trade.UserTrade) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 12 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class ExmoTradeServiceRaw method trades.

public List<UserTrade> trades(Integer limit, Long offset, Collection<CurrencyPair> currencyPairs) {
    List<String> markets = new ArrayList<>();
    for (CurrencyPair currencyPair : currencyPairs) {
        markets.add(ExmoAdapters.format(currencyPair));
    }
    Map<String, List<Map<String, String>>> map = exmo.userTrades(signatureCreator, apiKey, exchange.getNonceFactory(), join(markets, ","), offset, limit);
    List<UserTrade> trades = new ArrayList<>();
    for (String market : map.keySet()) {
        for (Map<String, String> tradeDatum : map.get(market)) {
            trades.add(ExmoAdapters.adaptTrade(tradeDatum, adaptMarket(market)));
        }
    }
    Collections.sort(trades, (o1, o2) -> o2.getTimestamp().compareTo(o1.getTimestamp()));
    return trades;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UserTrade(org.knowm.xchange.dto.trade.UserTrade) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 13 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class ExmoTradeServiceRaw method userTrades.

public ExmoUserTrades userTrades(String orderId) {
    Map<String, Object> map = exmo.orderTrades(signatureCreator, apiKey, exchange.getNonceFactory(), orderId);
    List<UserTrade> userTrades = new ArrayList<>();
    Boolean result = (Boolean) map.get("result");
    if (result != null && !result)
        return null;
    BigDecimal originalAmount = new BigDecimal(map.get("out_amount").toString());
    for (Map<String, Object> tradeDatum : (List<Map<String, Object>>) map.get("trades")) {
        CurrencyPair market = adaptMarket(tradeDatum.get("pair").toString());
        Map<String, String> bodge = new HashMap<>();
        for (String key : tradeDatum.keySet()) {
            bodge.put(key, tradeDatum.get(key).toString());
        }
        userTrades.add(ExmoAdapters.adaptTrade(bodge, market));
    }
    return new ExmoUserTrades(originalAmount, userTrades);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExmoUserTrades(org.knowm.xchange.exmo.dto.trade.ExmoUserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) ArrayList(java.util.ArrayList) List(java.util.List) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 14 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class LunoTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws ExchangeException, IOException {
    if (!(params instanceof TradeHistoryParamCurrencyPair)) {
        throw new ExchangeException("THe currency pair is mandatory in order to get user trades.");
    }
    CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
    Long since = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        since = ((TradeHistoryParamsTimeSpan) params).getStartTime().getTime();
    }
    Integer limit = null;
    if (params instanceof TradeHistoryParamLimit) {
        limit = ((TradeHistoryParamLimit) params).getLimit();
    }
    LunoUserTrades lunoTrades = lunoAPI.listTrades(LunoUtil.toLunoPair(currencyPair), since, limit);
    List<UserTrade> trades = new ArrayList<>();
    for (org.knowm.xchange.luno.dto.trade.LunoUserTrades.UserTrade t : lunoTrades.getTrades()) {
        final CurrencyPair pair = LunoUtil.fromLunoPair(t.pair);
        // currently there is no trade id!
        final String tradeId = null;
        final BigDecimal feeAmount;
        final Currency feeCurrency;
        if (t.feeBase.compareTo(BigDecimal.ZERO) > 0) {
            feeAmount = t.feeBase;
            feeCurrency = pair.base;
        } else {
            feeAmount = t.feeCounter;
            feeCurrency = pair.counter;
        }
        trades.add(new UserTrade.Builder().type(t.buy ? OrderType.BID : OrderType.ASK).originalAmount(t.volume).currencyPair(pair).price(t.price).timestamp(t.getTimestamp()).id(tradeId).orderId(t.orderId).feeAmount(feeAmount).feeCurrency(feeCurrency).build());
    }
    return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) LunoUserTrades(org.knowm.xchange.luno.dto.trade.LunoUserTrades) ArrayList(java.util.ArrayList) Exchange(org.knowm.xchange.Exchange) UserTrade(org.knowm.xchange.dto.trade.UserTrade) BigDecimal(java.math.BigDecimal) UserTrades(org.knowm.xchange.dto.trade.UserTrades) LunoUserTrades(org.knowm.xchange.luno.dto.trade.LunoUserTrades) Currency(org.knowm.xchange.currency.Currency) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 15 with UserTrade

use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.

the class TheRockAdapters method adaptUserTrades.

public static UserTrades adaptUserTrades(TheRockUserTrades trades, CurrencyPair currencyPair) {
    List<UserTrade> tradesList = new ArrayList<>(trades.getCount());
    long lastTradeId = 0;
    for (int i = 0; i < trades.getCount(); i++) {
        TheRockUserTrade trade = trades.getTrades()[i];
        long tradeId = trade.getId();
        if (tradeId > lastTradeId)
            lastTradeId = tradeId;
        tradesList.add(adaptUserTrade(trade, currencyPair));
    }
    return new UserTrades(tradesList, lastTradeId, Trades.TradeSortType.SortByID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) TheRockUserTrades(org.knowm.xchange.therock.dto.trade.TheRockUserTrades) TheRockUserTrade(org.knowm.xchange.therock.dto.trade.TheRockUserTrade) ArrayList(java.util.ArrayList) UserTrade(org.knowm.xchange.dto.trade.UserTrade) TheRockUserTrade(org.knowm.xchange.therock.dto.trade.TheRockUserTrade)

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