IBQuoteEngine extends AbstractIBQuoteEngine { @Override public synchronized void subscribeLevel1(Ticker ticker, Level1QuoteListener listener) { super.subscribeLevel1(ticker, listener); Integer quoteId = tickerMap.get(ticker); if (quoteId == null) { quoteId = ++nextQuoteId; tickerMap.put(ticker, quoteId); idToTickerMap.put(quoteId, ticker); Contract contract = ContractBuilderFactory.getContractBuilder(ticker).buildContract(ticker); List<TagValue> list = new ArrayList<>(); list.add(new TagValue("XYZ","XYZ")); ibConnection.reqMktData(nextQuoteId, contract, "", false, list); } if (closeQuoteMap.get(ticker) != null) { listener.quoteRecieved(closeQuoteMap.get(ticker)); } if (openQuoteMap.get(ticker) != null) { listener.quoteRecieved(openQuoteMap.get(ticker)); } } IBQuoteEngine(IBSocket ibSocket); @Override boolean isConnected(); void tickSize(int tickerId, int field, int size); void tickPrice(int tickerId, int field, double price, int canAutoExecute); void updateMktDepth(int tickerId, int position, int operation, int side, double price, int size); void updateMktDepth2(int tickerId, int position, String marketMaker, int operation, int side, double price, int size); void error(Exception e); void error(String str); void error(int id, int errorCode, String errorMsg); @Override void subscribeMarketDepth(Ticker ticker, Level2QuoteListener listener); @Override void unsubscribeMarketDepth(Ticker ticker, Level2QuoteListener listener); @Override synchronized void subscribeLevel1(Ticker ticker, Level1QuoteListener listener); @Override void unsubscribeLevel1(Ticker ticker, Level1QuoteListener listener); Date getServerTime(); void startEngine(Properties props); void stopEngine(); void startEngine(); boolean started(); IBSocket getIbSocket(); String getName(); void setName(String name); @Override void fireLevel1Quote(ILevel1Quote quote); @Override void useDelayedData(boolean useDelayed);  }
@Test @Ignore public void testSubscribeLevel1() { final EClientSocket mockSocketInterface = mockery.mock(EClientSocket.class); final IBConnectionInterface mockConnectionInterface = mockery.mock(IBConnectionInterface.class); final Level1QuoteListener mockQuoteListener = mockery.mock(Level1QuoteListener.class); final Ticker ticker = new StockTicker("LUT"); final int requestId = 1; final Contract contract = ContractBuilderFactory.getContractBuilder(ticker).buildContract(ticker); final List<TagValue> list = new ArrayList<>(); list.add(new TagValue("XYZ", "XYZ")); fail(); }
@Test public void testSubscribeLevel1_ClosePriceExists() { Level1QuoteListener listener = Mockito.mock(Level1QuoteListener.class); ILevel1Quote quote = Mockito.mock(ILevel1Quote.class); Ticker ticker = new StockTicker("abc"); ibQuoteEngine.closeQuoteMap.put(ticker, quote); ibQuoteEngine.tickerMap.put(ticker, 1); ibQuoteEngine.subscribeLevel1(ticker, listener); verify(listener).quoteRecieved(quote); }
@Test public void testSubscribeLevel1_OpenPriceExists() { Level1QuoteListener listener = Mockito.mock(Level1QuoteListener.class); ILevel1Quote quote = Mockito.mock(ILevel1Quote.class); Ticker ticker = new StockTicker("abc"); ibQuoteEngine.openQuoteMap.put(ticker, quote); ibQuoteEngine.tickerMap.put(ticker, 1); ibQuoteEngine.subscribeLevel1(ticker, listener); verify(listener).quoteRecieved(quote); }