@Test public void testPlaceMOCOrders() { String corrId = "123"; int longSize = 100; int shortSize = 200; ZonedDateTime currentDateTime = ZonedDateTime.of(2016, 3, 3, 5, 5, 1, 0, ZoneId.systemDefault()); ZonedDateTime orderTime = ZonedDateTime.now(); strategy.ibClient = mockIbClient; doReturn(corrId).when(strategy).getUUID(); doReturn(longSize).when(strategy).getOrderSize(longTicker); doReturn(shortSize).when(strategy).getOrderSize(shortTicker); doReturn(orderTime).when(strategy).getNextBusinessDay(currentDateTime); when(mockIbClient.getNextOrderId()).thenReturn("100", "101", "102", "103", "104", "105"); TradeOrder expectedLongOrder = new TradeOrder("100", longTicker, longSize, TradeDirection.BUY); expectedLongOrder.setType(TradeOrder.Type.MARKET_ON_CLOSE); expectedLongOrder.setReference("EOD-Pair-Strategy:123:Entry:Long*"); TradeOrder expectedLongExitOrder = new TradeOrder("101", longTicker, longSize, TradeDirection.SELL); expectedLongExitOrder.setType(TradeOrder.Type.MARKET_ON_OPEN); expectedLongExitOrder.setGoodAfterTime(orderTime); expectedLongExitOrder.setReference("EOD-Pair-Strategy:123:Exit:Long*"); expectedLongOrder.addChildOrder(expectedLongExitOrder); TradeOrder expectedShortOrder = new TradeOrder("102", shortTicker, shortSize, TradeDirection.SELL_SHORT); expectedShortOrder.setType(TradeOrder.Type.MARKET_ON_CLOSE); expectedShortOrder.setReference("EOD-Pair-Strategy:123:Entry:Short*"); TradeOrder expectedShortExitOrder = new TradeOrder("103", shortTicker, shortSize, TradeDirection.BUY_TO_COVER); expectedShortExitOrder.setType(TradeOrder.Type.MARKET_ON_OPEN); expectedShortExitOrder.setGoodAfterTime(orderTime); expectedShortExitOrder.setReference("EOD-Pair-Strategy:123:Exit:Short*"); expectedShortOrder.addChildOrder(expectedShortExitOrder); strategy.placeMOCOrders(longTicker, shortTicker, currentDateTime); verify(mockIbClient).placeOrder(expectedLongOrder); verify(mockIbClient).placeOrder(expectedShortOrder); }
@Test public void testStart() { TradeOrder order = new TradeOrder("123", longTicker, 100, TradeDirection.SELL); List<TradeOrder> openOrders = new ArrayList<>(); openOrders.add(order); when(mockIbClient.getOpenOrders()).thenReturn(openOrders); doReturn(true).when(strategy).checkOpenOrders(openOrders, strategy.longShortPairMap); strategy.start(propFile); verify(mockIbClient).addOrderStatusListener(mockReportGenerator); verify(mockIbClient) .subscribeLevel1(eq(new StockTicker("QQQ")), any(Level1QuoteListener.class)); verify(mockIbClient) .subscribeLevel1(eq(new StockTicker("SPY")), any(Level1QuoteListener.class)); verify(mockIbClient) .subscribeLevel1(eq(new StockTicker("DIA")), any(Level1QuoteListener.class)); verify(mockIbClient) .subscribeLevel1(eq(new StockTicker("IWM")), any(Level1QuoteListener.class)); }