Search in sources :

Example 1 with MercadoBitcoinUserOrders

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

the class MercadoBitcoinTradeService method getTradeHistory.

/**
 * @param params Required parameter types: {@link TradeHistoryParamCurrencyPair}. Supported types:
 *     {@link TradeHistoryParamsIdSpan}, {@link TradeHistoryParamsTimeSpan}.
 */
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    CurrencyPair pair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
    String fromId = null;
    String toId = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        TradeHistoryParamsIdSpan paramsIdSpan = (TradeHistoryParamsIdSpan) params;
        fromId = paramsIdSpan.getStartId();
        toId = paramsIdSpan.getEndId();
    }
    Long fromDate = null;
    Long toDate = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        TradeHistoryParamsTimeSpan paramsTimeSpan = (TradeHistoryParamsTimeSpan) params;
        fromDate = toUnixTimeNullSafe(paramsTimeSpan.getStartTime());
        toDate = toUnixTimeNullSafe(paramsTimeSpan.getEndTime());
    }
    MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> orders = getMercadoBitcoinUserOrders(MercadoBitcoinAdapters.adaptCurrencyPair(pair), null, /* all */
    null, fromId, toId, fromDate, toDate);
    return MercadoBitcoinAdapters.toUserTrades(pair, orders);
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) MercadoBitcoinUserOrders(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 2 with MercadoBitcoinUserOrders

use of org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders 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 3 with MercadoBitcoinUserOrders

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

the class MercadoBitcoinAdapterTest method testOrdersAdapter.

@Test
public void testOrdersAdapter() throws IOException {
    // Read in the JSON from the example resources
    InputStream is = MercadoBitcoinAdapterTest.class.getResourceAsStream("/org/knowm/xchange/mercadobitcoin/dto/trade/example-userorders.json");
    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> apiResult = mapper.readValue(is, new TypeReference<MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders>>() {
    });
    List<LimitOrder> orders = MercadoBitcoinAdapters.adaptOrders(new CurrencyPair(Currency.LTC, Currency.BRL), apiResult);
    Map<String, LimitOrder> orderById = new HashMap<>();
    for (LimitOrder order : orders) {
        orderById.put(order.getId(), order);
    }
    assertThat(orderById.get("1212").getType()).isEqualTo(OrderType.ASK);
    assertThat(orderById.get("1212").getTimestamp()).isEqualTo(new Date(1378929161000L));
    assertThat(orderById.get("1212").getLimitPrice()).isEqualTo(new BigDecimal("6.00000"));
    assertThat(orderById.get("1212").getOriginalAmount()).isEqualTo(new BigDecimal("165.47309607"));
    assertThat(orderById.get("1212").getCurrencyPair()).isEqualTo(new CurrencyPair(Currency.LTC, Currency.BRL));
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) MercadoBitcoinUserOrders(org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders) Date(java.util.Date) BigDecimal(java.math.BigDecimal) MercadoBitcoinBaseTradeApiResult(org.knowm.xchange.mercadobitcoin.dto.MercadoBitcoinBaseTradeApiResult) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 4 with MercadoBitcoinUserOrders

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

MercadoBitcoinUserOrders (org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrders)4 Map (java.util.Map)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 MercadoBitcoinUserOrdersEntry (org.knowm.xchange.mercadobitcoin.dto.trade.MercadoBitcoinUserOrdersEntry)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 MercadoBitcoinBaseTradeApiResult (org.knowm.xchange.mercadobitcoin.dto.MercadoBitcoinBaseTradeApiResult)1 DefaultTradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair)1 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)1 TradeHistoryParamsIdSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan)1 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)1