use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CandlestickHandlerTest method testCandlestickUpdateAndNotify.
/**
* Test the parsing of one candlestick
* @throws APIException
*/
@Test
public void testCandlestickUpdateAndNotify() throws APIException {
final String callbackValue = "[15134900000,15996,15997,16000,15980,318.5139342]";
final JSONArray jsonArray = new JSONArray(callbackValue);
final BitfinexCandlestickSymbol symbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1);
final ExecutorService executorService = Executors.newFixedThreadPool(10);
final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
Mockito.when(bitfinexApiBroker.getExecutorService()).thenReturn(executorService);
final QuoteManager tickerManager = new QuoteManager(bitfinexApiBroker);
Mockito.when(bitfinexApiBroker.getQuoteManager()).thenReturn(tickerManager);
final AtomicInteger counter = new AtomicInteger(0);
tickerManager.registerCandlestickCallback(symbol, (s, c) -> {
counter.incrementAndGet();
Assert.assertEquals(symbol, s);
Assert.assertEquals(15996, c.getOpen().doubleValue(), DELTA);
Assert.assertEquals(15997, c.getClose().doubleValue(), DELTA);
Assert.assertEquals(16000, c.getHigh().doubleValue(), DELTA);
Assert.assertEquals(15980, c.getLow().doubleValue(), DELTA);
Assert.assertEquals(318.5139342, c.getVolume().doubleValue(), DELTA);
});
final CandlestickHandler candlestickHandler = new CandlestickHandler();
candlestickHandler.handleChannelData(bitfinexApiBroker, symbol, jsonArray);
Assert.assertEquals(1, counter.get());
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CandlestickHandlerTest method testCandlestickSnapshotUpdateAndNotify.
/**
* Test the parsing of a candlestick snapshot
* @throws APIException
*/
@Test
public void testCandlestickSnapshotUpdateAndNotify() throws APIException {
final String callbackValue = "[[15134900000,15996,15997,16000,15980,318.5139342],[15135100000,15899,15996,16097,15890,1137.180342268]]";
final JSONArray jsonArray = new JSONArray(callbackValue);
final BitfinexCandlestickSymbol symbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BTC_USD, Timeframe.MINUTES_1);
final ExecutorService executorService = Executors.newFixedThreadPool(10);
final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
Mockito.when(bitfinexApiBroker.getExecutorService()).thenReturn(executorService);
final QuoteManager tickerManager = new QuoteManager(bitfinexApiBroker);
Mockito.when(bitfinexApiBroker.getQuoteManager()).thenReturn(tickerManager);
final AtomicInteger counter = new AtomicInteger(0);
tickerManager.registerCandlestickCallback(symbol, (s, c) -> {
Assert.assertEquals(symbol, s);
final int counterValue = counter.getAndIncrement();
if (counterValue == 0) {
Assert.assertEquals(15996, c.getOpen().doubleValue(), DELTA);
Assert.assertEquals(15997, c.getClose().doubleValue(), DELTA);
Assert.assertEquals(16000, c.getHigh().doubleValue(), DELTA);
Assert.assertEquals(15980, c.getLow().doubleValue(), DELTA);
Assert.assertEquals(318.5139342, c.getVolume().doubleValue(), DELTA);
} else if (counterValue == 1) {
Assert.assertEquals(15899, c.getOpen().doubleValue(), DELTA);
Assert.assertEquals(15996, c.getClose().doubleValue(), DELTA);
Assert.assertEquals(16097, c.getHigh().doubleValue(), DELTA);
Assert.assertEquals(15890, c.getLow().doubleValue(), DELTA);
Assert.assertEquals(1137.180342268, c.getVolume().doubleValue(), DELTA);
} else {
throw new IllegalArgumentException("Illegal call, expected 2 candlesticks");
}
});
final CandlestickHandler candlestickHandler = new CandlestickHandler();
candlestickHandler.handleChannelData(bitfinexApiBroker, symbol, jsonArray);
Assert.assertEquals(2, counter.get());
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CommandsCallbackTest method testSubscribeAndUnsubscribeCallback.
/**
* Test the subscribed callback
* @throws APIException
*/
@Test
public void testSubscribeAndUnsubscribeCallback() throws APIException {
final String jsonString = "{\"event\":\"subscribed\",\"channel\":\"ticker\",\"chanId\":30,\"symbol\":\"tNEOUSD\",\"pair\":\"NEOUSD\"}";
final JSONObject jsonObject = new JSONObject(jsonString);
final BitfinexApiBroker bitfinexApiBroker = new BitfinexApiBroker();
Assert.assertTrue(bitfinexApiBroker.getFromChannelSymbolMap(30) == null);
final SubscribedCallback subscribedCallback = new SubscribedCallback();
subscribedCallback.handleChannelData(bitfinexApiBroker, jsonObject);
Assert.assertTrue(bitfinexApiBroker.getFromChannelSymbolMap(30) instanceof BitfinexTickerSymbol);
final String unsubscribedJsonString = "{\"event\":\"unsubscribed\",\"status\":\"OK\",\"chanId\":30}";
final JSONObject jsonUnsubscribedObject = new JSONObject(unsubscribedJsonString);
final UnsubscribedCallback unsubscribedCallback = new UnsubscribedCallback();
unsubscribedCallback.handleChannelData(bitfinexApiBroker, jsonUnsubscribedObject);
Assert.assertTrue(bitfinexApiBroker.getFromChannelSymbolMap(30) == null);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CommandsCallbackTest method testAuthCommandCallback2.
/**
* Test the auth callback
* @throws APIException
*/
@Test
public void testAuthCommandCallback2() throws APIException {
final String authCallback = "{\"event\":\"auth\",\"status\":\"FAILED\",\"chanId\":0,}";
final BitfinexApiBroker bitfinexApiBroker = Mockito.spy(BitfinexApiBroker.class);
final JSONObject jsonObject = new JSONObject(authCallback);
final AuthCallbackHandler authCallbackHandler = new AuthCallbackHandler();
Assert.assertFalse(bitfinexApiBroker.isAuthenticated());
authCallbackHandler.handleChannelData(bitfinexApiBroker, jsonObject);
Assert.assertFalse(bitfinexApiBroker.isAuthenticated());
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CommandsCallbackTest method testConnectionHeartbeat.
/**
* Test the pong callback
* @throws APIException
*/
@Test
public void testConnectionHeartbeat() throws APIException {
final String jsonString = "{\"event\":\"pong\",\"ts\":1515023251265}";
final JSONObject jsonObject = new JSONObject(jsonString);
final BitfinexApiBroker bitfinexApiBroker = new BitfinexApiBroker();
final long oldHeartbeat = bitfinexApiBroker.getLastHeatbeat().get();
final ConnectionHeartbeatCallback connectionHeartbeatCallback = new ConnectionHeartbeatCallback();
connectionHeartbeatCallback.handleChannelData(bitfinexApiBroker, jsonObject);
final long newHeartbeat = bitfinexApiBroker.getLastHeatbeat().get();
Assert.assertTrue(oldHeartbeat < newHeartbeat);
}
Aggregations