Search in sources :

Example 1 with BitfinexException

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

the class BitfinexExchange method remoteInit.

@Override
public void remoteInit() throws IOException, ExchangeException {
    try {
        BitfinexMarketDataServiceRaw dataService = (BitfinexMarketDataServiceRaw) this.marketDataService;
        List<CurrencyPair> currencyPairs = dataService.getExchangeSymbols();
        exchangeMetaData = BitfinexAdapters.adaptMetaData(currencyPairs, exchangeMetaData);
        // Get the last-price of each pair. It is needed to infer XChange's priceScale out of
        // Bitfinex's pricePercision
        Map<CurrencyPair, BigDecimal> lastPrices = Arrays.stream(dataService.getBitfinexTickers(null)).map(BitfinexAdapters::adaptTicker).collect(Collectors.toMap(t -> t.getCurrencyPair(), t -> t.getLast()));
        final List<BitfinexSymbolDetail> symbolDetails = dataService.getSymbolDetails();
        exchangeMetaData = BitfinexAdapters.adaptMetaData(exchangeMetaData, symbolDetails, lastPrices);
        if (exchangeSpecification.getApiKey() != null && exchangeSpecification.getSecretKey() != null) {
            // Bitfinex does not provide any specific wallet health info
            // So instead of wallet status, fetch platform status to get wallet health
            Integer bitfinexPlatformStatusData = dataService.getBitfinexPlatformStatus()[0];
            boolean bitfinexPlatformStatusPresent = bitfinexPlatformStatusData != null;
            int bitfinexPlatformStatus = bitfinexPlatformStatusPresent ? bitfinexPlatformStatusData : 0;
            // Additional remoteInit configuration for authenticated instances
            BitfinexAccountService accountService = (BitfinexAccountService) this.accountService;
            final BitfinexAccountFeesResponse accountFees = accountService.getAccountFees();
            exchangeMetaData = BitfinexAdapters.adaptMetaData(accountFees, bitfinexPlatformStatus, bitfinexPlatformStatusPresent, exchangeMetaData);
            BitfinexTradeService tradeService = (BitfinexTradeService) this.tradeService;
            final BitfinexAccountInfosResponse[] bitfinexAccountInfos = tradeService.getBitfinexAccountInfos();
            exchangeMetaData = BitfinexAdapters.adaptMetaData(bitfinexAccountInfos, exchangeMetaData);
        }
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : BitfinexMarketDataServiceRaw(org.knowm.xchange.bitfinex.service.BitfinexMarketDataServiceRaw) BitfinexTradeService(org.knowm.xchange.bitfinex.service.BitfinexTradeService) Arrays(java.util.Arrays) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) ResilienceRegistries(org.knowm.xchange.client.ResilienceRegistries) BitfinexAccountFeesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse) BitfinexAccountInfosResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse) IOException(java.io.IOException) BitfinexAdapters(org.knowm.xchange.bitfinex.service.BitfinexAdapters) Exchange(org.knowm.xchange.Exchange) Collectors(java.util.stream.Collectors) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) SynchronizedValueFactory(si.mazi.rescu.SynchronizedValueFactory) BigDecimal(java.math.BigDecimal) List(java.util.List) BaseExchange(org.knowm.xchange.BaseExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) BitfinexSymbolDetail(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail) BitfinexMarketDataService(org.knowm.xchange.bitfinex.service.BitfinexMarketDataService) AtomicLongIncrementalTime2013NonceFactory(org.knowm.xchange.utils.nonce.AtomicLongIncrementalTime2013NonceFactory) Map(java.util.Map) BitfinexAccountService(org.knowm.xchange.bitfinex.service.BitfinexAccountService) BitfinexMarketDataServiceRaw(org.knowm.xchange.bitfinex.service.BitfinexMarketDataServiceRaw) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) BitfinexAccountService(org.knowm.xchange.bitfinex.service.BitfinexAccountService) BitfinexTradeService(org.knowm.xchange.bitfinex.service.BitfinexTradeService) BigDecimal(java.math.BigDecimal) BitfinexAccountInfosResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) BitfinexSymbolDetail(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) BitfinexAccountFeesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse)

Example 2 with BitfinexException

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

the class BitfinexMarketDataService method getOrderBook.

/**
 * @param args If two integers are provided, then those count as limit bid and limit ask count
 */
@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
    try {
        // null will cause fetching of full order book, the default behavior in XChange
        Integer limitBids = null;
        Integer limitAsks = null;
        if (args != null && args.length == 2) {
            Object arg0 = args[0];
            if (!(arg0 instanceof Integer)) {
                throw new ExchangeException("Argument 0 must be an Integer!");
            } else {
                limitBids = (Integer) arg0;
            }
            Object arg1 = args[1];
            if (!(arg1 instanceof Integer)) {
                throw new ExchangeException("Argument 1 must be an Integer!");
            } else {
                limitAsks = (Integer) arg1;
            }
        }
        BitfinexDepth bitfinexDepth = getBitfinexOrderBook(BitfinexUtils.toPairStringV1(currencyPair), limitBids, limitAsks);
        OrderBook orderBook = BitfinexAdapters.adaptOrderBook(bitfinexDepth, currencyPair);
        return orderBook;
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) LoanOrderBook(org.knowm.xchange.dto.marketdata.LoanOrderBook) BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException)

Example 3 with BitfinexException

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

the class BitfinexTradeService method placeLimitOrder.

@Override
public String placeLimitOrder(LimitOrder limitOrder) throws IOException {
    try {
        BitfinexOrderType type = BitfinexAdapters.adaptOrderFlagsToType(limitOrder.getOrderFlags());
        BitfinexOrderStatusResponse newOrder = placeBitfinexLimitOrder(limitOrder, type);
        return String.valueOf(newOrder.getId());
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse)

Example 4 with BitfinexException

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

the class BitfinexAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    try {
        String currency = null;
        Long startTime = null;
        Long endTime = null;
        Integer limit = null;
        if (params instanceof TradeHistoryParamCurrencyPair && ((TradeHistoryParamCurrencyPair) params).getCurrencyPair() != null) {
            currency = BitfinexAdapters.adaptCurrencyPair(((TradeHistoryParamCurrencyPair) params).getCurrencyPair());
        }
        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 = Integer.valueOf(tradeHistoryParamLimit.getLimit());
            }
        }
        return BitfinexAdapters.adaptFundingHistory(getMovementHistory(currency, startTime, endTime, limit));
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : DefaultTradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamsTimeSpan) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 5 with BitfinexException

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

the class BitfinexMarketDataService method getLendOrderBook.

public LoanOrderBook getLendOrderBook(String currency, Object... args) throws IOException {
    try {
        // According to API docs, default is 50
        int limitBids = 50;
        int limitAsks = 50;
        if (args != null && args.length == 2) {
            Object arg0 = args[0];
            if (!(arg0 instanceof Integer)) {
                throw new ExchangeException("Argument 0 must be an Integer!");
            } else {
                limitBids = (Integer) arg0;
            }
            Object arg1 = args[1];
            if (!(arg1 instanceof Integer)) {
                throw new ExchangeException("Argument 1 must be an Integer!");
            } else {
                limitAsks = (Integer) arg1;
            }
        }
        BitfinexLendDepth bitfinexLendDepth = getBitfinexLendBook(currency, limitBids, limitAsks);
        List<FixedRateLoanOrder> fixedRateAsks = BitfinexAdapters.adaptFixedRateLoanOrders(bitfinexLendDepth.getAsks(), currency, "ask", "");
        List<FixedRateLoanOrder> fixedRateBids = BitfinexAdapters.adaptFixedRateLoanOrders(bitfinexLendDepth.getBids(), currency, "bid", "");
        List<FloatingRateLoanOrder> floatingRateAsks = BitfinexAdapters.adaptFloatingRateLoanOrders(bitfinexLendDepth.getAsks(), currency, "ask", "");
        List<FloatingRateLoanOrder> floatingRateBids = BitfinexAdapters.adaptFloatingRateLoanOrders(bitfinexLendDepth.getBids(), currency, "bid", "");
        return new LoanOrderBook(null, fixedRateAsks, fixedRateBids, floatingRateAsks, floatingRateBids);
    } catch (BitfinexException e) {
        throw BitfinexErrorAdapter.adapt(e);
    }
}
Also used : LoanOrderBook(org.knowm.xchange.dto.marketdata.LoanOrderBook) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) BitfinexLendDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendDepth) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BitfinexException(org.knowm.xchange.bitfinex.dto.BitfinexException) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder)

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