use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class CommandsTest method testCommandsJSON.
/**
* Call all commands and check for excepion
* @throws CommandException
*/
@Test
public void testCommandsJSON() throws CommandException {
final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.EXCHANGE_STOP, 2).build();
final BitfinexCandlestickSymbol candleSymbol = new BitfinexCandlestickSymbol(BitfinexCurrencyPair.BCH_USD, Timeframe.HOUR_1);
final OrderbookConfiguration orderbookConfiguration = new OrderbookConfiguration(BitfinexCurrencyPair.BCH_USD, OrderBookPrecision.P0, OrderBookFrequency.F0, 50);
final RawOrderbookConfiguration rawOrderbookConfiguration = new RawOrderbookConfiguration(BitfinexCurrencyPair.BAT_BTC);
final List<AbstractAPICommand> commands = Arrays.asList(new AuthCommand(), new CancelOrderCommand(123), new CancelOrderGroupCommand(1), new OrderCommand(order), new PingCommand(), new SubscribeCandlesCommand(candleSymbol), new SubscribeTickerCommand(new BitfinexTickerSymbol(BitfinexCurrencyPair.BCH_USD)), new SubscribeTradesCommand(new BitfinexExecutedTradeSymbol(BitfinexCurrencyPair.BAT_BTC)), new SubscribeOrderbookCommand(orderbookConfiguration), new SubscribeRawOrderbookCommand(rawOrderbookConfiguration), new UnsubscribeChannelCommand(12));
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
for (final AbstractAPICommand command : commands) {
final String commandValue = command.getCommand(bitfinexApiBroker);
Assert.assertNotNull(commandValue);
Assert.assertTrue(commandValue.length() > 10);
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class HeartbeatManagerTest method testConnectWhenDisconnected.
@Test(timeout = 30000)
public void testConnectWhenDisconnected() throws Exception {
// Events
// * Disconnect websocket from heartbeat
// * Disconnect from bitfinex API reconnect method
// * Reconnect on bitfinex api
final CountDownLatch connectLatch = new CountDownLatch(3);
// Count down the latch on method call
final Answer<Void> answer = new Answer<Void>() {
public Void answer(final InvocationOnMock invocation) throws Throwable {
connectLatch.countDown();
return null;
}
};
final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
final HeartbeatThread heartbeatThreadRunnable = new HeartbeatThread(bitfinexApiBroker);
final WebsocketClientEndpoint websocketClientEndpoint = Mockito.mock(WebsocketClientEndpoint.class);
Mockito.when(websocketClientEndpoint.isConnected()).thenReturn(connectLatch.getCount() == 0);
Mockito.when(bitfinexApiBroker.getWebsocketEndpoint()).thenReturn(websocketClientEndpoint);
Mockito.doAnswer(answer).when(bitfinexApiBroker).reconnect();
Mockito.doAnswer(answer).when(websocketClientEndpoint).close();
final Thread heartbeatThread = new Thread(heartbeatThreadRunnable);
try {
heartbeatThread.start();
connectLatch.await();
} catch (Exception e) {
// Should not happen
throw e;
} finally {
heartbeatThread.interrupt();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class HeartbeatManagerTest method testHeartbeatHandler.
/**
* Test the heartbeart handler
* @throws APIException
*/
@Test
public void testHeartbeatHandler() throws APIException {
final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
final HeartbeatHandler handler = new HeartbeatHandler();
handler.handleChannelData(bitfinexApiBroker, null);
Mockito.verify(bitfinexApiBroker, Mockito.times(1)).updateConnectionHeartbeat();
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testWalletsOnUnauthClient.
/**
* Try to fetch wallets on an unauthenticated connection
*/
@Test
public void testWalletsOnUnauthClient() throws APIException {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
try {
bitfinexClient.connect();
Assert.assertFalse(bitfinexClient.isAuthenticated());
try {
bitfinexClient.getWalletManager().getWallets();
// Should not happen
Assert.assertTrue(false);
} catch (APIException e) {
return;
}
} catch (Exception e) {
// Should not happen
e.printStackTrace();
Assert.assertTrue(false);
} finally {
bitfinexClient.close();
}
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testAuthFailed.
/**
* Test auth failed
* @throws APIException
*/
@Test(expected = APIException.class, timeout = 10000)
public void testAuthFailed() throws APIException {
final String KEY = "key";
final String SECRET = "secret";
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker(KEY, SECRET);
Assert.assertEquals(KEY, bitfinexClient.getApiKey());
Assert.assertEquals(SECRET, bitfinexClient.getApiSecret());
Assert.assertFalse(bitfinexClient.isAuthenticated());
bitfinexClient.connect();
// Should not be reached
Assert.assertTrue(false);
bitfinexClient.close();
}
Aggregations