Search in sources :

Example 1 with BitfinexAccountInfosResponse

use of org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse 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 BitfinexAccountInfosResponse

use of org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse in project XChange by knowm.

the class BitfinexAdapters method adaptMetaData.

public static ExchangeMetaData adaptMetaData(BitfinexAccountInfosResponse[] bitfinexAccountInfos, ExchangeMetaData exchangeMetaData) {
    final Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs();
    // lets go with the assumption that the trading fees are common across all trading pairs for
    // now.
    // also setting the taker_fee as the trading_fee for now.
    final CurrencyPairMetaData metaData = new CurrencyPairMetaData(bitfinexAccountInfos[0].getTakerFees().movePointLeft(2), null, null, null, null);
    currencyPairs.keySet().parallelStream().forEach(currencyPair -> currencyPairs.merge(currencyPair, metaData, (oldMetaData, newMetaData) -> new CurrencyPairMetaData(newMetaData.getTradingFee(), oldMetaData.getMinimumAmount(), oldMetaData.getMaximumAmount(), oldMetaData.getPriceScale(), oldMetaData.getFeeTiers())));
    return exchangeMetaData;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) StopOrder(org.knowm.xchange.dto.trade.StopOrder) Arrays(java.util.Arrays) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date) BitfinexBalancesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexBalancesResponse) LoggerFactory(org.slf4j.LoggerFactory) BitfinexLendLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendLevel) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BitfinexDepositWithdrawalHistoryResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexDepositWithdrawalHistoryResponse) Map(java.util.Map) BitfinexTrade(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade) BitfinexPublicTrade(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) Wallet(org.knowm.xchange.dto.account.Wallet) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) MathContext(java.math.MathContext) BitfinexAccountInfosResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse) BitfinexTradeResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse) Collection(java.util.Collection) Set(java.util.Set) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) Stream(java.util.stream.Stream) BitfinexLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel) Entry(java.util.Map.Entry) Optional(java.util.Optional) BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker) BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth) Movement(org.knowm.xchange.bitfinex.v2.dto.account.Movement) CurrencyPairDeserializer(org.knowm.xchange.utils.jackson.CurrencyPairDeserializer) BitfinexUtils(org.knowm.xchange.bitfinex.v1.BitfinexUtils) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) Supplier(java.util.function.Supplier) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) BitfinexTickerFundingCurrency(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerFundingCurrency) Order(org.knowm.xchange.dto.Order) BitfinexSymbolDetail(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Ticker(org.knowm.xchange.dto.marketdata.Ticker) Logger(org.slf4j.Logger) Fee(org.knowm.xchange.dto.account.Fee) BitfinexAccountFeesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Trades(org.knowm.xchange.dto.marketdata.Trades) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder) BitfinexTradingFeeResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Trade(org.knowm.xchange.dto.marketdata.Trade) BitfinexOrderFlags(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderFlags) BitfinexTickerTraidingPair(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerTraidingPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) WalletHealth(org.knowm.xchange.dto.meta.WalletHealth) DateUtils(org.knowm.xchange.utils.DateUtils) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

IOException (java.io.IOException)2 BigDecimal (java.math.BigDecimal)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 BitfinexAccountFeesResponse (org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse)2 BitfinexSymbolDetail (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail)2 BitfinexAccountInfosResponse (org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 MathContext (java.math.MathContext)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1