use of com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration 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.OrderbookConfiguration 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.OrderbookConfiguration in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderbookTest method testTradingOrderbookEquals.
/**
* Test the equals method
*/
@Test
public void testTradingOrderbookEquals() {
final OrderbookConfiguration configuration1 = new OrderbookConfiguration(BitfinexCurrencyPair.BCH_USD, OrderBookPrecision.P1, OrderBookFrequency.F1, 50);
final OrderbookConfiguration configuration2 = new OrderbookConfiguration(BitfinexCurrencyPair.BCH_USD, OrderBookPrecision.P1, OrderBookFrequency.F1, 50);
final OrderbookConfiguration configuration3 = new OrderbookConfiguration(BitfinexCurrencyPair.BCH_USD, OrderBookPrecision.P0, OrderBookFrequency.F1, 50);
Assert.assertEquals(configuration1.hashCode(), configuration2.hashCode());
Assert.assertEquals(configuration1, configuration2);
Assert.assertFalse(configuration1.equals(configuration3));
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderbookTest method createOrderbookConfigurationFromJSON.
/**
* Test the build from JSON array
*/
@Test
public void createOrderbookConfigurationFromJSON() {
final String message = "{\"event\":\"subscribed\",\"channel\":\"book\",\"chanId\":3829,\"symbol\":\"tBTCUSD\",\"prec\":\"P0\",\"freq\":\"F0\",\"len\":\"25\",\"pair\":\"BTCUSD\"}";
final JSONTokener tokener = new JSONTokener(message);
final JSONObject jsonObject = new JSONObject(tokener);
final OrderbookConfiguration configuration = OrderbookConfiguration.fromJSON(jsonObject);
Assert.assertEquals(BitfinexCurrencyPair.BTC_USD, configuration.getCurrencyPair());
Assert.assertEquals(OrderBookFrequency.F0, configuration.getOrderBookFrequency());
Assert.assertEquals(OrderBookPrecision.P0, configuration.getOrderBookPrecision());
Assert.assertEquals(25, configuration.getPricePoints());
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class RawOrderbookManager method subscribeOrderbook.
/**
* Subscribe a orderbook
* @param currencyPair
* @param orderBookPrecision
* @param orderBookFrequency
* @param pricePoints
*/
public void subscribeOrderbook(final RawOrderbookConfiguration orderbookConfiguration) {
final SubscribeRawOrderbookCommand subscribeOrderbookCommand = new SubscribeRawOrderbookCommand(orderbookConfiguration);
bitfinexApiBroker.sendCommand(subscribeOrderbookCommand);
}
Aggregations