Search in sources :

Example 6 with BarMerger

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

the class BarMegerTest method testTickMerger4.

/**
 * Test three tick merge with other timestamps
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 6000)
public void testTickMerger4() throws InterruptedException, IOException, ParseException {
    final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
    final CountDownLatch latch = new CountDownLatch(2);
    final BiConsumer<BitfinexCurrencyPair, Bar> tickConsumer = (s, t) -> {
        latch.countDown();
    };
    final BarMerger tickMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, tickConsumer);
    tickMerger.addNewPrice(parser.parse("01:01:23").getTime(), 1.0, 5.0);
    tickMerger.addNewPrice(parser.parse("01:01:33").getTime(), 2.0, 5.0);
    tickMerger.addNewPrice(parser.parse("02:02:53").getTime(), 2.0, 5.0);
    tickMerger.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 7 with BarMerger

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

the class BarMegerTest method testTickMerger3.

/**
 * Test three tick merge
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 6000)
public void testTickMerger3() throws InterruptedException, IOException, ParseException {
    final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
    final CountDownLatch latch = new CountDownLatch(2);
    final BiConsumer<BitfinexCurrencyPair, Bar> tickConsumer = (s, t) -> {
        latch.countDown();
    };
    final BarMerger tickMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, tickConsumer);
    tickMerger.addNewPrice(parser.parse("01:01:23").getTime(), 1.0, 5.0);
    tickMerger.addNewPrice(parser.parse("01:01:33").getTime(), 2.0, 5.0);
    tickMerger.addNewPrice(parser.parse("01:02:53").getTime(), 2.0, 5.0);
    tickMerger.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 8 with BarMerger

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

the class BarMegerTest method testEmptyTickMerger.

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

Example 9 with BarMerger

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

the class EMABot method registerTicker.

protected void registerTicker(final BitfinexApiBroker bitfinexApiBroker) throws InterruptedException, APIException {
    logger.info("Register ticker");
    for (final BitfinexCurrencyPair currency : tradedCurrencies) {
        tickMerger.put(currency, new BarMerger(currency, TIMEFRAME, (s, t) -> barDoneCallback(s, t)));
        final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(currency);
        bitfinexApiBroker.getQuoteManager().subscribeTicker(symbol);
        logger.info("Wait for ticker");
        while (!bitfinexApiBroker.isTickerActive(symbol)) {
            Thread.sleep(100);
        }
        bitfinexApiBroker.getQuoteManager().registerTickCallback(symbol, (s, c) -> handleTickCallback(s, c));
    }
}
Also used : TimeSeries(org.ta4j.core.TimeSeries) Arrays(java.util.Arrays) BitfinexTick(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexTick) Decimal(org.ta4j.core.Decimal) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) OrderType(org.ta4j.core.Order.OrderType) BitfinexCandlestickSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexCandlestickSymbol) EMAStrategy03(com.github.jnidzwetzki.cryptobot.strategy.EMAStrategy03) ArrayList(java.util.ArrayList) APIException(com.github.jnidzwetzki.bitfinex.v2.entity.APIException) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol) ExchangeOrder(com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder) QuoteManager(com.github.jnidzwetzki.bitfinex.v2.manager.QuoteManager) Map(java.util.Map) BitfinexClientFactory(com.github.jnidzwetzki.cryptobot.util.BitfinexClientFactory) Strategy(org.ta4j.core.Strategy) TradeState(com.github.jnidzwetzki.cryptobot.entity.TradeState) TradeStrategyFactory(com.github.jnidzwetzki.cryptobot.strategy.TradeStrategyFactory) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) Logger(org.slf4j.Logger) TradeDirection(com.github.jnidzwetzki.cryptobot.entity.TradeDirection) Collectors(java.util.stream.Collectors) Timeframe(com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe) Bar(org.ta4j.core.Bar) TimeUnit(java.util.concurrent.TimeUnit) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) List(java.util.List) Trade(com.github.jnidzwetzki.cryptobot.entity.Trade) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BarMerger(com.github.jnidzwetzki.cryptobot.util.BarMerger) BitfinexCurrencyPair(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair) BitfinexTickerSymbol(com.github.jnidzwetzki.bitfinex.v2.entity.symbol.BitfinexTickerSymbol)

Example 10 with BarMerger

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

the class BarMegerTest method testTickMerger2.

/**
 * Test two tick merge
 * @throws InterruptedException
 * @throws IOException
 * @throws ParseException
 */
@Test(timeout = 5000)
public void testTickMerger2() throws InterruptedException, IOException, ParseException {
    final SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
    final CountDownLatch latch = new CountDownLatch(1);
    final BiConsumer<BitfinexCurrencyPair, Bar> tickConsumer = (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 tickMerger = new BarMerger(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1, tickConsumer);
    tickMerger.addNewPrice(parser.parse("01:01:13").getTime(), 1.0, 5.0);
    tickMerger.addNewPrice(parser.parse("01:01:23").getTime(), 2.0, 5.0);
    tickMerger.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)

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