Search in sources :

Example 1 with Wallet

use of com.github.jnidzwetzki.bitfinex.v2.entity.Wallet in project crypto-bot by jnidzwetzki.

the class BasePortfolioManager method getAvailablePortfolioValueInUSD.

@Override
protected double getAvailablePortfolioValueInUSD() throws APIException {
    final List<Wallet> wallets = getAllWallets();
    for (final Wallet wallet : wallets) {
        if (wallet.getCurreny().equals("USD")) {
            return wallet.getBalance();
        }
    }
    logger.error("Unable to find USD wallet");
    return 0;
}
Also used : Wallet(com.github.jnidzwetzki.bitfinex.v2.entity.Wallet)

Example 2 with Wallet

use of com.github.jnidzwetzki.bitfinex.v2.entity.Wallet in project crypto-bot by jnidzwetzki.

the class MarginPortfolioManager method getTotalPortfolioValueInUSD.

@Override
protected double getTotalPortfolioValueInUSD() throws APIException {
    final List<Wallet> wallets = getAllWallets();
    for (final Wallet wallet : wallets) {
        if (wallet.getCurreny().equals("USD")) {
            return wallet.getBalance();
        }
    }
    logger.error("Unable to find USD wallet");
    return 0;
}
Also used : Wallet(com.github.jnidzwetzki.bitfinex.v2.entity.Wallet)

Example 3 with Wallet

use of com.github.jnidzwetzki.bitfinex.v2.entity.Wallet in project crypto-bot by jnidzwetzki.

the class DonchianBot method registerTicker.

/**
 * Register the ticker
 * @throws InterruptedException
 * @throws APIException
 */
protected void registerTicker() throws InterruptedException, APIException {
    logger.info("Register ticker");
    for (final BitfinexCurrencyPair currency : tradedCurrencies) {
        // Subscribe ticket on all connections (needed for wallet in USD conversion)
        for (final BitfinexApiBroker bitfinexApiBroker : apiBrokerList) {
            final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency);
            bitfinexApiBroker.getQuoteManager().subscribeTicker(symbol);
            logger.info("Wait for ticker");
            while (!bitfinexApiBroker.isTickerActive(symbol)) {
                Thread.sleep(100);
            }
        }
        // Use only one connection for merging
        tickMerger.put(currency, new BarMerger(currency, TIMEFRAME, (s, t) -> barDoneCallback(s, t)));
        final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency);
        apiBrokerList.get(0).getQuoteManager().registerTickCallback(symbol, (s, c) -> handleBarCallback(s, c));
    }
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) Arrays(java.util.Arrays) BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) DonchianChannelUpper(com.github.jnidzwetzki.cryptobot.strategy.indicator.DonchianChannelUpper) Decimal(org.ta4j.core.Decimal) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) ArrayList(java.util.ArrayList) MaxPriceIndicator(org.ta4j.core.indicators.helpers.MaxPriceIndicator) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) PortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.PortfolioManager) Map(java.util.Map) BitfinexClientFactory(com.github.jnidzwetzki.cryptobot.util.BitfinexClientFactory) DonchianChannelLower(com.github.jnidzwetzki.cryptobot.strategy.indicator.DonchianChannelLower) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) Logger(org.slf4j.Logger) BasePortfolioManager(com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) Bar(org.ta4j.core.Bar) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) MinPriceIndicator(org.ta4j.core.indicators.helpers.MinPriceIndicator) MathUtil(org.bboxdb.commons.MathUtil) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)

Example 4 with Wallet

use of com.github.jnidzwetzki.bitfinex.v2.entity.Wallet in project crypto-bot by jnidzwetzki.

the class BasePortfolioManager method getTotalPortfolioValueInUSD.

@Override
protected double getTotalPortfolioValueInUSD() throws APIException {
    final List<Wallet> wallets = getAllWallets();
    double totalValue = 0;
    for (final Wallet wallet : wallets) {
        final String curreny = wallet.getCurreny();
        if (curreny.equals("USD")) {
            totalValue = totalValue + wallet.getBalance();
        } else {
            final String symbol = "t" + curreny + "USD";
            try {
                final BitfinexCurrencyPair bitfinexCurrencyPair = BitfinexCurrencyPair.fromSymbolString(symbol);
                final BitfinexTickerSymbol bitfinexSymbol = new BitfinexTickerSymbol(bitfinexCurrencyPair);
                final BitfinexTick lastTick = bitfinexApiBroker.getQuoteManager().getLastTick(bitfinexSymbol);
                if (lastTick != null) {
                    final double rate = lastTick.getClose();
                    final double value = rate * wallet.getBalance();
                    totalValue = totalValue + value;
                } else {
                    logger.debug("Unable to find tick for {}, appraise wallet with 0 USD", symbol);
                }
            } catch (IllegalArgumentException e) {
                logger.debug("Unkown symbol {}, ignoring wallet", symbol);
            }
        }
    }
    return totalValue;
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) Wallet(com.github.jnidzwetzki.bitfinex.v2.entity.Wallet) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)

Example 5 with Wallet

use of com.github.jnidzwetzki.bitfinex.v2.entity.Wallet in project crypto-bot by jnidzwetzki.

the class MarginPortfolioManager method getAvailablePortfolioValueInUSD.

@Override
protected double getAvailablePortfolioValueInUSD() throws APIException {
    final List<Wallet> wallets = getAllWallets();
    for (final Wallet wallet : wallets) {
        if (wallet.getCurreny().equals("USD")) {
            return wallet.getBalanceAvailable();
        }
    }
    logger.error("Unable to find USD wallet");
    return 0;
}
Also used : Wallet(com.github.jnidzwetzki.bitfinex.v2.entity.Wallet)

Aggregations

Wallet (com.github.jnidzwetzki.bitfinex.v2.entity.Wallet)9 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)4 WalletManager (com.github.jnidzwetzki.bitfinex.v2.manager.WalletManager)4 WalletHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.WalletHandler)3 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CalculateCommand (com.github.jnidzwetzki.bitfinex.v2.commands.CalculateCommand)2 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)2 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)2 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)2 BasePortfolioManager (com.github.jnidzwetzki.cryptobot.portfolio.BasePortfolioManager)2 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 Test (org.junit.Test)2 DoNothingHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.DoNothingHandler)1 HeartbeatHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.HeartbeatHandler)1 NotificationHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.NotificationHandler)1 OrderHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler)1 PositionHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.PositionHandler)1 TradeHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.TradeHandler)1