Search in sources :

Example 16 with BarMerger

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

the class BarMegerTest method testEmptyBarMerger.

/**
 * Test close Barmerger without any Bar
 * @throws IOException
 */
public void testEmptyBarMerger() throws IOException {
    final BarMerger BarMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, (s, t) -> {
    });
    BarMerger.close();
}
Also used : BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger)

Example 17 with BarMerger

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

the class BarMegerTest method testBarMergerMinMax.

/**
 * Test Bar merger min max
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 6000)
public void testBarMergerMinMax() 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(1.0, t.getMinPrice().doubleValue(), DELTA);
        Assert.assertEquals(8.0, t.getMaxPrice().doubleValue(), DELTA);
        Assert.assertEquals(3.0, t.getOpenPrice().doubleValue(), DELTA);
        Assert.assertEquals(4.5, t.getClosePrice().doubleValue(), DELTA);
        latch.countDown();
    };
    final BarMerger BarMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, BarConsumer);
    BarMerger.addNewPrice(parser.parse("01:01:01").getTime(), 3.0, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:02").getTime(), 2.0, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:03").getTime(), 8.0, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:04").getTime(), 1.5, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:05").getTime(), 2.5, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:06").getTime(), 1.0, 5.0);
    BarMerger.addNewPrice(parser.parse("01:01:07").getTime(), 4.5, 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 18 with BarMerger

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

the class BarMegerTest method testBarMerger3.

/**
 * Test three Bar merge
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 6000)
public void testBarMerger3() 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("01: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 19 with BarMerger

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

the class Main method loadDataFromFile.

protected void loadDataFromFile() throws FileNotFoundException, IOException {
    try (final BufferedReader br = new BufferedReader(new FileReader(new File(FILENAME)));
        final BarMerger tickMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_15, (s, t) -> timeSeries.addBar(t))) {
        String line = null;
        while ((line = br.readLine()) != null) {
            final String[] parts = line.split(",");
            final long timestamp = Long.parseLong(parts[0]);
            final double price = Double.parseDouble(parts[1]);
            final double volume = Double.parseDouble(parts[2]);
            if (timestamp < 1451606400) {
                continue;
            }
            // if(timestamp > 1483228800) {
            // continue;
            // }
            tickMerger.addNewPrice(TimeUnit.SECONDS.toMillis(timestamp), price, volume);
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) File(java.io.File)

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