final String symbol = currency.toBitfinexString(); final BitfinexTickerSymbol tickerSymbol = new BitfinexTickerSymbol(currency); System.out.println(symbol + " " + tickerManager.getLastTick(tickerSymbol)); if(trade != null) { final double priceIn = trade.getExpectedPriceOpen(); final double currentPrice = tickerManager.getLastTick(tickerSymbol).getClose().doubleValue(); System.out.println(symbol + ": price in " + priceIn + " / " + (currentPrice - priceIn));
/** * Are all tickers up-to-date * @return */ private boolean checkTickerFreshness() { final QuoteManager quoteManager = bitfinexApiBroker.getQuoteManager(); final Map<BitfinexStreamSymbol, Long> heartbeatValues = quoteManager.getLastTickerActivity(); return checkTickerFreshness(heartbeatValues); }
bitfinexApiBroker.getQuoteManager().registerCandlestickCallback(barSymbol, callback); bitfinexApiBroker.getQuoteManager().subscribeCandles(barSymbol); bitfinexApiBroker.getQuoteManager().registerCandlestickCallback(barSymbol, callback); bitfinexApiBroker.getQuoteManager().unsubscribeCandles(barSymbol);
protected void registerTicker(final BitfinexApiBroker bitfinexApiBroker) throws InterruptedException, APIException { logger.info("Register ticker"); for(final BitfinexCurrencyPair currency : tradedCurrencies) { tickMerger.put(currency, new BarMerger(currency, TIMEFRAME, (s, t) -> barDoneCallback(s, t))); final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency); bitfinexApiBroker.getQuoteManager().subscribeTicker(symbol); logger.info("Wait for ticker"); while (! bitfinexApiBroker.isTickerActive(symbol)) { Thread.sleep(100); } bitfinexApiBroker .getQuoteManager() .registerTickCallback(symbol, (s, c) -> handleTickCallback(s, c)); } }
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()); }
quoteManager.invalidateTickerHeartbeat(); orderManager.clear(); positionManager.clear();
public QuoteManager(final BitfinexWebsocketClient client, final ExecutorService executorService) { super(client, executorService); this.client = client; this.lastTickerActivity = new ConcurrentHashMap<>(); this.tickerCallbacks = new BiConsumerCallbackManager<>(executorService, client); this.candleCallbacks = new BiConsumerCallbackManager<>(executorService, client); this.tradesCallbacks = new BiConsumerCallbackManager<>(executorService, client); this.pendingSubscribes = new FutureOperationRegistry(); this.pendingUnsubscribes = new FutureOperationRegistry(); client.getCallbacks().onCandlesticksEvent(this::handleCandlestickCollection); client.getCallbacks().onTickEvent(this::handleNewTick); client.getCallbacks().onExecutedTradeEvent((sym, trades) -> trades.forEach(t -> this.handleExecutedTradeEntry(sym, t))); client.getCallbacks().onSubscribeChannelEvent((s) -> pendingSubscribes.handleEvent(s)); client.getCallbacks().onUnsubscribeChannelEvent((s) -> pendingUnsubscribes.handleEvent(s)); }
bitfinexApiBroker.getQuoteManager().subscribeTicker(symbol); .registerTickCallback(symbol, (s, c) -> handleBarCallback(s, c));
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(); }
final BitfinexCurrencyPair bitfinexCurrencyPair = BitfinexCurrencyPair.fromSymbolString(symbol); final BitfinexTickerSymbol bitfinexSymbol = new BitfinexTickerSymbol(bitfinexCurrencyPair); final BitfinexTick lastTick = bitfinexApiBroker.getQuoteManager().getLastTick(bitfinexSymbol);