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);
}
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;
}
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));
}
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());
}
}
Aggregations