Search in sources :

Example 1 with ExmoUserTrades

use of org.knowm.xchange.exmo.dto.trade.ExmoUserTrades 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 2 with ExmoUserTrades

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

the class ExmoTradeService method getOrder.

@Override
public /**
 * Warning: this make multiple api requests (one per parameter) so may result in you exceeding
 * your api limits
 */
Collection<Order> getOrder(OrderQueryParams... orderQueryParams) throws IOException {
    List<Order> results = new ArrayList<>();
    for (OrderQueryParams orderQueryParam : orderQueryParams) {
        String orderId = orderQueryParam.getOrderId();
        Order.OrderType type = null;
        CurrencyPair currencyPair = null;
        String id = null;
        Date timestamp = null;
        BigDecimal totalValue = BigDecimal.ZERO;
        BigDecimal cumulativeAmount = BigDecimal.ZERO;
        BigDecimal fee = BigDecimal.ZERO;
        Order.OrderStatus status = Order.OrderStatus.UNKNOWN;
        ExmoUserTrades exmoUserTrades = userTrades(orderId);
        if (exmoUserTrades == null)
            continue;
        BigDecimal originalAmount = exmoUserTrades.getOriginalAmount();
        for (UserTrade userTrade : exmoUserTrades.getUserTrades()) {
            type = userTrade.getType();
            currencyPair = userTrade.getCurrencyPair();
            id = userTrade.getOrderId();
            if (timestamp == null)
                timestamp = userTrade.getTimestamp();
            if (timestamp.getTime() < userTrade.getTimestamp().getTime())
                timestamp = userTrade.getTimestamp();
            BigDecimal amountForFill = userTrade.getOriginalAmount();
            BigDecimal priceForFill = userTrade.getPrice();
            BigDecimal value = amountForFill.multiply(priceForFill);
            cumulativeAmount = cumulativeAmount.add(amountForFill);
            totalValue = totalValue.add(value);
        }
        BigDecimal averagePrice = totalValue.divide(cumulativeAmount, 8, RoundingMode.HALF_UP);
        Order order = new MarketOrder(type, originalAmount, currencyPair, id, timestamp, averagePrice, cumulativeAmount, fee, status);
        results.add(order);
    }
    return results;
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) ArrayList(java.util.ArrayList) ExmoUserTrades(org.knowm.xchange.exmo.dto.trade.ExmoUserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) BigDecimal(java.math.BigDecimal) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 UserTrade (org.knowm.xchange.dto.trade.UserTrade)2 ExmoUserTrades (org.knowm.xchange.exmo.dto.trade.ExmoUserTrades)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Order (org.knowm.xchange.dto.Order)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)1 StopOrder (org.knowm.xchange.dto.trade.StopOrder)1 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)1 OrderQueryParams (org.knowm.xchange.service.trade.params.orders.OrderQueryParams)1