Search in sources :

Example 1 with BitfinexAccountService

use of org.knowm.xchange.bitfinex.service.BitfinexAccountService 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 BitfinexAccountService

use of org.knowm.xchange.bitfinex.service.BitfinexAccountService in project XChange by knowm.

the class BitfinexExchange method initServices.

@Override
protected void initServices() {
    this.marketDataService = new BitfinexMarketDataService(this, getResilienceRegistries());
    this.accountService = new BitfinexAccountService(this, getResilienceRegistries());
    this.tradeService = new BitfinexTradeService(this, getResilienceRegistries());
}
Also used : BitfinexAccountService(org.knowm.xchange.bitfinex.service.BitfinexAccountService) BitfinexMarketDataService(org.knowm.xchange.bitfinex.service.BitfinexMarketDataService) BitfinexTradeService(org.knowm.xchange.bitfinex.service.BitfinexTradeService)

Aggregations

BitfinexAccountService (org.knowm.xchange.bitfinex.service.BitfinexAccountService)2 BitfinexMarketDataService (org.knowm.xchange.bitfinex.service.BitfinexMarketDataService)2 BitfinexTradeService (org.knowm.xchange.bitfinex.service.BitfinexTradeService)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)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 BitfinexException (org.knowm.xchange.bitfinex.dto.BitfinexException)1 BitfinexAdapters (org.knowm.xchange.bitfinex.service.BitfinexAdapters)1 BitfinexMarketDataServiceRaw (org.knowm.xchange.bitfinex.service.BitfinexMarketDataServiceRaw)1 BitfinexAccountFeesResponse (org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse)1 BitfinexSymbolDetail (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail)1 BitfinexAccountInfosResponse (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse)1 ResilienceRegistries (org.knowm.xchange.client.ResilienceRegistries)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1