use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testPlaceOrder.
/**
* Test the placement of an order
* @throws InterruptedException
* @throws APIException
*/
@Test(timeout = 60000)
public void testPlaceOrder() throws APIException, InterruptedException {
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
Mockito.when(bitfinexApiBroker.isAuthenticated()).thenReturn(true);
final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.MARKET, 1).build();
final Runnable r = () -> {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
return;
}
final ExchangeOrder exchangeOrder = new ExchangeOrder();
exchangeOrder.setCid(order.getCid());
exchangeOrder.setState(ExchangeOrderState.STATE_ACTIVE);
orderManager.updateOrder(exchangeOrder);
};
// Cancel event
(new Thread(r)).start();
orderManager.placeOrderAndWaitUntilActive(order);
}
use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager 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.manager.OrderManager 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.manager.OrderManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest 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 OrderManager orderManager = new OrderManager(bitfinexApiBroker);
Mockito.when(bitfinexApiBroker.getOrderManager()).thenReturn(orderManager);
return bitfinexApiBroker;
}
Aggregations