Search in sources :

Example 1 with MercadoBitcoinUserOrdersEntry

use of org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry 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)

Example 2 with MercadoBitcoinUserOrdersEntry

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

the class MercadoBitcoinAdapters method processOrderEntry.

private static LimitOrder processOrderEntry(Map.Entry<String, MercadoBitcoinUserOrdersEntry> entry, CurrencyPair currencyPair) {
    String id = entry.getKey();
    MercadoBitcoinUserOrdersEntry userOrdersEntry = entry.getValue();
    String type = userOrdersEntry.getType();
    OrderType orderType = toOrderType(type);
    BigDecimal price = userOrdersEntry.getPrice();
    BigDecimal volume = userOrdersEntry.getVolume();
    long time = userOrdersEntry.getCreated() * 1000L;
    return new LimitOrder(orderType, volume, currencyPair, id, new Date(time), price);
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) MercadoBitcoinUserOrdersEntry(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 3 with MercadoBitcoinUserOrdersEntry

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

the class MercadoBitcoinAdapters method adaptOrders.

public static List<LimitOrder> adaptOrders(CurrencyPair currencyPair, MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> input) {
    List<LimitOrder> limitOrders = new ArrayList<>();
    MercadoBitcoinUserOrders orders = input.getTheReturn();
    for (Map.Entry<String, MercadoBitcoinUserOrdersEntry> entry : orders.entrySet()) {
        limitOrders.add(processOrderEntry(entry, currencyPair));
    }
    return limitOrders;
}
Also used : ArrayList(java.util.ArrayList) MercadoBitcoinUserOrdersEntry(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry) MercadoBitcoinUserOrders(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Map(java.util.Map)

Example 4 with MercadoBitcoinUserOrdersEntry

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

the class MercadoBitcoinTradeDemo method printRawOpenOrders.

private static void printRawOpenOrders(MercadoBitcoinTradeServiceRaw tradeService) throws IOException, InterruptedException {
    MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> openOrdersResult = tradeService.getMercadoBitcoinUserOrders("btc_brl", null, "active", null, null, null, null);
    MercadoBitcoinUserOrders openOrders = openOrdersResult.getTheReturn();
    System.out.println("Open Orders for BTC: " + openOrders.size());
    for (Map.Entry<String, MercadoBitcoinUserOrdersEntry> order : openOrders.entrySet()) {
        System.out.println(order.toString());
    }
    openOrdersResult = tradeService.getMercadoBitcoinUserOrders("ltc_brl", null, "active", null, null, null, null);
    openOrders = openOrdersResult.getTheReturn();
    System.out.println("Open Orders for LTC: " + openOrders.size());
    for (Map.Entry<String, MercadoBitcoinUserOrdersEntry> order : openOrders.entrySet()) {
        System.out.println(order.toString());
    }
}
Also used : MercadoBitcoinUserOrdersEntry(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry) MercadoBitcoinUserOrders(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders) Map(java.util.Map)

Aggregations

MercadoBitcoinUserOrdersEntry (org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry)4 Map (java.util.Map)3 OrderType (org.knowm.xchange.dto.Order.OrderType)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 MercadoBitcoinUserOrders (org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1 OperationEntry (org.knowm.xchange.mercadobitcoin.dto.trade.OperationEntry)1