use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class OkexTradeService method getOrder.
public Order getOrder(OrderQueryParams orderQueryParams) throws IOException {
Order result = null;
if (orderQueryParams instanceof OrderQueryParamInstrument) {
Instrument instrument = ((OrderQueryParamInstrument) orderQueryParams).getInstrument();
String orderId = orderQueryParams.getOrderId();
List<OkexOrderDetails> orderResults = getOkexOrder(OkexAdapters.adaptInstrumentId(instrument), orderId).getData();
if (!orderResults.isEmpty()) {
result = OkexAdapters.adaptOrder(orderResults.get(0));
}
} else {
throw new IOException("OrderQueryParams must implement OrderQueryParamInstrument interface.");
}
return result;
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class BankeraTradeService method getOrder.
@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
List<Order> orders = new ArrayList<>();
for (String orderId : orderIds) {
BankeraOrder order = getUserOrder(orderId);
orders.add(BankeraAdapters.adaptOrder(order));
}
return orders;
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class TradeServiceIntegrationTransactionsCreateOrder method getOrder.
// getOrder(String... orderIds)
// trades
private static void getOrder() throws IOException {
String apiKey = "00af0b38-11fb-4aab-bf19-45edd44a4adc";
String secretKey = "fa3f0510-155f-4567-a3b3-3f386080efa3";
Exchange coinsuper = ExchangeFactory.INSTANCE.createExchange(CoinsuperExchange.class);
ExchangeSpecification exchangeSpecification = coinsuper.getExchangeSpecification();
exchangeSpecification.setApiKey(apiKey);
exchangeSpecification.setSecretKey(secretKey);
coinsuper.applySpecification(exchangeSpecification);
TradeService tradeService = coinsuper.getTradeService();
try {
String orderNoList = "1608661340536594433,1608661662038384641";
Collection<Order> openOrders = tradeService.getOrder(orderNoList);
System.out.printf("Open Orders for %s: %s%n", orderNoList, openOrders);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class ExmoTradeServiceRaw method openOrders.
public List<LimitOrder> openOrders() {
Map<String, List<Map<String, String>>> map = exmo.userOpenOrders(signatureCreator, apiKey, exchange.getNonceFactory());
List<LimitOrder> openOrders = new ArrayList<>();
for (String market : map.keySet()) {
CurrencyPair currencyPair = adaptMarket(market);
for (Map<String, String> order : map.get(market)) {
Order.OrderType type = ExmoAdapters.adaptOrderType(order);
BigDecimal amount = new BigDecimal(order.get("quantity"));
String id = order.get("order_id");
BigDecimal price = new BigDecimal(order.get("price"));
Date created = DateUtils.fromUnixTime(Long.valueOf(order.get("created")));
openOrders.add(new LimitOrder(type, amount, currencyPair, id, created, price));
}
}
return openOrders;
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class OkCoinTradeService method cancelUpToThreeOrders.
/**
* Cancel a batch of up to three orders (maximum allowed by the exchange).
*
* @param limitOrders orders to cancel
* @return (id, result) mappings
*/
public Map<LimitOrder, Boolean> cancelUpToThreeOrders(List<LimitOrder> limitOrders) throws IOException {
Set<Long> ordersToCancel = limitOrders.stream().map(Order::getId).map(Long::parseLong).collect(Collectors.toSet());
if (ordersToCancel.isEmpty() || ordersToCancel.size() > 3) {
throw new UnsupportedOperationException("Can only batch cancel 1 to 3 orders. " + ordersToCancel.size() + " orders provided.");
}
CurrencyPair currencyPair = limitOrders.get(0).getCurrencyPair();
boolean valid = limitOrders.stream().allMatch(order -> order.getCurrencyPair().equals(currencyPair));
if (!valid) {
throw new UnsupportedOperationException("Can only batch cancel orders with the same currency pair.");
}
OkCoinBatchTradeResult okCoinBatchTradeResult = cancelUpToThreeOrders(ordersToCancel, OkCoinAdapters.adaptSymbol(currencyPair));
Map<String, Boolean> requestResults = new HashMap<>(ordersToCancel.size());
if (okCoinBatchTradeResult.getSuccess() != null) {
Arrays.stream(okCoinBatchTradeResult.getSuccess().split(BATCH_DELIMITER)).forEach(id -> requestResults.put(id, Boolean.TRUE));
}
if (okCoinBatchTradeResult.getError() != null) {
Arrays.stream(okCoinBatchTradeResult.getError().split(BATCH_DELIMITER)).forEach(id -> requestResults.put(id, Boolean.FALSE));
}
Map<LimitOrder, Boolean> results = new HashMap<>(limitOrders.size());
requestResults.forEach((id, result) -> limitOrders.stream().filter(order -> order.getId().equals(id)).findAny().ifPresent(limitOrder -> results.put(limitOrder, requestResults.get(id))));
return results;
}
Aggregations