InteractiveBrokersClient implements InteractiveBrokersClientInterface { @Override public List<BarData> requestHistoricalData(Ticker ticker, Date endDateTime, int duration, BarData.LengthUnit durationLengthUnit, int barSize, BarData.LengthUnit barSizeUnit, IHistoricalDataProvider.ShowProperty whatToShow, boolean useRTH) throws IOException { return historicalDataProvider.requestHistoricalData(ticker, endDateTime, duration, durationLengthUnit, barSize, barSizeUnit, whatToShow, useRTH); } protected  InteractiveBrokersClient(String host, int port, int clientId); static InteractiveBrokersClientInterface getInstance(String host, int port, int clientId); @Override void connect(); @Override void disconnect(); @Override void subscribeLevel1( Ticker ticker, Level1QuoteListener listener ); @Override void subscribeMarketDepth( Ticker ticker, Level2QuoteListener listener ); @Override void unsubscribeLevel1( Ticker ticker, Level1QuoteListener listener ); @Override void unsubscribeMarketDepth( Ticker ticker, Level2QuoteListener listener ); @Override void addBrokerErrorListener(BrokerErrorListener listener); @Override void removeBrokerErrorListener(BrokerErrorListener listener); @Override void useDelayedData( boolean b ); @Override String getHost(); @Override int getPort(); @Override int getClientId(); @Override void placeOrder(TradeOrder order); @Override void addOrderStatusListener(OrderEventListener listener); @Override String getNextOrderId(); @Override List<TradeOrder> getOpenOrders(); @Override List<BarData> requestHistoricalData(Ticker ticker, Date endDateTime, int duration, BarData.LengthUnit durationLengthUnit, int barSize, BarData.LengthUnit barSizeUnit, IHistoricalDataProvider.ShowProperty whatToShow, boolean useRTH); @Override List<BarData> requestHistoricalData(Ticker ticker, int duration, BarData.LengthUnit lengthUnit, int barSize, BarData.LengthUnit barSizeUnit, IHistoricalDataProvider.ShowProperty showProperty ); @Override List<Position> getOpenPositions(); @Override void subscribeRealtimeBar(RealtimeBarRequest request, RealtimeBarListener listener ); static void setMockInteractiveBrokersClient(InteractiveBrokersClientInterface mockClient, String host, int port, int clientId);  }
@Test public void testRequestGetHistoricalData() { List<BarData> barData = new ArrayList<>(); barData.add(new BarData()); Ticker ticker = new StockTicker("ABC"); int duration = 1; BarData.LengthUnit unit = BarData.LengthUnit.DAY; int barSize = 1; BarData.LengthUnit sizeUnit = BarData.LengthUnit.HOUR; IHistoricalDataProvider.ShowProperty showProperty = IHistoricalDataProvider.ShowProperty.TRADES; when(mockHistoricalDataProvider.requestHistoricalData(ticker, duration, unit, barSize, sizeUnit, showProperty, true)).thenReturn(barData); assertEquals(barData, client.requestHistoricalData(ticker, duration, unit, barSize, sizeUnit, showProperty)); }
@Test public void testRequestGetHistoricalData_OverloadedMethod() throws IOException { List<BarData> barData = new ArrayList<>(); barData.add(new BarData()); Ticker ticker = new StockTicker("ABC"); int duration = 1; BarData.LengthUnit unit = BarData.LengthUnit.DAY; int barSize = 1; BarData.LengthUnit sizeUnit = BarData.LengthUnit.HOUR; IHistoricalDataProvider.ShowProperty showProperty = IHistoricalDataProvider.ShowProperty.TRADES; Date startDate = new Date(); when(mockHistoricalDataProvider.requestHistoricalData(ticker, startDate, duration, unit, barSize, sizeUnit, showProperty, true)).thenReturn(barData); assertEquals(barData, client.requestHistoricalData(ticker, startDate, duration, unit, barSize, sizeUnit, showProperty, true)); }