use of com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration 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.RawOrderbookConfiguration in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class RawOrderbookTest method testTradingOrderbookEquals.
/**
* Test the equals method
*/
@Test
public void testTradingOrderbookEquals() {
final RawOrderbookConfiguration configuration1 = new RawOrderbookConfiguration(BitfinexCurrencyPair.BCH_USD);
final RawOrderbookConfiguration configuration2 = new RawOrderbookConfiguration(BitfinexCurrencyPair.BCH_USD);
final RawOrderbookConfiguration configuration3 = new RawOrderbookConfiguration(BitfinexCurrencyPair.AVT_BTC);
Assert.assertEquals(configuration1.hashCode(), configuration2.hashCode());
Assert.assertEquals(configuration1, configuration2);
Assert.assertFalse(configuration1.equals(configuration3));
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration 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);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class BitfinexApiBroker method resubscribeChannels.
/**
* Resubscribe the old ticker
* @throws InterruptedException
* @throws APIException
*/
private void resubscribeChannels() throws InterruptedException, APIException {
final Map<Integer, BitfinexStreamSymbol> oldChannelIdSymbolMap = new HashMap<>();
synchronized (channelIdSymbolMap) {
oldChannelIdSymbolMap.putAll(channelIdSymbolMap);
channelIdSymbolMap.clear();
channelIdSymbolMap.notifyAll();
}
// Resubscribe channels
for (BitfinexStreamSymbol symbol : oldChannelIdSymbolMap.values()) {
if (symbol instanceof BitfinexTickerSymbol) {
sendCommand(new SubscribeTickerCommand((BitfinexTickerSymbol) symbol));
} else if (symbol instanceof BitfinexExecutedTradeSymbol) {
sendCommand(new SubscribeTradesCommand((BitfinexExecutedTradeSymbol) symbol));
} else if (symbol instanceof BitfinexCandlestickSymbol) {
sendCommand(new SubscribeCandlesCommand((BitfinexCandlestickSymbol) symbol));
} else if (symbol instanceof OrderbookConfiguration) {
sendCommand(new SubscribeOrderbookCommand((OrderbookConfiguration) symbol));
} else if (symbol instanceof RawOrderbookConfiguration) {
sendCommand(new SubscribeRawOrderbookCommand((RawOrderbookConfiguration) symbol));
} else {
logger.error("Unknown stream symbol: {}", symbol);
}
}
waitForChannelResubscription(oldChannelIdSymbolMap);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class BitfinexApiBroker method handleChannelDataArray.
/**
* Handle the channel data with has an array at first position
* @param jsonArray
* @param channelSymbol
* @throws APIException
*/
private void handleChannelDataArray(final JSONArray jsonArray, final BitfinexStreamSymbol channelSymbol) throws APIException {
final JSONArray subarray = jsonArray.getJSONArray(1);
if (channelSymbol instanceof BitfinexCandlestickSymbol) {
final ChannelCallbackHandler handler = new CandlestickHandler();
handler.handleChannelData(this, channelSymbol, subarray);
} else if (channelSymbol instanceof RawOrderbookConfiguration) {
final RawOrderbookHandler handler = new RawOrderbookHandler();
handler.handleChannelData(this, channelSymbol, subarray);
} else if (channelSymbol instanceof OrderbookConfiguration) {
final OrderbookHandler handler = new OrderbookHandler();
handler.handleChannelData(this, channelSymbol, subarray);
} else if (channelSymbol instanceof BitfinexTickerSymbol) {
final ChannelCallbackHandler handler = new TickHandler();
handler.handleChannelData(this, channelSymbol, subarray);
} else if (channelSymbol instanceof BitfinexExecutedTradeSymbol) {
final ChannelCallbackHandler handler = new ExecutedTradeHandler();
handler.handleChannelData(this, channelSymbol, subarray);
} else {
logger.error("Unknown stream type: {}", channelSymbol);
}
}
Aggregations