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();
}
Aggregations