use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker 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.BitfinexApiBroker 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.BitfinexApiBroker 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.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testCancelOrderUnauth.
/**
* Test the cancelation of an order
* @throws InterruptedException
* @throws APIException
*/
@Test(expected = APIException.class)
public void testCancelOrderUnauth() throws APIException, InterruptedException {
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
Mockito.when(bitfinexApiBroker.getCapabilities()).thenReturn(ConnectionCapabilities.NO_CAPABILITIES);
final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
orderManager.cancelOrderAndWaitForCompletion(12);
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testOrderChannelHandler2.
/**
* Test the order channel handler - snapshot
* @throws APIException
*/
@Test
public void testOrderChannelHandler2() throws APIException {
final String jsonString = "[0,\"on\",[[6784335053,null,1514956504945000,\"tIOTUSD\",1514956505134,1514956505164,-24.175121,-24.175121,\"EXCHANGE STOP\",null,null,null,0,\"ACTIVE\",null,null,3.84,0,null,null,null,null,null,0,0,0], [67843353243,null,1514956234945000,\"tBTCUSD\",1514956505134,1514956505164,-24.175121,-24.175121,\"EXCHANGE STOP\",null,null,null,0,\"ACTIVE\",null,null,3.84,0,null,null,null,null,null,0,0,0]]]";
final JSONArray jsonArray = new JSONArray(jsonString);
final OrderHandler orderHandler = new OrderHandler();
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
Assert.assertTrue(orderManager.getOrders().isEmpty());
orderHandler.handleChannelData(bitfinexApiBroker, jsonArray);
Assert.assertEquals(2, orderManager.getOrders().size());
orderManager.clear();
Assert.assertTrue(orderManager.getOrders().isEmpty());
}
Aggregations