use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testOrderSubmissionFailed.
/**
* Test order submit failed
* @throws APIException
* @throws InterruptedException
*/
@Test(timeout = 10000)
public void testOrderSubmissionFailed() throws APIException, InterruptedException {
final String jsonString = "[0,\"n\",[null,\"on-req\",null,null,[null,null,1513970684865000,\"tBTCUSD\",null,null,0.001,0.001,\"EXCHANGE MARKET\",null,null,null,null,null,null,null,12940,null,null,null,null,null,null,0,null,null],null,\"ERROR\",\"Invalid order: minimum size for BTC/USD is 0.002\"]]";
final JSONArray jsonArray = new JSONArray(jsonString);
final CountDownLatch latch = new CountDownLatch(1);
final Consumer<ExchangeOrder> orderCallback = (e) -> {
Assert.assertEquals(ExchangeOrderState.STATE_ERROR, e.getState());
Assert.assertEquals(API_KEY, e.getApikey());
Assert.assertEquals(1513970684865000l, e.getCid());
Assert.assertEquals(BitfinexCurrencyPair.BTC_USD.toBitfinexString(), e.getSymbol());
latch.countDown();
};
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
bitfinexApiBroker.getOrderManager().registerCallback(orderCallback);
final NotificationHandler notificationHandler = new NotificationHandler();
notificationHandler.handleChannelData(bitfinexApiBroker, jsonArray);
latch.await();
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testCancelOrder.
/**
* Test the cancelation of an order
* @throws InterruptedException
* @throws APIException
*/
@Test(timeout = 60000)
public void testCancelOrder() throws APIException, InterruptedException {
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
final Runnable r = () -> {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
return;
}
final ExchangeOrder exchangeOrder = new ExchangeOrder();
exchangeOrder.setOrderId(12);
exchangeOrder.setState(ExchangeOrderState.STATE_CANCELED);
orderManager.updateOrder(exchangeOrder);
};
// Cancel event
(new Thread(r)).start();
orderManager.cancelOrderAndWaitForCompletion(12);
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testOrderChannelHandler1.
/**
* Test the order channel handler - single order
* @throws APIException
*/
@Test
public void testOrderChannelHandler1() throws APIException {
final String jsonString = "[0,\"on\",[6784335053,null,1514956504945000,\"tIOTUSD\",1514956505134,1514956505164,-24.175121,-24.175121,\"EXCHANGE STOP\",null,null,null,0,\"ACTIVE\",null,null,3.84,0,null,null,null,null,null,0,0,0]]";
final JSONArray jsonArray = new JSONArray(jsonString);
final OrderHandler orderHandler = new OrderHandler();
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
Assert.assertTrue(orderManager.getOrders().isEmpty());
orderHandler.handleChannelData(bitfinexApiBroker, jsonArray);
Assert.assertEquals(1, orderManager.getOrders().size());
}
use of com.github.jnidzwetzki.bitfinex.v2.entity.APIException 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.entity.APIException 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());
}
Aggregations