Search in sources :

Example 1 with OpenOrdersParamCurrencyPair

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.");
    }
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) KucoinExamplesUtils(org.knowm.xchange.examples.kucoin.KucoinExamplesUtils) OrderCancelResponse(org.knowm.xchange.kucoin.dto.response.OrderCancelResponse) OrderType(org.knowm.xchange.dto.Order.OrderType) UUID(java.util.UUID) Exchange(org.knowm.xchange.Exchange) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BigDecimal(java.math.BigDecimal) Order(org.knowm.xchange.dto.Order) TradeService(org.knowm.xchange.service.trade.TradeService) Optional(java.util.Optional) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) KucoinTradeServiceRaw(org.knowm.xchange.kucoin.KucoinTradeServiceRaw) OrderCreateApiRequest(org.knowm.xchange.kucoin.dto.request.OrderCreateApiRequest) OrderCreateResponse(org.knowm.xchange.kucoin.dto.response.OrderCreateResponse) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) StopOrder(org.knowm.xchange.dto.trade.StopOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)

Example 2 with OpenOrdersParamCurrencyPair

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);
}
Also used : TradeService(org.knowm.xchange.service.trade.TradeService) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) Test(org.junit.Test) AbstractResilienceTest(org.knowm.xchange.binance.AbstractResilienceTest)

Example 3 with OpenOrdersParamCurrencyPair

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;
}
Also used : BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)

Example 4 with OpenOrdersParamCurrencyPair

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);
}
Also used : OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)

Example 5 with OpenOrdersParamCurrencyPair

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);
}
Also used : TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) OrderType(org.knowm.xchange.dto.Order.OrderType) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) Exchange(org.knowm.xchange.Exchange) OrderHistory(org.knowm.xchange.dragonex.dto.trade.OrderHistory) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) DealHistoryRequest(org.knowm.xchange.dragonex.dto.trade.DealHistoryRequest) OrderHistoryRequest(org.knowm.xchange.dragonex.dto.trade.OrderHistoryRequest) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DealHistory(org.knowm.xchange.dragonex.dto.trade.DealHistory) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) IOException(java.io.IOException) UserTrades(org.knowm.xchange.dto.trade.UserTrades) OrderReference(org.knowm.xchange.dragonex.dto.trade.OrderReference) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Collectors(java.util.stream.Collectors) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) UserOrder(org.knowm.xchange.dragonex.dto.trade.UserOrder) OrderPlacement(org.knowm.xchange.dragonex.dto.trade.OrderPlacement) List(java.util.List) Order(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted.Order) TradeService(org.knowm.xchange.service.trade.TradeService) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OrderHistoryRequest(org.knowm.xchange.dragonex.dto.trade.OrderHistoryRequest) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OrderHistory(org.knowm.xchange.dragonex.dto.trade.OrderHistory) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)

Aggregations

OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)32 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)18 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)13 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)13 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)12 TradeService (org.knowm.xchange.service.trade.TradeService)10 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)10 Exchange (org.knowm.xchange.Exchange)7 Order (org.knowm.xchange.dto.Order)7 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)7 StopOrder (org.knowm.xchange.dto.trade.StopOrder)6 OpenOrdersParams (org.knowm.xchange.service.trade.params.orders.OpenOrdersParams)6 BigDecimal (java.math.BigDecimal)5 ArrayList (java.util.ArrayList)5 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)5 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)5 IOException (java.io.IOException)4 OrderType (org.knowm.xchange.dto.Order.OrderType)4 Optional (java.util.Optional)3 UUID (java.util.UUID)3