use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class CexIOAdapters method adaptOpenOrders.
public static OpenOrders adaptOpenOrders(List<CexIOOrder> cexIOOrderList) {
List<LimitOrder> limitOrders = new ArrayList<>();
for (CexIOOrder cexIOOrder : cexIOOrderList) {
OrderType orderType = cexIOOrder.getType() == CexIOOrder.Type.buy ? OrderType.BID : OrderType.ASK;
String id = Long.toString(cexIOOrder.getId());
limitOrders.add(new LimitOrder(orderType, cexIOOrder.getAmount(), cexIOOrder.getAmount().subtract(cexIOOrder.getPending()), new CurrencyPair(cexIOOrder.getSymbol1(), cexIOOrder.getSymbol2()), id, DateUtils.fromMillisUtc(cexIOOrder.getTime()), cexIOOrder.getPrice()));
}
return new OpenOrders(limitOrders);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class GateioTradeDemo method generic.
private static void generic(TradeService tradeService) throws IOException, InterruptedException {
LimitOrder limitOrder = new LimitOrder(OrderType.ASK, new BigDecimal("0.384"), CurrencyPair.LTC_BTC, "", null, new BigDecimal("0.0265"));
String orderId = tradeService.placeLimitOrder(limitOrder);
System.out.println(// Returned order id is currently broken for Gateio, rely on open orders instead//
orderId);
// for demo :(
// wait for Gateio's back-end to propagate the order
Thread.sleep(2000);
OpenOrders openOrders = tradeService.getOpenOrders();
System.out.println(openOrders);
List<LimitOrder> openOrdersList = openOrders.getOpenOrders();
if (!openOrdersList.isEmpty()) {
String existingOrderId = openOrdersList.get(0).getId();
boolean isCancelled = tradeService.cancelOrder(existingOrderId);
System.out.println(isCancelled);
}
// wait for Gateio's back-end to propagate the cancelled order
Thread.sleep(2000);
openOrders = tradeService.getOpenOrders();
System.out.println(openOrders);
Thread.sleep(2000);
Trades tradeHistory = tradeService.getTradeHistory(new DefaultTradeHistoryParamCurrencyPair(CurrencyPair.LTC_BTC));
System.out.println(tradeHistory);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class CoinbeneTradeDemo method generic.
public static void generic(Exchange exchange) throws IOException {
CurrencyPair pair = CurrencyPair.BTC_USDT;
TradeService tradeService = exchange.getTradeService();
// Get open orders
OpenOrders orders = tradeService.getOpenOrders(new DefaultOpenOrdersParamCurrencyPair(pair));
LimitOrder order = orders.getOpenOrders().stream().collect(StreamUtils.singletonCollector());
if (order != null) {
System.out.println(order);
}
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class TradeServiceIntegration method testCgetOpenOrdersByMarketTest.
@Test
public void testCgetOpenOrdersByMarketTest() throws Exception {
DefaultOpenOrdersParamCurrencyPair currencyPair = new DefaultOpenOrdersParamCurrencyPair();
currencyPair.setCurrencyPair(CurrencyPair.ETH_BTC);
OpenOrders openOrders = tradeService.getOpenOrders(currencyPair);
logger.info("Response: {}", openOrders);
}
use of org.knowm.xchange.dto.trade.OpenOrders in project XChange by knowm.
the class BTCMarketsAdaptersTest method shouldAdaptOrders.
@Test
public void shouldAdaptOrders() throws IOException {
final BTCMarketsOrders response = parse(BTCMarketsOrders.class);
final OpenOrders openOrders = BTCMarketsAdapters.adaptOpenOrders(response);
assertThat(openOrders.getOpenOrders()).hasSize(2);
assertThat(openOrders.getOpenOrders().get(1).getId()).isEqualTo("4345675");
assertThat(openOrders.getOpenOrders().get(1).getCurrencyPair()).isEqualTo(CurrencyPair.BTC_AUD);
assertThat(openOrders.getOpenOrders().get(1).getType()).isEqualTo(Order.OrderType.ASK);
assertThat(openOrders.getOpenOrders().get(1).getTimestamp().getTime()).isEqualTo(1378636912705L);
assertThat(openOrders.getOpenOrders().get(1).getLimitPrice()).isEqualTo("130.00000000");
assertThat(openOrders.getOpenOrders().get(1).getOriginalAmount()).isEqualTo("0.10000000");
assertThat(openOrders.getOpenOrders().get(1).getCumulativeAmount()).isEqualTo(BigDecimal.valueOf(0.1));
assertThat(openOrders.getOpenOrders().get(1).getAveragePrice()).isEqualTo(BigDecimal.valueOf(130.0));
assertThat(openOrders.getOpenOrders().get(1).getFee()).isEqualTo(BigDecimal.valueOf(0.001));
assertThat(openOrders.getOpenOrders().get(0).getUserReference()).isEqualTo("orderOne");
assertThat(openOrders.getOpenOrders().get(1).getUserReference()).isNull();
}
Aggregations