Search in sources :

Example 1 with RawOrderbookManager

use of com.github.jnidzwetzki.bitfinex.v2.manager.RawOrderbookManager in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class IntegrationTest method testRawOrderbookStream.

/**
 * Test the raw orderbook stream
 */
@Test(timeout = 10000)
public void testRawOrderbookStream() {
    final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
    // Await at least 20 callbacks
    final CountDownLatch latch = new CountDownLatch(20);
    try {
        bitfinexClient.connect();
        final RawOrderbookConfiguration orderbookConfiguration = new RawOrderbookConfiguration(BitfinexCurrencyPair.BTC_USD);
        final RawOrderbookManager rawOrderbookManager = bitfinexClient.getRawOrderbookManager();
        final BiConsumer<RawOrderbookConfiguration, RawOrderbookEntry> callback = (c, o) -> {
            Assert.assertTrue(o.getAmount().doubleValue() != 0);
            Assert.assertTrue(o.getPrice().doubleValue() != 0);
            Assert.assertTrue(o.getOrderId() >= 0);
            Assert.assertTrue(o.toString().length() > 0);
            latch.countDown();
        };
        rawOrderbookManager.registerOrderbookCallback(orderbookConfiguration, callback);
        rawOrderbookManager.subscribeOrderbook(orderbookConfiguration);
        latch.await();
        rawOrderbookManager.unsubscribeOrderbook(orderbookConfiguration);
        Assert.assertTrue(rawOrderbookManager.removeOrderbookCallback(orderbookConfiguration, callback));
        Assert.assertFalse(rawOrderbookManager.removeOrderbookCallback(orderbookConfiguration, callback));
    } catch (Exception e) {
        // Should not happen
        e.printStackTrace();
        Assert.assertTrue(false);
    } finally {
        bitfinexClient.close();
    }
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) OrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry) OrderBookPrecision(com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookPrecision) Test(org.junit.Test) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) OrderbookManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager) OrderBookFrequency(com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookFrequency) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) RawOrderbookManager(com.github.jnidzwetzki.bitfinex.v2.manager.RawOrderbookManager) QuoteManager(com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager) RawOrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry) BiConsumer(java.util.function.BiConsumer) ExecutedTrade(com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade) Assert(org.junit.Assert) BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) RawOrderbookManager(com.github.jnidzwetzki.bitfinex.v2.manager.RawOrderbookManager) RawOrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry) CountDownLatch(java.util.concurrent.CountDownLatch) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) Test(org.junit.Test)

Aggregations

BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)1 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)1 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)1 ExecutedTrade (com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade)1 OrderBookFrequency (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookFrequency)1 OrderBookPrecision (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookPrecision)1 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)1 OrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry)1 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)1 RawOrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry)1 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)1 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)1 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)1 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)1 OrderbookManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager)1 QuoteManager (com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager)1 RawOrderbookManager (com.github.jnidzwetzki.bitfinex.v2.manager.RawOrderbookManager)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BiConsumer (java.util.function.BiConsumer)1