Search in sources :

Example 1 with LivecoinException

use of org.knowm.xchange.livecoin.dto.LivecoinException in project XChange by knowm.

the class LivecoinAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    try {
        Date start = new Date(0);
        Date end = new Date();
        if (params instanceof TradeHistoryParamsTimeSpan) {
            TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
            start = tradeHistoryParamsTimeSpan.getStartTime();
            end = tradeHistoryParamsTimeSpan.getEndTime();
        }
        Long offset = 0L;
        if (params instanceof TradeHistoryParamOffset) {
            offset = ((TradeHistoryParamOffset) params).getOffset();
        }
        Integer limit = 100;
        if (params instanceof TradeHistoryParamLimit) {
            limit = ((TradeHistoryParamLimit) params).getLimit();
        }
        List<Map> fundingRaw = funding(start, end, limit, offset);
        return fundingRaw.stream().map(LivecoinAdapters::adaptFundingRecord).collect(Collectors.toList());
    } catch (LivecoinException e) {
        throw LivecoinErrorAdapter.adapt(e);
    }
}
Also used : TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) Map(java.util.Map) Date(java.util.Date) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)

Example 2 with LivecoinException

use of org.knowm.xchange.livecoin.dto.LivecoinException in project XChange by knowm.

the class LivecoinMarketDataService method getOrderBook.

@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
    try {
        int depth = 50;
        if (args != null && args.length > 0) {
            if (args[0] instanceof Number) {
                Number arg = (Number) args[0];
                depth = arg.intValue();
            }
        }
        LivecoinOrderBook orderBook = getOrderBookRaw(currencyPair, depth, Boolean.TRUE);
        return LivecoinAdapters.adaptOrderBook(orderBook, currencyPair);
    } catch (LivecoinException e) {
        throw LivecoinErrorAdapter.adapt(e);
    }
}
Also used : LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) LivecoinOrderBook(org.knowm.xchange.livecoin.dto.marketdata.LivecoinOrderBook)

Example 3 with LivecoinException

use of org.knowm.xchange.livecoin.dto.LivecoinException 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 LivecoinException

use of org.knowm.xchange.livecoin.dto.LivecoinException 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 5 with LivecoinException

use of org.knowm.xchange.livecoin.dto.LivecoinException in project XChange by knowm.

the class LivecoinTradeService method cancelOrder.

public boolean cancelOrder(CancelOrderParams params) throws IOException {
    try {
        if (!(params instanceof CancelOrderByCurrencyPair) && !(params instanceof CancelOrderByIdParams)) {
            throw new ExchangeException("You need to provide the currency pair and the order id to cancel an order.");
        }
        CurrencyPair currencyPair = ((CancelOrderByCurrencyPair) params).getCurrencyPair();
        String orderId = ((CancelOrderByIdParams) params).getOrderId();
        return cancelOrder(currencyPair, orderId);
    } catch (LivecoinException e) {
        throw LivecoinErrorAdapter.adapt(e);
    }
}
Also used : CancelOrderByIdParams(org.knowm.xchange.service.trade.params.CancelOrderByIdParams) LivecoinException(org.knowm.xchange.livecoin.dto.LivecoinException) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) 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)

Aggregations

LivecoinException (org.knowm.xchange.livecoin.dto.LivecoinException)6 Date (java.util.Date)4 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)4 TradeHistoryParamOffset (org.knowm.xchange.service.trade.params.TradeHistoryParamOffset)4 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)4 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)3 UserTrades (org.knowm.xchange.dto.trade.UserTrades)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)3 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)3 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)3 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)3 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)3 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ResilienceRegistries (org.knowm.xchange.client.ResilienceRegistries)2