Search in sources :

Example 1 with OrderQueryParamCurrencyPair

use of org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair in project XChange by knowm.

the class BinanceTradeService method getOrder.

@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
    try {
        Collection<Order> orders = new ArrayList<>();
        for (OrderQueryParams param : params) {
            if (!(param instanceof OrderQueryParamCurrencyPair)) {
                throw new ExchangeException("Parameters must be an instance of OrderQueryParamCurrencyPair");
            }
            OrderQueryParamCurrencyPair orderQueryParamCurrencyPair = (OrderQueryParamCurrencyPair) param;
            if (orderQueryParamCurrencyPair.getCurrencyPair() == null || orderQueryParamCurrencyPair.getOrderId() == null) {
                throw new ExchangeException("You need to provide the currency pair and the order id to query an order.");
            }
            orders.add(BinanceAdapters.adaptOrder(super.orderStatus(orderQueryParamCurrencyPair.getCurrencyPair(), BinanceAdapters.id(orderQueryParamCurrencyPair.getOrderId()), null)));
        }
        return orders;
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) BinanceNewOrder(org.knowm.xchange.binance.dto.trade.BinanceNewOrder) BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BinanceException(org.knowm.xchange.binance.dto.BinanceException) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) ArrayList(java.util.ArrayList) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams)

Example 2 with OrderQueryParamCurrencyPair

use of org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair in project XChange by knowm.

the class LivecoinTradeService method getOrder.

@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
    try {
        if (params == null || params.length == 0) {
            LivecoinPaginatedResponse<LivecoinUserOrder> response = clientOrders(null, null, null, null, null, null);
            return LivecoinAdapters.adaptUserOrders(response.getData());
        }
        List<Order> result = new ArrayList<>();
        for (OrderQueryParams param : params) {
            CurrencyPair pair = null;
            if (param instanceof OrderQueryParamCurrencyPair) {
                pair = ((OrderQueryParamCurrencyPair) param).getCurrencyPair();
            }
            LivecoinPaginatedResponse<LivecoinUserOrder> response = clientOrders(pair, null, null, null, null, null);
            if (param.getOrderId() == null) {
                result.addAll(LivecoinAdapters.adaptUserOrders(response.getData()));
            } else {
                response.getData().stream().filter(order -> order.getId().toString().equals(param.getOrderId())).findAny().map(LivecoinAdapters::adaptUserOrder).ifPresent(result::add);
            }
        }
        return result;
    } catch (LivecoinException e) {
        throw LivecoinErrorAdapter.adapt(e);
    }
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) LivecoinUserOrder(org.knowm.xchange.livecoin.dto.marketdata.LivecoinUserOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) 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) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) ArrayList(java.util.ArrayList) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams) 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)

Example 3 with OrderQueryParamCurrencyPair

use of org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair 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);
    }
}
Also used : LatokenNewOrder(org.knowm.xchange.latoken.dto.trade.LatokenNewOrder) Order(org.knowm.xchange.dto.Order) LatokenTestOrder(org.knowm.xchange.latoken.dto.trade.LatokenTestOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) LatokenException(org.knowm.xchange.latoken.dto.LatokenException) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) ArrayList(java.util.ArrayList) LatokenOrderStatus(org.knowm.xchange.latoken.dto.trade.LatokenOrderStatus) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

ArrayList (java.util.ArrayList)3 Order (org.knowm.xchange.dto.Order)3 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)3 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)3 OrderQueryParams (org.knowm.xchange.service.trade.params.orders.OrderQueryParams)3 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)2 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)2 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 BinanceException (org.knowm.xchange.binance.dto.BinanceException)1 BinanceNewOrder (org.knowm.xchange.binance.dto.trade.BinanceNewOrder)1 BinanceOrder (org.knowm.xchange.binance.dto.trade.BinanceOrder)1 ResilienceRegistries (org.knowm.xchange.client.ResilienceRegistries)1