use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair 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();
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair 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();
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair 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();
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair in project crypto-bot by jnidzwetzki.
the class TestCapitalAllocation method testCapitalAllocationExchange1.
@Test
public void testCapitalAllocationExchange1() throws APIException {
final PortfolioManager portfolioManager = buildPortfolioManager();
final Map<BitfinexCurrencyPair, CurrencyEntry> entries = new HashMap<>();
final CurrencyEntry entry1 = new CurrencyEntry(BitfinexCurrencyPair.BTC_USD, 1000, 990);
entries.put(BitfinexCurrencyPair.BTC_USD, entry1);
portfolioManager.calculatePositionSizes(entries);
// Max loss = 10, max capital allocation 50%
Assert.assertEquals(0.45, entry1.getPositionSize(), DELTA);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair in project crypto-bot by jnidzwetzki.
the class TestCapitalAllocation method testCapitalAllocationExchangeMaxPositionLoss1.
@Test
public void testCapitalAllocationExchangeMaxPositionLoss1() throws APIException {
final PortfolioManager portfolioManager = buildPortfolioManager();
final Map<BitfinexCurrencyPair, CurrencyEntry> entries = new HashMap<>();
final CurrencyEntry entry1 = new CurrencyEntry(BitfinexCurrencyPair.BTC_USD, 1000, 0);
entries.put(BitfinexCurrencyPair.BTC_USD, entry1);
portfolioManager.calculatePositionSizes(entries);
// Max loss = 10, max capital allocation 50%
Assert.assertEquals(0.045, entry1.getPositionSize(), DELTA);
}
Aggregations