Search in sources :

Example 1 with OperationEntry

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

the class MercadoBitcoinAdapters method toUserTrades.

public static UserTrades toUserTrades(CurrencyPair pair, MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> orders) {
    List<UserTrade> result = new LinkedList<>();
    for (Map.Entry<String, MercadoBitcoinUserOrdersEntry> e : orders.getTheReturn().entrySet()) {
        String orderId = e.getKey();
        MercadoBitcoinUserOrdersEntry order = e.getValue();
        OrderType type = toOrderType(order.getType());
        for (Map.Entry<String, OperationEntry> f : order.getOperations().entrySet()) {
            String txId = f.getKey();
            OperationEntry op = f.getValue();
            result.add(new UserTrade.Builder().currencyPair(pair).id(txId).orderId(orderId).price(op.getPrice()).timestamp(fromUnixTime(op.getCreated())).originalAmount(op.getVolume()).type(type).build());
        }
    }
    // TODO verify sortType
    return new UserTrades(result, Trades.TradeSortType.SortByID);
}
Also used : UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderType(org.knowm.xchange.dto.Order.OrderType) OperationEntry(org.knowm.xchange.mercadobitcoin.dto.trade.OperationEntry) MercadoBitcoinUserOrdersEntry(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Map(java.util.Map) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 OrderType (org.knowm.xchange.dto.Order.OrderType)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1 MercadoBitcoinUserOrdersEntry (org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry)1 OperationEntry (org.knowm.xchange.mercadobitcoin.dto.trade.OperationEntry)1