use of com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry 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.entity.OrderbookEntry in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderbookHandler method handleEntry.
/**
* Handle a new orderbook entry
* @param bitfinexApiBroker
* @param configuration
* @param jsonArray
*/
private void handleEntry(final BitfinexApiBroker bitfinexApiBroker, final OrderbookConfiguration configuration, final JSONArray jsonArray) {
final BigDecimal price = jsonArray.getBigDecimal(0);
final BigDecimal count = jsonArray.getBigDecimal(1);
final BigDecimal amount = jsonArray.getBigDecimal(2);
final OrderbookEntry orderbookEntry = new OrderbookEntry(price, count, amount);
bitfinexApiBroker.getOrderbookManager().handleNewOrderbookEntry(configuration, orderbookEntry);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class RawOrderbookHandler method handleEntry.
/**
* Handle a new orderbook entry
* @param bitfinexApiBroker
* @param configuration
* @param jsonArray
*/
private void handleEntry(final BitfinexApiBroker bitfinexApiBroker, final RawOrderbookConfiguration configuration, final JSONArray jsonArray) {
final long orderId = jsonArray.getNumber(0).longValue();
final BigDecimal price = jsonArray.getBigDecimal(1);
final BigDecimal amount = jsonArray.getBigDecimal(2);
final RawOrderbookEntry orderbookEntry = new RawOrderbookEntry(orderId, price, amount);
bitfinexApiBroker.getRawOrderbookManager().handleNewOrderbookEntry(configuration, orderbookEntry);
}
Aggregations