use of com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry 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();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry 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