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();
}
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();
}
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();
}
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));
}
}
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();
}
Aggregations