EODTradingStrategy implements Level1QuoteListener, OrderEventListener, BrokerErrorListener { protected boolean checkOpenOrders(List<TradeOrder> orders, Map<Ticker,Ticker> tickers) { if( orders.isEmpty() ) { return false; } for( TradeOrder order : orders ) { if(order.getType() == TradeOrder.Type.MARKET_ON_CLOSE) { for( Ticker ticker : tickers.keySet()) { if(order.getTicker().equals(ticker)) { return true; } } } } return false; }  void start(String propFile); synchronized void placeMOCOrders(Ticker longTicker, Ticker shortTicker, ZonedDateTime lastReportedTime); @Override void orderEvent(OrderEvent event); @Override void quoteRecieved(ILevel1Quote quote); ZonedDateTime getNextBusinessDay(ZonedDateTime date); @Override void brokerErrorFired(BrokerError error); static void main(String[] args);  }
@Test public void testCheckOpenOrders_OrderMapEmpty() { assertFalse(strategy.checkOpenOrders(new ArrayList<>(), new HashMap<>())); }
@Test public void testCheckOpenOrders_NoMocOrders() { List<TradeOrder> orders = new ArrayList<>(); orders.add(new TradeOrder("123", new StockTicker("ABC"), 10, TradeDirection.SELL)); assertFalse(strategy.checkOpenOrders(orders, new HashMap<>())); }
@Test public void testCheckOpenOrders_MocOrdersDontMatchTickers() { 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("AAA"), new StockTicker("XYZ")); assertFalse(strategy.checkOpenOrders(orders, tickerMap)); }
@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)); }