Search in sources :

Example 6 with BitfinexException

use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.

the class BitfinexTradeService method getTradeHistory.

/**
 * @param params Implementation of {@link TradeHistoryParamCurrencyPair} is mandatory. Can
 *     optionally implement {@link TradeHistoryParamPaging} and {@link
 *     TradeHistoryParamsTimeSpan#getStartTime()}. All other TradeHistoryParams types will be
 *     ignored.
 */
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    try {
        String symbol = null;
        if (params instanceof TradeHistoryParamCurrencyPair && ((TradeHistoryParamCurrencyPair) params).getCurrencyPair() != null) {
            symbol = BitfinexAdapters.adaptCurrencyPair(((TradeHistoryParamCurrencyPair) params).getCurrencyPair());
        }
        Long startTime = 0L;
        Long endTime = null;
        Long limit = 50L;
        Long sort = null;
        if (params instanceof TradeHistoryParamsTimeSpan) {
            TradeHistoryParamsTimeSpan paramsTimeSpan = (TradeHistoryParamsTimeSpan) params;
            startTime = DateUtils.toMillisNullSafe(paramsTimeSpan.getStartTime());
            endTime = DateUtils.toMillisNullSafe(paramsTimeSpan.getEndTime());
        }
        if (params instanceof TradeHistoryParamLimit) {
            TradeHistoryParamLimit tradeHistoryParamLimit = (TradeHistoryParamLimit) params;
            if (tradeHistoryParamLimit.getLimit() != null) {
                limit = Long.valueOf(tradeHistoryParamLimit.getLimit());
            }
        }
        if (params instanceof TradeHistoryParamsSorted) {
            TradeHistoryParamsSorted tradeHistoryParamsSorted = (TradeHistoryParamsSorted) params;
            sort = tradeHistoryParamsSorted.getOrder() == TradeHistoryParamsSorted.Order.asc ? 1L : -1L;
        }
        final List<Trade> trades = getBitfinexTradesV2(symbol, startTime, endTime, limit, sort);
        return BitfinexAdapters.adaptTradeHistoryV2(trades);
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : Trade(org.knowm.xchange.bitfinex.v2.dto.trade.Trade) DefaultTradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamsTimeSpan) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 7 with BitfinexException

use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.

the class BitfinexTradeService method getOrder.

@Override
public Collection<Order> getOrder(String... orderIds) throws IOException {
    try {
        List<Order> openOrders = new ArrayList<>();
        for (String orderId : orderIds) {
            BitfinexOrderStatusResponse orderStatus = getBitfinexOrderStatus(orderId);
            BitfinexOrderStatusResponse[] orderStatuses = new BitfinexOrderStatusResponse[1];
            if (orderStatus != null) {
                orderStatuses[0] = orderStatus;
                OpenOrders orders = BitfinexAdapters.adaptOrders(orderStatuses);
                openOrders.add(orders.getOpenOrders().get(0));
            }
        }
        return openOrders;
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : StopOrder(org.knowm.xchange.dto.trade.StopOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) ArrayList(java.util.ArrayList) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse)

Example 8 with BitfinexException

use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.

the class BitfinexTradeService method changeOrder.

@Override
public String changeOrder(LimitOrder order) throws IOException {
    boolean useRemaining = order.getOriginalAmount() == null || order.hasFlag(BitfinexOrderFlags.USE_REMAINING);
    BitfinexReplaceOrderRequest request = new BitfinexReplaceOrderRequest(String.valueOf(exchange.getNonceFactory().createValue()), Long.valueOf(order.getId()), BitfinexAdapters.adaptCurrencyPair(order.getCurrencyPair()), order.getOriginalAmount(), order.getLimitPrice(), "bitfinex", BitfinexAdapters.adaptOrderType(order.getType()), BitfinexAdapters.adaptOrderFlagsToType(order.getOrderFlags()).getValue(), order.hasFlag(BitfinexOrderFlags.HIDDEN), order.hasFlag(BitfinexOrderFlags.POST_ONLY), useRemaining);
    try {
        BitfinexOrderStatusResponse response = bitfinex.replaceOrder(apiKey, payloadCreator, signatureCreator, request);
        return String.valueOf(response.getId());
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) BitfinexReplaceOrderRequest(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexReplaceOrderRequest)

Aggregations

BitfinexException (org.knowm.xchange.bitfinex.dto.BitfinexException)8 BitfinexOrderStatusResponse (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)3 LoanOrderBook (org.knowm.xchange.dto.marketdata.LoanOrderBook)2 DefaultTradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamsTimeSpan)2 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)2 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)2 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BaseExchange (org.knowm.xchange.BaseExchange)1 Exchange (org.knowm.xchange.Exchange)1 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)1 BitfinexAccountService (org.knowm.xchange.bitfinex.service.BitfinexAccountService)1 BitfinexAdapters (org.knowm.xchange.bitfinex.service.BitfinexAdapters)1