Search in sources :

Example 1 with PortfolioOrderManager

use of com.github.jnidzwetzki.cryptobot.PortfolioOrderManager 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)

Aggregations

BitfinexApiBroker (com.github.jnidzwetzki.bitfinex.v2.BitfinexApiBroker)1 PortfolioOrderManager (com.github.jnidzwetzki.cryptobot.PortfolioOrderManager)1 Trade (com.github.jnidzwetzki.cryptobot.entity.Trade)1 Session (org.hibernate.Session)1 Test (org.junit.Test)1