use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class GateioAdapterTest method testAdaptOpenOrders.
@Test
public void testAdaptOpenOrders() throws IOException {
// Read in the JSON from the example resources
InputStream is = GateioAdapterTest.class.getResourceAsStream("/org/knowm/xchange/gateio/dto/trade/example-order-list-data.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
GateioOpenOrders openOrders = mapper.readValue(is, GateioOpenOrders.class);
OpenOrders adaptedOpenOrders = GateioAdapters.adaptOpenOrders(openOrders, currencyPairs);
List<LimitOrder> adaptedOrderList = adaptedOpenOrders.getOpenOrders();
assertThat(adaptedOrderList).hasSize(2);
LimitOrder adaptedOrder = adaptedOrderList.get(0);
assertThat(adaptedOrder.getType()).isEqualTo(OrderType.ASK);
assertThat(adaptedOrder.getOriginalAmount()).isEqualTo(new BigDecimal("100000"));
assertThat(adaptedOrder.getCurrencyPair()).isEqualTo(CurrencyPair.ETH_BTC);
assertThat(adaptedOrder.getId()).isEqualTo("0");
assertThat(adaptedOrder.getLimitPrice()).isEqualTo(new BigDecimal("0.0693"));
}
use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class GateioAdapterTest method testAdaptOrderBook.
@Test
public void testAdaptOrderBook() throws IOException {
// Read in the JSON from the example resources
InputStream is = GateioAdapterTest.class.getResourceAsStream("/org/knowm/xchange/gateio/dto/marketdata/example-depth-data.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
GateioDepth depth = mapper.readValue(is, GateioDepth.class);
OrderBook orderBook = GateioAdapters.adaptOrderBook(depth, CurrencyPair.LTC_BTC);
List<LimitOrder> asks = orderBook.getAsks();
assertThat(asks).hasSize(3);
LimitOrder ask = asks.get(0);
assertThat(ask.getLimitPrice()).isEqualTo("0.1785");
assertThat(ask.getOriginalAmount()).isEqualTo("1324.111");
assertThat(ask.getType()).isEqualTo(OrderType.ASK);
assertThat(ask.getTimestamp()).isNull();
assertThat(ask.getCurrencyPair()).isEqualTo(CurrencyPair.LTC_BTC);
}
use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class GeminiAdapters method adaptOrders.
public static OpenOrders adaptOrders(GeminiOrderStatusResponse[] activeOrders, CurrencyPair currencyPair) {
List<LimitOrder> limitOrders = new ArrayList<>(activeOrders.length);
for (GeminiOrderStatusResponse order : activeOrders) {
CurrencyPair currentCurrencyPair = adaptCurrencyPair(order.getSymbol());
if (currencyPair != null && !currentCurrencyPair.equals(currencyPair)) {
continue;
}
OrderType orderType = order.getSide().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
Date timestamp = convertBigDecimalTimestampToDate(new BigDecimal(order.getTimestamp()));
OrderStatus status = OrderStatus.NEW;
if (order.isCancelled()) {
status = OrderStatus.CANCELED;
} else if (order.getExecutedAmount().signum() > 0 && order.getExecutedAmount().compareTo(order.getOriginalAmount()) < 0) {
status = OrderStatus.PARTIALLY_FILLED;
} else if (order.getExecutedAmount().compareTo(order.getOriginalAmount()) == 0) {
status = OrderStatus.FILLED;
}
LimitOrder limitOrder = new LimitOrder(orderType, order.getOriginalAmount(), currentCurrencyPair, String.valueOf(order.getId()), timestamp, order.getPrice(), order.getAvgExecutionPrice(), order.getExecutedAmount(), null, status);
limitOrders.add(limitOrder);
}
return new OpenOrders(limitOrders);
}
use of org.knowm.xchange.dto.trade.LimitOrder in project XChange by knowm.
the class TradeServiceIntegration method placeLimitOrder.
private static void placeLimitOrder() throws IOException {
Exchange exx = getExchange();
TradeService tradeService = exx.getTradeService();
try {
// place a limit order
LimitOrder limitOrder = new LimitOrder((OrderType.BID), new BigDecimal("1.0"), CurrencyPair.ETH_BTC, null, null, new BigDecimal("0.00050"));
String limitOrderReturnValue = tradeService.placeLimitOrder(limitOrder);
System.out.println("Order Id: " + limitOrderReturnValue);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.knowm.xchange.dto.trade.LimitOrder 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);
}
}
Aggregations