Search in sources :

Example 6 with BitfinexTick

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class IntegrationTest method testReconnect.

/**
 * Test the session reconnect
 * @throws APIException
 * @throws InterruptedException
 */
@Test
public void testReconnect() throws APIException, InterruptedException {
    final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
    bitfinexClient.connect();
    final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(BitfinexCurrencyPair.BTC_USD);
    final QuoteManager orderbookManager = bitfinexClient.getQuoteManager();
    orderbookManager.subscribeTicker(symbol);
    Thread.sleep(1000);
    bitfinexClient.reconnect();
    // Await at least 2 callbacks
    final CountDownLatch latch = new CountDownLatch(2);
    final BiConsumer<BitfinexTickerSymbol, BitfinexTick> callback = (c, o) -> {
        latch.countDown();
    };
    orderbookManager.registerTickCallback(symbol, callback);
    latch.await();
    Assert.assertTrue(bitfinexClient.isTickerActive(symbol));
    orderbookManager.unsubscribeTicker(symbol);
    Assert.assertFalse(bitfinexClient.isTickerActive(symbol));
    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) BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) QuoteManager(com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 7 with BitfinexTick

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class BitfinexTickTest method testCompareTo.

@Test
public void testCompareTo() {
    final BitfinexTick tick1 = new BitfinexTick(210, 11d, 16d, 18d, 10d, 100d);
    final BitfinexTick tick2 = new BitfinexTick(213, 12d, 15d, 18d, 12d, 100d);
    Assert.assertTrue(tick1.compareTo(tick2) < 0);
    Assert.assertTrue(tick2.compareTo(tick1) > 0);
    Assert.assertTrue(tick1.compareTo(tick1) == 0);
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) Test(org.junit.Test)

Example 8 with BitfinexTick

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class BitfinexTickTest method testToString.

@Test
public void testToString() {
    final BitfinexTick tick1 = new BitfinexTick(213, 12d, 15d, 18d, 12d, 100d);
    Assert.assertTrue(tick1.toString().length() > 10);
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) Test(org.junit.Test)

Example 9 with BitfinexTick

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class BitfinexTickTest method testEquals.

@Test
public void testEquals() {
    final BitfinexTick tick1 = new BitfinexTick(210, new BigDecimal(11), new BigDecimal(16), new BigDecimal(18), new BigDecimal(10), new BigDecimal(45));
    final BitfinexTick tick2 = new BitfinexTick(213, new BigDecimal(12), new BigDecimal(15), new BigDecimal(18), new BigDecimal(10));
    final BitfinexTick tick3 = new BitfinexTick(213, new BigDecimal(12), new BigDecimal(15), new BigDecimal(18), new BigDecimal(10));
    Assert.assertEquals(tick2, tick3);
    Assert.assertEquals(tick2.hashCode(), tick3.hashCode());
    Assert.assertEquals(tick3.hashCode(), tick3.hashCode());
    Assert.assertFalse(tick1.equals(tick2));
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 10 with BitfinexTick

use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick in project bitfinex-v2-wss-api-java by jnidzwetzki.

the class BitfinexTickTest method testGetter.

@Test
public void testGetter() {
    final BitfinexTick tick1 = new BitfinexTick(210, 11, 16, 18, 10, 45);
    final BitfinexTick tick2 = new BitfinexTick(210, new BigDecimal(11), new BigDecimal(16), new BigDecimal(18), new BigDecimal(10));
    Assert.assertEquals(210, tick1.getTimestamp());
    Assert.assertEquals(11, tick1.getOpen().doubleValue(), DELTA);
    Assert.assertEquals(16, tick1.getClose().doubleValue(), DELTA);
    Assert.assertEquals(18, tick1.getHigh().doubleValue(), DELTA);
    Assert.assertEquals(10, tick1.getLow().doubleValue(), DELTA);
    Assert.assertEquals(45, tick1.getVolume().doubleValue(), DELTA);
    Assert.assertEquals(BitfinexTick.INVALID_VOLUME, tick2.getVolume());
}
Also used : BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)12 Test (org.junit.Test)7 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)5 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)5 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)5 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)4 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)4 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)4 BigDecimal (java.math.BigDecimal)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 BiConsumer (java.util.function.BiConsumer)4 ExecutedTrade (com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade)3 OrderBookFrequency (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookFrequency)3 OrderBookPrecision (com.github.jnidzwetzki.bitfinex.v2.entity.OrderBookPrecision)3 OrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookConfiguration)3 OrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.OrderbookEntry)3 RawOrderbookConfiguration (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookConfiguration)3 RawOrderbookEntry (com.github.jnidzwetzki.bitfinex.v2.entity.RawOrderbookEntry)3 BitfinexExecutedTradeSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexExecutedTradeSymbol)3 OrderbookManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderbookManager)3