use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair in project crypto-bot by jnidzwetzki.
the class TestCapitalAllocation method testCapitalAllocationExchange2.
@Test
public void testCapitalAllocationExchange2() 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);
final CurrencyEntry entry2 = new CurrencyEntry(BitfinexCurrencyPair.IOT_USD, 1000, 990);
entries.put(BitfinexCurrencyPair.IOT_USD, entry2);
portfolioManager.calculatePositionSizes(entries);
// Max loss = 10, max capital allocation 50%
Assert.assertEquals(0.45, entry1.getPositionSize(), DELTA);
Assert.assertEquals(0.45, entry2.getPositionSize(), DELTA);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair 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.bitfinex.v2.entity.BitfinexCurrencyPair 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.bitfinex.v2.entity.BitfinexCurrencyPair in project crypto-bot by jnidzwetzki.
the class EMABot method updateScreen.
public synchronized void updateScreen() {
if (!UPDATE_SCREEN) {
return;
}
final QuoteManager tickerManager = bitfinexApiBroker.getQuoteManager();
CliTools.clearScreen();
System.out.println("");
System.out.println("==========");
System.out.println("Last ticks");
System.out.println("==========");
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
final String symbol = currency.toBitfinexString();
final BitfinexTickerSymbol tickerSymbol = new BitfinexTickerSymbol(currency);
System.out.println(symbol + " " + tickerManager.getLastTick(tickerSymbol));
}
System.out.println("");
System.out.println("==========");
System.out.println("Last bars");
System.out.println("==========");
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
System.out.println(currency + " " + timeSeries.get(currency).getLastBar());
}
System.out.println("");
System.out.println("==========");
System.out.println("P/L");
System.out.println("==========");
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
final String symbol = currency.toBitfinexString();
final BitfinexTickerSymbol tickerSymbol = new BitfinexTickerSymbol(currency);
final Trade trade = getOpenTrade(currency);
if (trade != null) {
final double priceIn = trade.getExpectedPriceOpen();
final double currentPrice = tickerManager.getLastTick(tickerSymbol).getClose();
System.out.println(symbol + ": price in " + priceIn + " / " + (currentPrice - priceIn));
}
}
System.out.println("");
System.out.println("==========");
System.out.println("Trades");
System.out.println("==========");
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
final String symbol = currency.toBitfinexString();
final List<Trade> lastTrades = trades.get(currency);
if (lastTrades == null) {
continue;
}
lastTrades.sort((t1, t2) -> Long.compare(t2.getTid(), t1.getTid()));
final List<Trade> lastTwoTrades = lastTrades.subList(Math.max(lastTrades.size() - 2, 0), lastTrades.size());
for (final Trade trade : lastTwoTrades) {
System.out.println(symbol + " " + trade);
}
}
try {
System.out.println("");
System.out.println("==========");
System.out.println("Orders");
System.out.println("==========");
final List<ExchangeOrder> orders = new ArrayList<>(bitfinexApiBroker.getOrderManager().getOrders());
orders.sort((o1, o2) -> Long.compare(o2.getCid(), o1.getCid()));
final List<ExchangeOrder> lastOrders = orders.subList(Math.max(orders.size() - 3, 0), orders.size());
for (final ExchangeOrder order : lastOrders) {
System.out.println(order);
}
} catch (APIException e) {
logger.error("Got eception while reading wallets", e);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair in project crypto-bot by jnidzwetzki.
the class EMABot method createStrategies.
/**
* Init the trading stretegies
*/
private void createStrategies() {
for (final BitfinexCurrencyPair currency : tradedCurrencies) {
TradeStrategyFactory strategyFactory = new EMAStrategy03(5, 12, 40, timeSeries.get(currency));
final Strategy strategy = strategyFactory.getStrategy();
strategies.put(currency, strategy);
}
}
Aggregations