use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class PositionTest method testPositionHandlerUpdate.
/**
* Test the position handler
* @throws APIException
*/
@Test
public void testPositionHandlerUpdate() throws APIException {
final String jsonString = "[0,\"pu\",[\"tETHUSD\",\"ACTIVE\",0.14,713.78,-0.00330012,0,null,null,null,null]]";
final JSONArray jsonArray = new JSONArray(jsonString);
final PositionHandler positionHandler = new PositionHandler();
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
Assert.assertTrue(bitfinexApiBroker.getPositionManager().getPositions().isEmpty());
positionHandler.handleChannelData(bitfinexApiBroker, jsonArray);
Assert.assertEquals(1, bitfinexApiBroker.getPositionManager().getPositions().size());
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class PositionTest method testPositionHandlerSnapshot.
/**
* Test the position handler
* @throws APIException
*/
@Test
public void testPositionHandlerSnapshot() throws APIException {
final String jsonString = "[0,\"ps\",[[\"tETHUSD\",\"ACTIVE\",0.14,713.78,-0.00330012,0,null,null,null,null], [\"tBTCUSD\",\"ACTIVE\",0.14,713.78,-0.00330012,0,null,null,null,null]]]";
final JSONArray jsonArray = new JSONArray(jsonString);
final PositionHandler positionHandler = new PositionHandler();
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
Assert.assertTrue(bitfinexApiBroker.getPositionManager().getPositions().isEmpty());
positionHandler.handleChannelData(bitfinexApiBroker, jsonArray);
Assert.assertEquals(2, bitfinexApiBroker.getPositionManager().getPositions().size());
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class PositionTest method buildMockedBitfinexConnection.
/**
* Build a mocked bitfinex connection
* @return
*/
private BitfinexApiBroker buildMockedBitfinexConnection() {
final ExecutorService executorService = Executors.newFixedThreadPool(10);
final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
Mockito.when(bitfinexApiBroker.getExecutorService()).thenReturn(executorService);
final PositionManager positionManager = new PositionManager(executorService);
Mockito.when(bitfinexApiBroker.getPositionManager()).thenReturn(positionManager);
return bitfinexApiBroker;
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class TradeManagerTest method testTradeChannelHandler2.
/**
* Test the trade channel handler
* @throws APIException
* @throws InterruptedException
*/
@Test(timeout = 10000)
public void testTradeChannelHandler2() throws APIException, InterruptedException {
final String jsonString = "[0,\"tu\",[106655593,\"tBTCUSD\",1512247319827,5691690918,-0.002,10894,\"EXCHANGE MARKET\",10894,-1,-0.0392184,\"USD\"]]";
final JSONArray jsonArray = new JSONArray(jsonString);
final TradeHandler tradeHandler = new TradeHandler();
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
final CountDownLatch latch = new CountDownLatch(1);
bitfinexApiBroker.getTradeManager().registerCallback((t) -> {
try {
Assert.assertFalse(t.isExecuted());
Assert.assertEquals(106655593, t.getId());
Assert.assertEquals(BitfinexCurrencyPair.BTC_USD, t.getCurrency());
Assert.assertEquals(1512247319827l, t.getMtsCreate());
Assert.assertEquals(5691690918l, t.getOrderId());
Assert.assertEquals(-0.002, t.getExecAmount().doubleValue(), DELTA);
Assert.assertEquals(10894, t.getExecPrice().doubleValue(), DELTA);
Assert.assertEquals(BitfinexOrderType.EXCHANGE_MARKET, t.getOrderType());
Assert.assertEquals(10894, t.getOrderPrice().doubleValue(), DELTA);
Assert.assertFalse(t.isMaker());
Assert.assertEquals(-0.0392184, t.getFee().doubleValue(), DELTA);
Assert.assertEquals("USD", t.getFeeCurrency());
Assert.assertTrue(t.toString().length() > 0);
} catch (Throwable e) {
e.printStackTrace();
throw e;
}
latch.countDown();
});
tradeHandler.handleChannelData(bitfinexApiBroker, jsonArray);
latch.await();
}
use of com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class TradeManagerTest method buildMockedBitfinexConnection.
/**
* Build a mocked bitfinex connection
* @return
*/
private BitfinexApiBroker buildMockedBitfinexConnection() {
final ExecutorService executorService = Executors.newFixedThreadPool(10);
final BitfinexApiBroker bitfinexApiBroker = Mockito.mock(BitfinexApiBroker.class);
Mockito.when(bitfinexApiBroker.getExecutorService()).thenReturn(executorService);
Mockito.when(bitfinexApiBroker.getApiKey()).thenReturn(API_KEY);
Mockito.when(bitfinexApiBroker.isAuthenticated()).thenReturn(true);
Mockito.when(bitfinexApiBroker.getCapabilities()).thenReturn(ConnectionCapabilities.ALL_CAPABILITIES);
final TradeManager tradeManager = new TradeManager(bitfinexApiBroker);
Mockito.when(bitfinexApiBroker.getTradeManager()).thenReturn(tradeManager);
return bitfinexApiBroker;
}
Aggregations