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;
}
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;
}
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));
}
}
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;
}
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;
}
Aggregations