Search in sources :

Example 1 with OpenOrdersParams

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);
}
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 2 with OpenOrdersParams

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);
}
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)

Example 3 with OpenOrdersParams

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);
    }
}
Also used : LivecoinErrorAdapter(org.knowm.xchange.livecoin.LivecoinErrorAdapter) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) Date(java.util.Date) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ArrayList(java.util.ArrayList) Order(org.knowm.xchange.dto.Order) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) LivecoinExchange(org.knowm.xchange.livecoin.LivecoinExchange) Livecoin(org.knowm.xchange.livecoin.Livecoin) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) ResilienceRegistries(org.knowm.xchange.client.ResilienceRegistries) LivecoinUserOrder(org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder) Collection(java.util.Collection) IOException(java.io.IOException) UserTrades(org.knowm.xchange.dto.trade.UserTrades) LivecoinAdapters(org.knowm.xchange.livecoin.LivecoinAdapters) Collectors(java.util.stream.Collectors) Trades(org.knowm.xchange.dto.marketdata.Trades) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) List(java.util.List) TradeService(org.knowm.xchange.service.trade.TradeService) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) LivecoinPaginatedResponse(org.knowm.xchange.livecoin.dto.LivecoinPaginatedResponse) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) CancelOrderParams(org.knowm.xchange.service.trade.params.CancelOrderParams) Collections(java.util.Collections) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) LivecoinUserOrder(org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) LivecoinAdapters(org.knowm.xchange.livecoin.LivecoinAdapters)

Example 4 with OpenOrdersParams

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

Example 5 with OpenOrdersParams

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)));
}
Also used : LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BithumbOrder(org.knowm.xchange.bithumb.dto.account.BithumbOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) Logger(org.slf4j.Logger) BithumbTradeServiceRaw(org.knowm.xchange.bithumb.service.BithumbTradeServiceRaw) BithumbOrder(org.knowm.xchange.bithumb.dto.account.BithumbOrder) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Exchange(org.knowm.xchange.Exchange) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BigDecimal(java.math.BigDecimal) Order(org.knowm.xchange.dto.Order) Currency(org.knowm.xchange.currency.Currency) TradeService(org.knowm.xchange.service.trade.TradeService) BithumbDemoUtils(org.knowm.xchange.examples.bithumb.BithumbDemoUtils) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) BithumbException(org.knowm.xchange.bithumb.BithumbException) CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) IOException(java.io.IOException) DefaultTradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamCurrencyPair) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrdersParams(org.knowm.xchange.service.trade.params.orders.OpenOrdersParams) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)

Aggregations

OpenOrdersParams (org.knowm.xchange.service.trade.params.orders.OpenOrdersParams)9 TradeService (org.knowm.xchange.service.trade.TradeService)7 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)6 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)6 IOException (java.io.IOException)5 Exchange (org.knowm.xchange.Exchange)4 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)4 Test (org.junit.Test)3 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)3 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)3 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)3 TradeHistoryParams (org.knowm.xchange.service.trade.params.TradeHistoryParams)3 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AbstractResilienceTest (org.knowm.xchange.binance.AbstractResilienceTest)2 BithumbException (org.knowm.xchange.bithumb.BithumbException)2 Order (org.knowm.xchange.dto.Order)2