use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair 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.service.trade.params.orders.OpenOrdersParamCurrencyPair 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.OpenOrdersParamCurrencyPair in project XChange by knowm.
the class YoBitTradeServiceRaw method activeOrders.
public BaseYoBitResponse activeOrders(OpenOrdersParamCurrencyPair params) throws IOException {
CurrencyPair currencyPair = params.getCurrencyPair();
String market = YoBitAdapters.adaptCcyPairToUrlFormat(currencyPair);
BaseYoBitResponse response = service.activeOrders(exchange.getExchangeSpecification().getApiKey(), signatureCreator, "ActiveOrders", exchange.getNonceFactory(), market);
if (!response.success)
throw new ExchangeException("failed to get open orders");
return response;
}
use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair in project XChange by knowm.
the class PoloniexTradeDemo method printOpenOrders.
private static void printOpenOrders(TradeService tradeService) throws Exception {
TimeUnit.SECONDS.sleep(2);
final OpenOrdersParamCurrencyPair params = (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
OpenOrders openOrders = tradeService.getOpenOrders(params);
System.out.printf("All open Orders: %s%n", openOrders);
params.setCurrencyPair(currencyPair);
openOrders = tradeService.getOpenOrders(params);
System.out.printf("Open Orders for %s: %s%n: ", params, openOrders);
params.setCurrencyPair(REP_ETH);
openOrders = tradeService.getOpenOrders(params);
System.out.printf("Open Orders for %s: %s%n: ", params, openOrders);
}
use of org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair 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);
}
Aggregations