use of org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder in project XChange by knowm.
the class LivecoinTradeService method getOpenOrders.
@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
try {
CurrencyPair pair = null;
if (params instanceof OpenOrdersParamCurrencyPair) {
pair = ((OpenOrdersParamCurrencyPair) params).getCurrencyPair();
}
LivecoinPaginatedResponse<LivecoinUserOrder> response = clientOrders(pair, "OPEN", null, null, null, null);
if (response.getData() == null) {
return new OpenOrders(Collections.emptyList());
}
return new OpenOrders(response.getData().stream().filter(this::isOrderOpen).map(LivecoinAdapters::adaptUserOrder).filter(order -> order instanceof LimitOrder).map(order -> (LimitOrder) order).collect(Collectors.toList()));
} catch (LivecoinException e) {
throw LivecoinErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder in project XChange by knowm.
the class LivecoinAdapters method adaptUserOrder.
public static Order adaptUserOrder(LivecoinUserOrder order) {
OrderType type;
boolean limit;
switch(order.getType()) {
case "MARKET_SELL":
type = OrderType.ASK;
limit = false;
break;
case "LIMIT_SELL":
type = OrderType.ASK;
limit = true;
break;
case "LIMIT_BUY":
type = OrderType.BID;
limit = true;
break;
case "MARKET_BUY":
type = OrderType.BID;
limit = false;
break;
default:
throw new ExchangeException("Order id=" + order.getId() + " has unknown type " + order.getType());
}
CurrencyPair pair = new CurrencyPair(order.getCurrencyPair());
Order.OrderStatus status;
if (order.getRemainingQuantity().compareTo(BigDecimal.ZERO) == 0) {
status = Order.OrderStatus.FILLED;
} else {
status = order.getRemainingQuantity().compareTo(order.getQuantity()) < 0 ? Order.OrderStatus.PARTIALLY_FILLED : Order.OrderStatus.PENDING_NEW;
}
Order.Builder builder;
if (limit) {
builder = new LimitOrder.Builder(type, pair).limitPrice(order.getPrice()).remainingAmount(order.getRemainingQuantity());
} else {
builder = new MarketOrder.Builder(type, pair).averagePrice(order.getPrice());
}
return builder.originalAmount(order.getQuantity()).id(order.getId().toString()).timestamp(DateUtils.fromUnixTime(order.getIssueTime())).orderStatus(status).build();
}
use of org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder in project XChange by knowm.
the class LivecoinTradeService method getOrder.
@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
try {
if (params == null || params.length == 0) {
LivecoinPaginatedResponse<LivecoinUserOrder> response = clientOrders(null, null, null, null, null, null);
return LivecoinAdapters.adaptUserOrders(response.getData());
}
List<Order> result = new ArrayList<>();
for (OrderQueryParams param : params) {
CurrencyPair pair = null;
if (param instanceof OrderQueryParamCurrencyPair) {
pair = ((OrderQueryParamCurrencyPair) param).getCurrencyPair();
}
LivecoinPaginatedResponse<LivecoinUserOrder> response = clientOrders(pair, null, null, null, null, null);
if (param.getOrderId() == null) {
result.addAll(LivecoinAdapters.adaptUserOrders(response.getData()));
} else {
response.getData().stream().filter(order -> order.getId().toString().equals(param.getOrderId())).findAny().map(LivecoinAdapters::adaptUserOrder).ifPresent(result::add);
}
}
return result;
} catch (LivecoinException e) {
throw LivecoinErrorAdapter.adapt(e);
}
}
Aggregations