@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 testCheckOpenOrders_HappyPath() { List<TradeOrder> orders = new ArrayList<>(); TradeOrder order = new TradeOrder("123", new StockTicker("ABC"), 10, TradeDirection.SELL); order.setType(TradeOrder.Type.MARKET_ON_CLOSE); orders.add(order); Map<Ticker, Ticker> tickerMap = new HashMap<>(); tickerMap.put(new StockTicker("ABC"), new StockTicker("XYZ")); assertTrue(strategy.checkOpenOrders(orders, tickerMap)); }