use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testOrderbookStream.
/**
* Test the orderbook stream
*/
@Test(timeout = 10000)
public void testOrderbookStream() {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
// Await at least 10 callbacks
final CountDownLatch latch = new CountDownLatch(10);
try {
bitfinexClient.connect();
final OrderbookConfiguration orderbookConfiguration = new OrderbookConfiguration(BitfinexCurrencyPair.BTC_USD, OrderBookPrecision.P0, OrderBookFrequency.F0, 25);
final OrderbookManager orderbookManager = bitfinexClient.getOrderbookManager();
final BiConsumer<OrderbookConfiguration, OrderbookEntry> callback = (c, o) -> {
Assert.assertTrue(o.getAmount().doubleValue() != 0);
Assert.assertTrue(o.getPrice().doubleValue() != 0);
Assert.assertTrue(o.getCount().doubleValue() != 0);
Assert.assertTrue(o.toString().length() > 0);
latch.countDown();
};
orderbookManager.registerOrderbookCallback(orderbookConfiguration, callback);
orderbookManager.subscribeOrderbook(orderbookConfiguration);
latch.await();
orderbookManager.unsubscribeOrderbook(orderbookConfiguration);
Assert.assertTrue(orderbookManager.removeOrderbookCallback(orderbookConfiguration, callback));
Assert.assertFalse(orderbookManager.removeOrderbookCallback(orderbookConfiguration, callback));
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testTickerStream.
/**
* Test the tick stream
*/
@Test(timeout = 60000)
public void testTickerStream() {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
// Await at least 2 callbacks
final CountDownLatch latch = new CountDownLatch(2);
try {
bitfinexClient.connect();
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(BitfinexCurrencyPair.BTC_USD);
final QuoteManager orderbookManager = bitfinexClient.getQuoteManager();
final BiConsumer<BitfinexTickerSymbol, BitfinexTick> callback = (c, o) -> {
latch.countDown();
};
orderbookManager.registerTickCallback(symbol, callback);
orderbookManager.subscribeTicker(symbol);
latch.await();
Assert.assertTrue(bitfinexClient.isTickerActive(symbol));
orderbookManager.unsubscribeTicker(symbol);
Assert.assertFalse(bitfinexClient.isTickerActive(symbol));
Assert.assertTrue(orderbookManager.removeTickCallback(symbol, callback));
Assert.assertFalse(orderbookManager.removeTickCallback(symbol, callback));
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testCandleStream.
/**
* Test the candle stream
*/
@Test(timeout = 10000)
public void testCandleStream() {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
// Await at least 10 callbacks
final CountDownLatch latch = new CountDownLatch(10);
try {
bitfinexClient.connect();
final BitfinexCandlestickSymbol symbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1);
final QuoteManager orderbookManager = bitfinexClient.getQuoteManager();
final BiConsumer<BitfinexCandlestickSymbol, BitfinexTick> callback = (c, o) -> {
latch.countDown();
};
orderbookManager.registerCandlestickCallback(symbol, callback);
orderbookManager.subscribeCandles(symbol);
latch.await();
orderbookManager.unsubscribeCandles(symbol);
Assert.assertTrue(orderbookManager.removeCandlestickCallback(symbol, callback));
Assert.assertFalse(orderbookManager.removeCandlestickCallback(symbol, callback));
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testReconnect.
/**
* Test the session reconnect
* @throws APIException
* @throws InterruptedException
*/
@Test
public void testReconnect() throws APIException, InterruptedException {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
bitfinexClient.connect();
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(BitfinexCurrencyPair.BTC_USD);
final QuoteManager orderbookManager = bitfinexClient.getQuoteManager();
orderbookManager.subscribeTicker(symbol);
Thread.sleep(1000);
bitfinexClient.reconnect();
// Await at least 2 callbacks
final CountDownLatch latch = new CountDownLatch(2);
final BiConsumer<BitfinexTickerSymbol, BitfinexTick> callback = (c, o) -> {
latch.countDown();
};
orderbookManager.registerTickCallback(symbol, callback);
latch.await();
Assert.assertTrue(bitfinexClient.isTickerActive(symbol));
orderbookManager.unsubscribeTicker(symbol);
Assert.assertFalse(bitfinexClient.isTickerActive(symbol));
bitfinexClient.close();
}
Aggregations