use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class BitstampTradeService method getOpenOrders.
@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws ExchangeException, IOException {
BitstampOrder[] openOrders = getBitstampOpenOrders();
List<LimitOrder> limitOrders = new ArrayList<>(openOrders.length);
for (BitstampOrder bitstampOrder : openOrders) {
OrderType orderType = bitstampOrder.getType() == 0 ? OrderType.BID : OrderType.ASK;
String id = Long.toString(bitstampOrder.getId());
BigDecimal price = bitstampOrder.getPrice();
limitOrders.add(new LimitOrder(orderType, bitstampOrder.getAmount(), new BitstampV2.Pair(bitstampOrder.getCurrencyPair()).pair, id, bitstampOrder.getDatetime(), price, // avgPrice
null, // cumAmount
null, // fee
null, Order.OrderStatus.NEW));
}
return new OpenOrders(limitOrders);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class CoingiAdapters method adaptOpenOrders.
public static OpenOrders adaptOpenOrders(CoingiOrdersList orders) {
List<LimitOrder> list = new ArrayList<>();
for (CoingiOrder order : orders) {
LimitOrder limitOrder = new LimitOrder(order.getType() == 0 ? OrderType.BID : OrderType.ASK, order.getOriginalBaseAmount(), adaptCurrency(order.getCurrencyPair()), order.getId(), new Date(order.getTimestamp()), order.getPrice());
limitOrder.setOrderStatus(adaptOrderStatus(order.getStatus()));
list.add(limitOrder);
}
return new OpenOrders(list);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class CoinfloorCancelOrderIntegration method cancelOpenOrdersTest.
@Test
public void cancelOpenOrdersTest() throws IOException {
final ExchangeSpecification specification = new ExchangeSpecification(CoinfloorExchange.class);
String username = System.getProperty("xchange.coinfloor.username");
String password = System.getProperty("xchange.coinfloor.password");
if (username == null || password == null) {
return;
}
specification.setUserName(username);
specification.setPassword(password);
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
TradeService service = exchange.getTradeService();
// fetch open orders
CoinfloorOpenOrdersParams params = (CoinfloorOpenOrdersParams) service.createOpenOrdersParams();
OpenOrders openOrders = service.getOpenOrders(params);
// cancel one order
if (openOrders.getOpenOrders().size() > 0) {
LimitOrder order = openOrders.getOpenOrders().iterator().next();
boolean success = service.cancelOrder(order.getId());
logger.info("cancel of order={} success={}", order, success);
}
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class KucoinTradeRawDemo method genericStopLimitOrder.
private static void genericStopLimitOrder(TradeService tradeService) throws Exception {
System.out.println("GENERIC STOP LIMIT ORDER...\n");
StopOrder stopOrder = new StopOrder.Builder(ORDER_TYPE, PAIR).limitPrice(STOP_LIMIT).stopPrice(STOP_PRICE).originalAmount(AMOUNT).build();
String uuid = tradeService.placeStopOrder(stopOrder);
System.out.println("Stop order successfully placed. ID=" + uuid);
// wait for order to propagate
Thread.sleep(3000);
OpenOrdersParamCurrencyPair orderParams = (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
orderParams.setCurrencyPair(PAIR);
OpenOrders openOrders = tradeService.getOpenOrders(orderParams);
Optional<? extends Order> found = openOrders.getHiddenOrders().stream().filter(o -> o.getId().equals(uuid)).findFirst();
if (!found.isPresent()) {
throw new AssertionError("Order not found on book");
}
if (!(found.get() instanceof StopOrder)) {
throw new AssertionError("Stop order not returned");
}
StopOrder returnedStopOrder = (StopOrder) found.get();
if (returnedStopOrder.getLimitPrice().compareTo(STOP_LIMIT) != 0) {
throw new AssertionError("Limit price mismatch: " + returnedStopOrder.getLimitPrice());
}
if (returnedStopOrder.getStopPrice().compareTo(STOP_PRICE) != 0) {
throw new AssertionError("Stop price mismatch: " + returnedStopOrder.getStopPrice());
}
System.out.println("Attempting to cancel order " + uuid);
boolean cancelled = tradeService.cancelOrder(uuid);
if (cancelled) {
System.out.println("Order successfully canceled.");
} else {
System.out.println("Order not successfully canceled.");
}
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class MercadoBitcoinTradeDemo method printOpenOrders.
private static void printOpenOrders(TradeService tradeService) throws IOException, InterruptedException {
OpenOrders openOrders = tradeService.getOpenOrders();
System.out.println("Open Orders: " + openOrders.toString());
}
Aggregations