Search in sources :

Example 1 with OrderManager

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();
}
Also used : Trade(com.github.jnidzwetzki.cryptobot.entity.Trade) BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) PortfolioOrderManager(com.github.jnidzwetzki.cryptobot.PortfolioOrderManager) Session(org.hibernate.Session) Test(org.junit.Test)

Example 2 with OrderManager

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);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) OrderManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager) Test(org.junit.Test)

Example 3 with OrderManager

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());
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONArray(org.json.JSONArray) OrderManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager) OrderHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler) Test(org.junit.Test)

Example 4 with OrderManager

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());
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) JSONArray(org.json.JSONArray) OrderManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager) OrderHandler(com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler) Test(org.junit.Test)

Example 5 with OrderManager

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);
}
Also used : BitfinexApiBroker(com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker) BitfinexOrder(com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder) OrderManager(com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager) Test(org.junit.Test)

Aggregations

BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)9 OrderManager (com.github.jnidzwetzki.bitfinex.v2.manager.OrderManager)8 Test (org.junit.Test)8 OrderHandler (com.github.jnidzwetzki.bitfinex.v2.callback.api.OrderHandler)3 JSONArray (org.json.JSONArray)3 BitfinexOrder (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexOrder)2 ExchangeOrder (com.github.jnidzwetzki.bitfinex.v2.entity.ExchangeOrder)2 PortfolioOrderManager (com.github.jnidzwetzki.cryptobot.PortfolioOrderManager)1 Trade (com.github.jnidzwetzki.cryptobot.entity.Trade)1 ExecutorService (java.util.concurrent.ExecutorService)1 Session (org.hibernate.Session)1