Search in sources :

Example 1 with BarMerger

use of com.github.jnidzwetzki.cryptobot.util.BarMerger in project crypto-bot by jnidzwetzki.

the class BarMegerTest method testBarAlignment1.

/**
 * Test the alignment of the Bars
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 10000)
public void testBarAlignment1() throws InterruptedException, IOException, ParseException {
    final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
    final CountDownLatch latch = new CountDownLatch(3);
    final BiConsumer<BitfinexCurrencyPair, Bar> BarConsumer = (s, t) -> {
        Assert.assertTrue(t.getEndTime().getSecond() == 59);
        latch.countDown();
    };
    final BarMerger BarMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, BarConsumer);
    BarMerger.addNewPrice(parser.parse("01:01:23").getTime(), 1.0, 5.0);
    BarMerger.addNewPrice(parser.parse("01:02:33").getTime(), 2.0, 5.0);
    BarMerger.addNewPrice(parser.parse("02:03:53").getTime(), 2.0, 5.0);
    BarMerger.addNewPrice(parser.parse("22:22:53").getTime(), 2.0, 5.0);
    BarMerger.close();
    latch.await();
}
Also used : BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) CountDownLatch(java.util.concurrent.CountDownLatch) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BiConsumer(java.util.function.BiConsumer) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) Test(org.junit.Test) ParseException(java.text.ParseException) Assert(org.junit.Assert) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) Bar(org.ta4j.core.Bar) Bar(org.ta4j.core.Bar) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) CountDownLatch(java.util.concurrent.CountDownLatch) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 2 with BarMerger

use of com.github.jnidzwetzki.cryptobot.util.BarMerger in project crypto-bot by jnidzwetzki.

the class BarMegerTest method testBarAlignment2.

/**
 * Test the alignment of the Bars
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 10000)
public void testBarAlignment2() throws InterruptedException, IOException, ParseException {
    final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
    final CountDownLatch latch = new CountDownLatch(4);
    final BiConsumer<BitfinexCurrencyPair, Bar> BarConsumer = (s, t) -> {
        Assert.assertTrue(t.getEndTime().getMinute() == 14 || t.getEndTime().getMinute() == 29 || t.getEndTime().getMinute() == 44 || t.getEndTime().getMinute() == 59);
        Assert.assertEquals(59, t.getEndTime().getSecond());
        latch.countDown();
    };
    final BarMerger BarMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_15, BarConsumer);
    BarMerger.addNewPrice(parser.parse("01:01:00").getTime(), 1.0, 5.0);
    BarMerger.addNewPrice(parser.parse("02:41:33").getTime(), 2.0, 5.0);
    BarMerger.addNewPrice(parser.parse("10:33:11").getTime(), 2.0, 5.0);
    BarMerger.addNewPrice(parser.parse("22:22:53").getTime(), 2.0, 5.0);
    BarMerger.close();
    latch.await();
}
Also used : BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) CountDownLatch(java.util.concurrent.CountDownLatch) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BiConsumer(java.util.function.BiConsumer) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) Test(org.junit.Test) ParseException(java.text.ParseException) Assert(org.junit.Assert) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) Bar(org.ta4j.core.Bar) Bar(org.ta4j.core.Bar) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) CountDownLatch(java.util.concurrent.CountDownLatch) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 3 with BarMerger

use of com.github.jnidzwetzki.cryptobot.util.BarMerger in project crypto-bot by jnidzwetzki.

the class BarMegerTest method testBarMerger4.

/**
 * Test three Bar merge with other timestamps
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 6000)
public void testBarMerger4() throws InterruptedException, IOException, ParseException {
    final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
    final CountDownLatch latch = new CountDownLatch(2);
    final BiConsumer<BitfinexCurrencyPair, Bar> BarConsumer = (s, t) -> {
        latch.countDown();
    };
    final BarMerger BarMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, BarConsumer);
    BarMerger.addNewPrice(parser.parse("01:01:23").getTime(), 1.0, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:33").getTime(), 2.0, 5.0);
    BarMerger.addNewPrice(parser.parse("02:02:53").getTime(), 2.0, 5.0);
    BarMerger.close();
    latch.await();
}
Also used : BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) CountDownLatch(java.util.concurrent.CountDownLatch) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BiConsumer(java.util.function.BiConsumer) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) Test(org.junit.Test) ParseException(java.text.ParseException) Assert(org.junit.Assert) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) Bar(org.ta4j.core.Bar) Bar(org.ta4j.core.Bar) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) CountDownLatch(java.util.concurrent.CountDownLatch) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 4 with BarMerger

use of com.github.jnidzwetzki.cryptobot.util.BarMerger in project crypto-bot by jnidzwetzki.

the class BarMegerTest method testBarMerger2.

/**
 * Test two Bar merge
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 5000)
public void testBarMerger2() throws InterruptedException, IOException, ParseException {
    final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
    final CountDownLatch latch = new CountDownLatch(1);
    final BiConsumer<BitfinexCurrencyPair, Bar> BarConsumer = (s, t) -> {
        Assert.assertEquals(10, t.getVolume().doubleValue(), DELTA);
        Assert.assertEquals(1.0, t.getMinPrice().doubleValue(), DELTA);
        Assert.assertEquals(2.0, t.getMaxPrice().doubleValue(), DELTA);
        latch.countDown();
    };
    final BarMerger BarMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, BarConsumer);
    BarMerger.addNewPrice(parser.parse("01:01:13").getTime(), 1.0, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:23").getTime(), 2.0, 5.0);
    BarMerger.close();
    latch.await();
}
Also used : BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) CountDownLatch(java.util.concurrent.CountDownLatch) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BiConsumer(java.util.function.BiConsumer) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) Test(org.junit.Test) ParseException(java.text.ParseException) Assert(org.junit.Assert) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) Bar(org.ta4j.core.Bar) Bar(org.ta4j.core.Bar) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) CountDownLatch(java.util.concurrent.CountDownLatch) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 5 with BarMerger

use of com.github.jnidzwetzki.cryptobot.util.BarMerger in project crypto-bot by jnidzwetzki.

the class BarMegerTest method testBarMerger1.

/**
 * Test one Bar
 * @throws InterruptedException
 * @throws IOException
 */
@Test(timeout = 5000)
public void testBarMerger1() throws InterruptedException, IOException {
    final CountDownLatch latch = new CountDownLatch(1);
    final BiConsumer<BitfinexCurrencyPair, Bar> BarConsumer = (s, t) -> {
        latch.countDown();
    };
    final BarMerger BarMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, BarConsumer);
    BarMerger.addNewPrice(1000000, 1.0, 5.0);
    BarMerger.close();
    latch.await();
}
Also used : BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) CountDownLatch(java.util.concurrent.CountDownLatch) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BiConsumer(java.util.function.BiConsumer) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) Test(org.junit.Test) ParseException(java.text.ParseException) Assert(org.junit.Assert) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) Bar(org.ta4j.core.Bar) Bar(org.ta4j.core.Bar) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) CountDownLatch(java.util.concurrent.CountDownLatch) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) Test(org.junit.Test)

Aggregations

BarMerger (com.github.jnidzwetzki.cryptobot.util.BarMerger)19 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)16 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)16 Bar (org.ta4j.core.Bar)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 IOException (java.io.IOException)14 ParseException (java.text.ParseException)14 SimpleDateFormat (java.text.SimpleDateFormat)14 BiConsumer (java.util.function.BiConsumer)14 Assert (org.junit.Assert)14 Test (org.junit.Test)14 BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)2 APIException (com.github.jnidzwetzki.bitfinex.v2.entity.APIException)2 BitfinexTick (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick)2 BitfinexCandlestickSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol)2 BitfinexTickerSymbol (com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)2 BitfinexClientFactory (com.github.jnidzwetzki.cryptobot.util.BitfinexClientFactory)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2