/** * Get all wallets * @param currency * @return * @throws APIException */ protected List<Wallet> getAllWallets() throws APIException { return bitfinexApiBroker.getWalletManager().getWallets() .stream() .filter(w -> w.getWalletType().equals(getWalletType())) .collect(Collectors.toList()); }
/** * Get all wallets * @return * @throws BitfinexClientException */ public Collection<BitfinexWallet> getWallets() throws BitfinexClientException { throwExceptionIfUnauthenticated(); synchronized (walletTable) { return Collections.unmodifiableCollection(walletTable.values()); } }
public PooledBitfinexApiBroker(final BitfinexWebsocketConfiguration config, final BitfinexApiCallbackRegistry callbacks, final SequenceNumberAuditor seqNoAuditor, final int channelsPerConnection) { configuration = new BitfinexWebsocketConfiguration(config); callbackRegistry = callbacks; sequenceNumberAuditor = seqNoAuditor; maxChannelsPerClient = channelsPerConnection; connectEventManager = new EventsInTimeslotManager(1, configuration.getConnectionEstablishingDelay(), TimeUnit.MILLISECONDS); quoteManager = new QuoteManager(this, configuration.getExecutorService()); orderbookManager = new OrderbookManager(this, configuration.getExecutorService()); rawOrderbookManager = new RawOrderbookManager(this, configuration.getExecutorService()); orderManager = new OrderManager(this, configuration.getExecutorService()); tradeManager = new TradeManager(this, configuration.getExecutorService()); positionManager = new PositionManager(this, configuration.getExecutorService()); walletManager = new WalletManager(this, configuration.getExecutorService()); connectionFeatureManager = new ConnectionFeatureManager(this, configuration.getExecutorService()); callbackRegistry.onSubscribeChannelEvent(sym -> pendingSubscriptions.forEach((client, symbols) -> symbols.remove(sym))); callbackRegistry.onUnsubscribeChannelEvent(sym -> pendingSubscriptions.forEach((client, symbols) -> symbols.remove(sym))); SimpleBitfinexApiBroker authClient = new SimpleBitfinexApiBroker(configuration, callbackRegistry, seqNoAuditor, true); clients.put(numberOfClients.getAndIncrement(), authClient); pendingSubscriptions.put(authClient, ConcurrentHashMap.newKeySet()); }
public WalletManager(final BitfinexWebsocketClient client, final ExecutorService executorService) { super(client, executorService); this.walletTable = HashBasedTable.create(); client.getCallbacks().onMyWalletEvent((account, wallets) -> wallets.forEach(wallet -> { try { Table<BitfinexWallet.Type, String, BitfinexWallet> walletTable = getWalletTable(); synchronized (walletTable) { walletTable.put(wallet.getWalletType(), wallet.getCurrency(), wallet); walletTable.notifyAll(); } } catch (BitfinexClientException e) { e.printStackTrace(); } })); }
public SimpleBitfinexApiBroker(final BitfinexWebsocketConfiguration config, final BitfinexApiCallbackRegistry callbackRegistry, final SequenceNumberAuditor sequenceNumberAuditor, final boolean skipConnectionStateNotification) { this.configuration = new BitfinexWebsocketConfiguration(config); this.callbackRegistry = callbackRegistry; this.skipConnectionStateNotification = skipConnectionStateNotification; this.channelIdToHandlerMap = new ConcurrentHashMap<>(); this.permissions = BitfinexApiKeyPermissions.NO_PERMISSIONS; this.sequenceNumberAuditor = sequenceNumberAuditor; this.lastHeartbeat = new AtomicLong(0); this.orderbookManager = new OrderbookManager(this, configuration.getExecutorService()); this.rawOrderbookManager = new RawOrderbookManager(this, configuration.getExecutorService()); this.orderManager = new OrderManager(this, configuration.getExecutorService()); this.tradeManager = new TradeManager(this, configuration.getExecutorService()); this.positionManager = new PositionManager(this, configuration.getExecutorService()); this.walletManager = new WalletManager(this, configuration.getExecutorService()); this.quoteManager = new QuoteManager(this, configuration.getExecutorService()); this.connectionFeatureManager = new ConnectionFeatureManager(this, configuration.getExecutorService()); setupCommandCallbacks(); }
/** * Get the exchange wallet * @param currency * @return * @throws APIException */ protected Wallet getWalletForCurrency(final String currency) throws APIException { return bitfinexApiBroker.getWalletManager().getWallets() .stream() .filter(w -> w.getWalletType().equals(getWalletType())) .filter(w -> w.getCurreny().equals(currency)) .findFirst() .orElse(null); }
/** * Calculate the wallet margin balance for the given currency (e.g., BTC) * * @param symbol * @throws BitfinexClientException */ public void calculateWalletMarginBalance(final String symbol) throws BitfinexClientException { throwExceptionIfUnauthenticated(); client.sendCommand(new CalculateCommand("wallet_margin_" + symbol)); }
/** * Execute a new open position order * @param symbol * @param endIndex * @throws APIException */ private void openOrder(final BitfinexCurrencyPair symbol, final int endIndex) throws APIException { final Decimal lastClosePrice = timeSeries.get(symbol).getLastBar().getClosePrice(); final Trade openTrade = getOpenTrade(symbol); if(openTrade != null) { logger.debug("Unable to open new trade, there is already one active {}", openTrade); return; } final double amount = PositionSizeManager.getPositionSize(symbol, OrderType.BUY, bitfinexApiBroker.getWalletManager().getWallets()); final Trade trade = new Trade("EMA Strategy", TradeDirection.LONG, symbol, amount); trade.setExpectedPriceOpen(lastClosePrice.doubleValue()); addTradeToOpenTradeList(trade); orderManager.openTrade(trade); }
/** * Calculate the wallet funding balance for the given currency (e.g., BTC) * * @param symbol * @throws BitfinexClientException */ public void calculateWalletFundingBalance(final String symbol) throws BitfinexClientException { throwExceptionIfUnauthenticated(); client.sendCommand(new CalculateCommand("wallet_funding_" + symbol)); }