use of java.util.function.BiConsumer in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testRawOrderbookStream.
/**
* Test the raw orderbook stream
*/
@Test(timeout = 10000)
public void testRawOrderbookStream() {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
// Await at least 20 callbacks
final CountDownLatch latch = new CountDownLatch(20);
try {
bitfinexClient.connect();
final RawOrderbookConfiguration orderbookConfiguration = new RawOrderbookConfiguration(BitfinexCurrencyPair.BTC_USD);
final RawOrderbookManager rawOrderbookManager = bitfinexClient.getRawOrderbookManager();
final BiConsumer<RawOrderbookConfiguration, RawOrderbookEntry> callback = (c, o) -> {
Assert.assertTrue(o.getAmount().doubleValue() != 0);
Assert.assertTrue(o.getPrice().doubleValue() != 0);
Assert.assertTrue(o.getOrderId() >= 0);
Assert.assertTrue(o.toString().length() > 0);
latch.countDown();
};
rawOrderbookManager.registerOrderbookCallback(orderbookConfiguration, callback);
rawOrderbookManager.subscribeOrderbook(orderbookConfiguration);
latch.await();
rawOrderbookManager.unsubscribeOrderbook(orderbookConfiguration);
Assert.assertTrue(rawOrderbookManager.removeOrderbookCallback(orderbookConfiguration, callback));
Assert.assertFalse(rawOrderbookManager.removeOrderbookCallback(orderbookConfiguration, callback));
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of java.util.function.BiConsumer in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testTickerStream.
/**
* Test the tick stream
*/
@Test(timeout = 60000)
public void testTickerStream() {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
// Await at least 2 callbacks
final CountDownLatch latch = new CountDownLatch(2);
try {
bitfinexClient.connect();
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(BitfinexCurrencyPair.BTC_USD);
final QuoteManager orderbookManager = bitfinexClient.getQuoteManager();
final BiConsumer<BitfinexTickerSymbol, BitfinexTick> callback = (c, o) -> {
latch.countDown();
};
orderbookManager.registerTickCallback(symbol, callback);
orderbookManager.subscribeTicker(symbol);
latch.await();
Assert.assertTrue(bitfinexClient.isTickerActive(symbol));
orderbookManager.unsubscribeTicker(symbol);
Assert.assertFalse(bitfinexClient.isTickerActive(symbol));
Assert.assertTrue(orderbookManager.removeTickCallback(symbol, callback));
Assert.assertFalse(orderbookManager.removeTickCallback(symbol, callback));
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of java.util.function.BiConsumer in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testCandleStream.
/**
* Test the candle stream
*/
@Test(timeout = 10000)
public void testCandleStream() {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
// Await at least 10 callbacks
final CountDownLatch latch = new CountDownLatch(10);
try {
bitfinexClient.connect();
final BitfinexCandlestickSymbol symbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1);
final QuoteManager orderbookManager = bitfinexClient.getQuoteManager();
final BiConsumer<BitfinexCandlestickSymbol, BitfinexTick> callback = (c, o) -> {
latch.countDown();
};
orderbookManager.registerCandlestickCallback(symbol, callback);
orderbookManager.subscribeCandles(symbol);
latch.await();
orderbookManager.unsubscribeCandles(symbol);
Assert.assertTrue(orderbookManager.removeCandlestickCallback(symbol, callback));
Assert.assertFalse(orderbookManager.removeCandlestickCallback(symbol, callback));
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of java.util.function.BiConsumer in project arez by arez.
the class SpyEventProcessorTest method maintainNesting.
@Test
public void maintainNesting() throws Throwable {
final TestSpyEventProcessor processor = new TestSpyEventProcessor();
final ObserverCreatedEvent event = new ObserverCreatedEvent(new NullObserverInfo());
final AtomicInteger handleCallCount = new AtomicInteger();
final BiConsumer<SpyUtil.NestingDelta, ObserverCreatedEvent> handler = (delta, e) -> {
handleCallCount.incrementAndGet();
assertEquals(delta, SpyUtil.NestingDelta.NONE);
assertEquals(e, event);
};
processor.on(ObserverCreatedEvent.class, handler);
assertEquals(processor.getNestingDelta(event), SpyUtil.NestingDelta.NONE);
assertEquals(handleCallCount.get(), 0);
assertEquals(processor.getNestingLevel(), 0);
assertEquals(processor._handleUnhandledEventCallCount, 0);
processor.onSpyEvent(event);
assertEquals(handleCallCount.get(), 1);
assertEquals(processor.getNestingLevel(), 0);
assertEquals(processor._handleUnhandledEventCallCount, 0);
}
use of java.util.function.BiConsumer in project portfolio by buchen.
the class HelloBankPDFExtractor method addDividendTransaction.
@SuppressWarnings("nls")
private void addDividendTransaction() {
DocumentType type = new DocumentType("Geschäftsart: Ertrag", (context, lines) -> {
Pattern exchangeRatePattern = Pattern.compile("Devisenkurs: (?<exchangeRate>[\\d+,.]*) \\(\\d+.\\d+.\\d{4}+\\) [\\d+,.]* \\w{3}+ *");
for (String line : lines) {
Matcher matcher = exchangeRatePattern.matcher(line);
if (matcher.matches())
context.put("exchangeRate", matcher.group(1));
}
});
this.addDocumentTyp(type);
Block block = new Block("Geschäftsart: Ertrag");
type.addBlock(block);
BiConsumer<AccountTransaction, Map<String, String>> taxProcessor = (t, v) -> {
long tax = asAmount(v.get("tax"));
String currency = asCurrencyCode(v.get("currency"));
if (currency.equals(t.getCurrencyCode())) {
t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), tax)));
} else {
String exchangeRateString = type.getCurrentContext().get("exchangeRate");
if (exchangeRateString != null) {
BigDecimal exchangeRate = BigDecimal.ONE.divide(asExchangeRate(exchangeRateString), 10, BigDecimal.ROUND_HALF_UP);
if (currency.equals(t.getSecurity().getCurrencyCode())) {
long convertedTax = BigDecimal.valueOf(tax).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), convertedTax), Money.of(currency, tax), exchangeRate));
} else {
long convertedTax = BigDecimal.valueOf(tax).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
t.addUnit(new Unit(Unit.Type.TAX, Money.of(t.getCurrencyCode(), convertedTax)));
}
}
}
};
block.set(new Transaction<AccountTransaction>().subject(() -> {
AccountTransaction transaction = new AccountTransaction();
transaction.setType(AccountTransaction.Type.DIVIDENDS);
return transaction;
}).section("isin", "name", //
"currency").match(//
"Titel: (?<isin>\\S*) (?<name>.*)$").match("Dividende: [\\d+,.]* (?<currency>\\w{3}+) *").assign((t, v) -> t.setSecurity(getOrCreateSecurity(v))).section(//
"shares").match(//
"^(Abgang: )?(?<shares>[\\d+,.]*) Stk$").assign((t, v) -> t.setShares(asShares(v.get("shares")))).section("amount", "currency").match("Zu Gunsten .* (?<amount>[\\d+,.]*) (?<currency>\\w{3}+) *$").assign((t, v) -> {
t.setAmount(asAmount(v.get("amount")));
t.setCurrencyCode(asCurrencyCode(v.get("currency")));
}).section(//
"date").match(//
"Valuta (?<date>\\d+.\\d+.\\d{4}+)").assign((t, v) -> t.setDateTime(asDate(v.get("date")))).section("tax", //
"currency").optional().match("Inkassoprovision: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match("Umsatzsteuer: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match(//
"Fremde Spesen: -(?<tax>[\\d+,.-]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match(//
"KESt Ausländische Dividende: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("tax", //
"currency").optional().match(//
"Quellensteuer[^.]*: -(?<tax>[\\d+,.]*) (?<currency>\\w{3}+) *").assign(taxProcessor).section("gross", //
"currency").optional().match("Bruttoertrag: (?<gross>[\\d+,.-]*) (?<currency>\\w{3}+) *").assign((t, v) -> {
long gross = asAmount(v.get("gross"));
String currency = asCurrencyCode(v.get("currency"));
if (currency.equals(t.getSecurity().getCurrencyCode())) {
String exchangeRateString = type.getCurrentContext().get("exchangeRate");
if (exchangeRateString != null) {
BigDecimal exchangeRate = BigDecimal.ONE.divide(asExchangeRate(exchangeRateString), 10, BigDecimal.ROUND_HALF_UP);
long convertedGross = BigDecimal.valueOf(gross).multiply(exchangeRate).setScale(0, BigDecimal.ROUND_HALF_UP).longValue();
t.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of(t.getCurrencyCode(), convertedGross), Money.of(currency, gross), exchangeRate));
}
}
}).wrap(TransactionItem::new));
}
Aggregations