use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParams in project XChange by knowm.
the class TradeServiceResilienceTest method shouldSucceedIfFirstCallTimeoutedAndRetryIsEnabled.
@Test
public void shouldSucceedIfFirstCallTimeoutedAndRetryIsEnabled() throws Exception {
// given
TradeService service = createExchangeWithRetryEnabled().getTradeService();
stubForOpenOrdersWithFirstCallTimetoutAndSecondSuccessful();
OpenOrdersParams params = service.createOpenOrdersParams();
((OpenOrdersParamCurrencyPair) params).setCurrencyPair(CurrencyPair.LTC_BTC);
// when
OpenOrders openOrders = service.getOpenOrders(params);
// then
assertThat(openOrders.getOpenOrders()).hasSize(1).first().extracting(Order::getCurrencyPair).isEqualTo(CurrencyPair.LTC_BTC);
}
use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParams in project XChange by knowm.
the class DragonexTradeService method getOpenOrders.
@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
if (!(params instanceof OpenOrdersParamCurrencyPair)) {
throw new ExchangeException("You need to provide the currency pair.");
}
OpenOrdersParamCurrencyPair pairParams = (OpenOrdersParamCurrencyPair) params;
if (pairParams.getCurrencyPair() == null) {
throw new ExchangeException("You need to provide the currency pair.");
}
long symbolId = exchange.symbolId(pairParams.getCurrencyPair());
OrderHistoryRequest req = new OrderHistoryRequest(symbolId, null, null, 1000, 1);
OrderHistory orderHistory = super.orderHistory(exchange.getOrCreateToken().token, req);
List<LimitOrder> openOrders = orderHistory.getList().stream().map(o -> new LimitOrder(o.orderType == 1 ? OrderType.BID : OrderType.ASK, o.volume, exchange.pair(o.symbolId), Long.toString(o.orderId), o.getTimestamp(), o.price)).collect(Collectors.toList());
return new OpenOrders(openOrders);
}
use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParams 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);
}
}
use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParams in project XChange by knowm.
the class BitstampTradeDemo method generic.
private static void generic(TradeService tradeService) throws IOException {
final OpenOrdersParamCurrencyPair openOrdersParamsBtcEur = (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
openOrdersParamsBtcEur.setCurrencyPair(CurrencyPair.BTC_EUR);
final OpenOrdersParamCurrencyPair openOrdersParamsBtcUsd = (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
openOrdersParamsBtcUsd.setCurrencyPair(CurrencyPair.BTC_USD);
final OpenOrdersParams openOrdersParamsAll = tradeService.createOpenOrdersParams();
printOpenOrders(tradeService, openOrdersParamsAll);
// place a limit buy order
LimitOrder limitOrder = new LimitOrder((OrderType.BID), new BigDecimal(".01"), CurrencyPair.BTC_EUR, null, null, new BigDecimal("500.00"));
String limitOrderReturnValue = tradeService.placeLimitOrder(limitOrder);
System.out.println("Limit Order return value: " + limitOrderReturnValue);
printOpenOrders(tradeService, openOrdersParamsAll);
printOpenOrders(tradeService, openOrdersParamsBtcEur);
printOpenOrders(tradeService, openOrdersParamsBtcUsd);
// Cancel the added order
boolean cancelResult = tradeService.cancelOrder(limitOrderReturnValue);
System.out.println("Canceling returned " + cancelResult);
printOpenOrders(tradeService, openOrdersParamsAll);
}
use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParams in project XChange by knowm.
the class BithumbTradeDemo method generic.
private static void generic(TradeService tradeService) throws IOException, InterruptedException {
log.debug("{}", "----------GENERIC----------");
final OpenOrdersParams openOrders = new DefaultOpenOrdersParamCurrencyPair(CURRENCY_PAIR);
try {
log.debug("{}", tradeService.getOpenOrders(openOrders));
} catch (ExchangeException e) {
log.debug("", e);
}
final TradeHistoryParams tradeHistoryParams = new DefaultTradeHistoryParamCurrencyPair(CURRENCY_PAIR);
log.debug("{}", tradeService.getTradeHistory(tradeHistoryParams));
final LimitOrder limitOrderBuy = new LimitOrder.Builder(Order.OrderType.BID, CURRENCY_PAIR).originalAmount(BigDecimal.valueOf(10)).limitPrice(BigDecimal.valueOf(100)).build();
log.debug("{}", tradeService.placeLimitOrder(limitOrderBuy));
// wait for order to propagate
Thread.sleep(3000);
final LimitOrder limitOrderSell = new LimitOrder.Builder(Order.OrderType.ASK, CURRENCY_PAIR).originalAmount(BigDecimal.valueOf(10)).limitPrice(BigDecimal.valueOf(600)).build();
log.debug("{}", tradeService.placeLimitOrder(limitOrderSell));
// wait for order to propagate
Thread.sleep(3000);
tradeService.getOpenOrders(openOrders).getOpenOrders().stream().map(Order::getId).map(orderId -> new CancelOrderByPairAndIdParams() {
@Override
public String getOrderId() {
return orderId;
}
@Override
public CurrencyPair getCurrencyPair() {
return CURRENCY_PAIR;
}
}).forEach(param -> {
try {
log.debug("{}", tradeService.cancelOrder(param));
} catch (IOException ignored) {
}
});
// log.debug("{}",tradeService.placeMarketOrder(new MarketOrder(Order.OrderType.ASK,
// BigDecimal.valueOf(10), CURRENCY_PAIR)));
}
Aggregations