use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class GeminiAdaptersTest method testAdaptLimitOrderUntouched.
@Test
public void testAdaptLimitOrderUntouched() throws IOException {
// Read in the JSON from the example resources
InputStream is = GeminiAdaptersTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/order/limit-order-untouched.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
GeminiOrderStatusResponse geminiOrderStatusResponse = mapper.readValue(is, GeminiOrderStatusResponse.class);
Order order = GeminiAdapters.adaptOrder(geminiOrderStatusResponse);
assertThat(order.getId()).isEqualTo("44375901");
assertThat(order.getAveragePrice()).isEqualTo(new BigDecimal("0.00"));
assertThat(order.getCumulativeAmount()).isEqualTo(new BigDecimal("0"));
assertThat(order.getCurrencyPair()).isEqualTo(CurrencyPair.BTC_USD);
assertThat(order.getStatus()).isEqualTo(Order.OrderStatus.OPEN);
assertThat(LimitOrder.class.isAssignableFrom(order.getClass()));
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class IndependentReserveTradeService method getOrder.
@Override
public Collection<Order> getOrder(OrderQueryParams... orderQueryParams) throws IOException {
List<Order> res = new ArrayList<>();
for (OrderQueryParams orderQueryParam : Arrays.asList(orderQueryParams)) {
IndependentReserveOrderDetailsResponse orderDetailsResponse = getOrderDetails(orderQueryParam.getOrderId());
res.add(IndependentReserveAdapters.adaptOrderDetails(orderDetailsResponse));
}
return res;
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class LatokenTradeService method getOrder.
@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
try {
Collection<Order> orders = new ArrayList<>();
// pair/status (via LatokenQueryOrderParams)
for (OrderQueryParams param : params) {
if (param instanceof OrderQueryParamCurrencyPair) {
OrderQueryParamCurrencyPair orderQueryParamCurrencyPair = (OrderQueryParamCurrencyPair) param;
CurrencyPair pair = orderQueryParamCurrencyPair.getCurrencyPair();
if (pair == null) {
throw new ExchangeException("CurrencyPair must be provided to query an order.");
}
LatokenOrderStatus status = LatokenOrderStatus.active;
Integer limit = null;
if (param instanceof LatokenQueryOrderParams) {
LatokenQueryOrderParams latokenParam = (LatokenQueryOrderParams) param;
status = latokenParam.getStatus();
limit = latokenParam.getLimit();
}
List<LatokenOrder> latokenOrders = getLatokenOrders(pair, status, limit);
latokenOrders.forEach(latokenOrder -> orders.add(LatokenAdapters.adaptOrder(this.exchange, latokenOrder)));
} else {
if (param.getOrderId() == null) {
throw new ExchangeException("OrderId must be provided to query an order.");
}
LatokenOrder latokenOrder = getLatokenOrder(param.getOrderId());
orders.add(LatokenAdapters.adaptOrder(this.exchange, latokenOrder));
}
}
return orders;
} catch (LatokenException e) {
throw LatokenErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class PaymiumTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
Long offset = null;
Integer limit = null;
if (params instanceof TradeHistoryParamOffset) {
final TradeHistoryParamOffset historyParamOffset = (TradeHistoryParamOffset) params;
offset = historyParamOffset.getOffset();
}
if (params instanceof TradeHistoryParamLimit) {
final TradeHistoryParamLimit historyParamLimit = (TradeHistoryParamLimit) params;
limit = historyParamLimit.getLimit();
}
List<UserTrade> userTrades = new ArrayList();
List<PaymiumOrder> orders = getPaymiumOrders(offset, limit);
for (PaymiumOrder order : orders) {
Order.OrderType orderType = null;
Currency currencyFee = null;
BigDecimal fee = null;
switch(order.getDirection()) {
case "buy":
orderType = Order.OrderType.ASK;
currencyFee = Currency.BTC;
fee = order.getBtcFee();
break;
case "sell":
orderType = Order.OrderType.BID;
currencyFee = Currency.EUR;
fee = order.getCurrencyFee();
break;
}
UserTrade userTrade = new UserTrade.Builder().type(orderType).originalAmount(order.getTradedCurrency()).currencyPair(CurrencyPair.BTC_EUR).price(order.getPrice()).id(order.getUuid()).orderId(order.getUuid()).feeAmount(fee).feeCurrency(currencyFee).build();
userTrades.add(userTrade);
}
return new UserTrades(userTrades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.Order in project XChange by knowm.
the class OkexExchangeIntegration method testOrderActions.
@Test
public void testOrderActions() throws Exception {
if (!API_KEY.isEmpty() && !SECRET_KEY.isEmpty() && !PASSPHRASE.isEmpty()) {
ExchangeSpecification spec = ExchangeFactory.INSTANCE.createExchange(OkexExchange.class).getDefaultExchangeSpecification();
spec.setApiKey(API_KEY);
spec.setSecretKey(SECRET_KEY);
spec.setExchangeSpecificParametersItem("passphrase", PASSPHRASE);
final Exchange exchange = ExchangeFactory.INSTANCE.createExchange(spec);
final OkexTradeService okexTradeService = (OkexTradeService) exchange.getTradeService();
assertThat(exchange.getExchangeSpecification().getSslUri()).isEqualTo("https://www.okex.com");
assertThat(exchange.getExchangeSpecification().getHost()).isEqualTo("okex.com");
// Place a single order
LimitOrder limitOrder = new LimitOrder(Order.OrderType.ASK, BigDecimal.TEN, TRX_USDT, null, new Date(), new BigDecimal(100));
String orderId = okexTradeService.placeLimitOrder(limitOrder);
log.info("Placed orderId: {}", orderId);
// Amend the above order
LimitOrder limitOrder2 = new LimitOrder(Order.OrderType.ASK, BigDecimal.TEN, TRX_USDT, orderId, new Date(), new BigDecimal(1000));
String orderId2 = okexTradeService.changeOrder(limitOrder2);
log.info("Amended orderId: {}", orderId2);
// Get non-existent Order Detail
Order failOrder = okexTradeService.getOrder(new DefaultQueryOrderParamInstrument(TRX_USDT, "2132465465"));
log.info("Null Order: {}", failOrder);
// Get Order Detail
Order amendedOrder = okexTradeService.getOrder(new DefaultQueryOrderParamInstrument(TRX_USDT, orderId2));
log.info("Amended Order: {}", amendedOrder);
// Cancel that order
boolean result = exchange.getTradeService().cancelOrder(new OkexTradeParams.OkexCancelOrderParams(TRX_USDT, orderId2));
log.info("Cancellation result: {}", result);
// Place batch orders
List<String> orderIds = okexTradeService.placeLimitOrder(Arrays.asList(limitOrder, limitOrder, limitOrder));
log.info("Placed batch orderIds: {}", orderIds);
// Amend batch orders
List<LimitOrder> amendOrders = new ArrayList<>();
for (String id : orderIds) {
amendOrders.add(new LimitOrder(Order.OrderType.ASK, BigDecimal.TEN, TRX_USDT, id, new Date(), new BigDecimal(1000)));
}
List<String> amendedOrderIds = okexTradeService.changeOrder(amendOrders);
log.info("Amended batch orderIds: {}", amendedOrderIds);
OpenOrders openOrders = okexTradeService.getOpenOrders();
log.info("Open Orders: {}", openOrders);
// Cancel batch orders
List<CancelOrderParams> cancelOrderParams = new ArrayList<>();
for (String id : orderIds) {
cancelOrderParams.add(new OkexTradeParams.OkexCancelOrderParams(TRX_USDT, id));
}
List<Boolean> results = okexTradeService.cancelOrder(cancelOrderParams);
log.info("Cancelled order results: {}", results);
}
}
Aggregations