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