Search in sources :

Example 1 with OrderbookEntry

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();
    }
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) OrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry) OrderBookPrecision(com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookPrecision) Test(org.junit.Test) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) OrderbookManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager) OrderBookFrequency(com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookFrequency) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) RawOrderbookManager(com.github.jnidzwetzki.bitfinex.v2.manager.RawOrderbookManager) QuoteManager(com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager) RawOrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry) BiConsumer(java.util.function.BiConsumer) ExecutedTrade(com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade) Assert(org.junit.Assert) BitfinexExecutedTradeSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) OrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration) RawOrderbookConfiguration(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration) OrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry) RawOrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry) CountDownLatch(java.util.concurrent.CountDownLatch) OrderbookManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager) RawOrderbookManager(com.github.jnidzwetzki.bitfinex.v2.manager.RawOrderbookManager) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) Test(org.junit.Test)

Example 2 with OrderbookEntry

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);
}
Also used : OrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry) BigDecimal(java.math.BigDecimal)

Example 3 with 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);
}
Also used : RawOrderbookEntry(com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry) BigDecimal(java.math.BigDecimal)

Aggregations

OrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry)2 RawOrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry)2 BigDecimal (java.math.BigDecimal)2 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)1 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)1 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)1 ExecutedTrade (com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade)1 OrderBookFrequency (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookFrequency)1 OrderBookPrecision (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookPrecision)1 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)1 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)1 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)1 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)1 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)1 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)1 OrderbookManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager)1 QuoteManager (com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager)1 RawOrderbookManager (com.github.jnidzwetzki.bitfinex.v2.manager.RawOrderbookManager)1 CountDownLatch (java.util.concurrent.CountDownLatch)1