use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project crypto-bot by jnidzwetzki.
the class TestCapitalAllocation method testCapitalAllocationExchange3.
@Test
public void testCapitalAllocationExchange3() 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);
final CurrencyEntry entry3 = new CurrencyEntry(BitfinexCurrencyPair.XRP_USD, 1000, 990);
entries.put(BitfinexCurrencyPair.XRP_USD, entry3);
portfolioManager.calculatePositionSizes(entries);
// Max loss = 10, max capital allocation 50%
Assert.assertEquals(0.3, entry1.getPositionSize(), DELTA);
Assert.assertEquals(0.3, entry2.getPositionSize(), DELTA);
Assert.assertEquals(0.3, entry3.getPositionSize(), DELTA);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException 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.entity.APIException 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.entity.APIException 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();
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class IntegrationTest method testReconnect.
/**
* Test the session reconnect
* @throws APIException
* @throws InterruptedException
*/
@Test
public void testReconnect() throws APIException, InterruptedException {
final BitfinexApiBroker bitfinexClient = new BitfinexApiBroker();
bitfinexClient.connect();
final BitfinexTickerSymbol symbol = new BitfinexTickerSymbol(BitfinexCurrencyPair.BTC_USD);
final QuoteManager orderbookManager = bitfinexClient.getQuoteManager();
orderbookManager.subscribeTicker(symbol);
Thread.sleep(1000);
bitfinexClient.reconnect();
// Await at least 2 callbacks
final CountDownLatch latch = new CountDownLatch(2);
final BiConsumer<BitfinexTickerSymbol, BitfinexTick> callback = (c, o) -> {
latch.countDown();
};
orderbookManager.registerTickCallback(symbol, callback);
latch.await();
Assert.assertTrue(bitfinexClient.isTickerActive(symbol));
orderbookManager.unsubscribeTicker(symbol);
Assert.assertFalse(bitfinexClient.isTickerActive(symbol));
bitfinexClient.close();
}
Aggregations