use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager in project crypto-bot by jnidzwetzki.
the class TestPersistence method testGetOpenTrades.
/**
* Test get open trades from order manager
*/
@Test
public void testGetOpenTrades() {
final BitfinexApiBroker apiBroker = Mockito.mock(BitfinexApiBroker.class);
final PortfolioOrderManager ordermanager = new PortfolioOrderManager(apiBroker);
Assert.assertTrue(ordermanager.getAllOpenTrades().isEmpty());
final Trade trade = new Trade("ABC", TradeDirection.LONG, BitfinexCurrencyPair.BTC_USD, 1);
trade.setTradeState(TradeState.CREATED);
final Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(trade);
session.getTransaction().commit();
Assert.assertTrue(ordermanager.getAllOpenTrades().isEmpty());
session.beginTransaction();
trade.setTradeState(TradeState.OPEN);
session.saveOrUpdate(trade);
session.getTransaction().commit();
session.beginTransaction();
Assert.assertEquals(1, ordermanager.getAllOpenTrades().size());
session.getTransaction().commit();
final Trade trade2 = new Trade("ABC", TradeDirection.LONG, BitfinexCurrencyPair.BTC_USD, 1);
trade2.setTradeState(TradeState.OPEN);
session.beginTransaction();
session.save(trade2);
session.getTransaction().commit();
session.beginTransaction();
Assert.assertEquals(2, ordermanager.getAllOpenTrades().size());
session.getTransaction().commit();
session.close();
}
use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testCancelOrderUnauth.
/**
* Test the cancelation of an order
* @throws InterruptedException
* @throws APIException
*/
@Test(expected = APIException.class)
public void testCancelOrderUnauth() throws APIException, InterruptedException {
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
Mockito.when(bitfinexApiBroker.getCapabilities()).thenReturn(ConnectionCapabilities.NO_CAPABILITIES);
final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
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 testOrderChannelHandler2.
/**
* Test the order channel handler - snapshot
* @throws APIException
*/
@Test
public void testOrderChannelHandler2() 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], [67843353243,null,1514956234945000,\"tBTCUSD\",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(2, orderManager.getOrders().size());
orderManager.clear();
Assert.assertTrue(orderManager.getOrders().isEmpty());
}
use of com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager in project bitfinex-v2-wss-api-java by jnidzwetzki.
the class OrderManagerTest method testOrderChannelHandler3.
/**
* Test the order channel handler - posclose order
* @throws APIException
*/
@Test
public void testOrderChannelHandler3() throws APIException {
final String jsonString = "[0,\"on\",[6827301913,null,null,\"tXRPUSD\",1515069803530,1515069803530,-60,-60,\"MARKET\",null,null,null,0,\"ACTIVE (note:POSCLOSE)\",null,null,0,3.2041,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 testPlaceOrderUnauth.
/**
* Test the placement of an order
* @throws InterruptedException
* @throws APIException
*/
@Test(expected = APIException.class)
public void testPlaceOrderUnauth() throws APIException, InterruptedException {
final BitfinexApiBroker bitfinexApiBroker = buildMockedBitfinexConnection();
Mockito.when(bitfinexApiBroker.getCapabilities()).thenReturn(ConnectionCapabilities.NO_CAPABILITIES);
final OrderManager orderManager = bitfinexApiBroker.getOrderManager();
final BitfinexOrder order = BitfinexOrderBuilder.create(BitfinexCurrencyPair.BCH_USD, BitfinexOrderType.MARKET, 12).build();
orderManager.placeOrderAndWaitUntilActive(order);
}
Aggregations