use of com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testExecutedTradesStream.
/**
* Test executed trades stream
*/
@Test(timeout = 60000)
public void testExecutedTradesStream() {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
// Await at least 2 callbacks
final CountDownLatch latch = new CountDownLatch(2);
try {
bitfinexClient.connect();
final BitfinexExecutedTradeSymbol symbol = new BitfinexExecutedTradeSymbol(BitfinexCurrencyPair.BTC_USD);
final QuoteManager executedTradeManager = bitfinexClient.getQuoteManager();
final BiConsumer<BitfinexExecutedTradeSymbol, ExecutedTrade> callback = (c, o) -> {
latch.countDown();
};
executedTradeManager.registerExecutedTradeCallback(symbol, callback);
executedTradeManager.subscribeExecutedTrades(symbol);
latch.await();
executedTradeManager.unsubscribeExecutedTrades(symbol);
Assert.assertTrue(executedTradeManager.removeExecutedTradeCallback(symbol, callback));
Assert.assertFalse(executedTradeManager.removeExecutedTradeCallback(symbol, callback));
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.ExecutedTrade in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class ExecutedTradeHandler method handleEntry.
/**
* Handle a new executed trade entry
* @param bitfinexApiBroker
* @param symbol
* @param jsonArray
*/
private void handleEntry(final BitfinexApiBroker bitfinexApiBroker, final BitfinexExecutedTradeSymbol symbol, final JSONArray jsonArray) {
final ExecutedTrade executedTrade = new ExecutedTrade();
final long id = jsonArray.getNumber(0).longValue();
executedTrade.setId(id);
final long timestamp = jsonArray.getNumber(1).longValue();
executedTrade.setTimestamp(timestamp);
final BigDecimal amount = jsonArray.getBigDecimal(2);
executedTrade.setAmount(amount);
// Funding or Currency
if (jsonArray.optNumber(4) != null) {
final BigDecimal rate = jsonArray.getBigDecimal(3);
executedTrade.setRate(rate);
final int period = jsonArray.getNumber(4).intValue();
executedTrade.setPeriod(period);
} else {
final BigDecimal price = jsonArray.getBigDecimal(3);
executedTrade.setPrice(price);
}
bitfinexApiBroker.getQuoteManager().handleExecutedTradeEntry(symbol, executedTrade);
}
Aggregations