BarBuilder implements IBarBuilder { protected BigDecimal getValue( ILevel1Quote quote ) { if( isCurrency ) { if( quote.containsType(QuoteType.BID) ) { lastBid = quote.getValue(QuoteType.BID); } if( quote.containsType(QuoteType.ASK ) ) { lastAsk = quote.getValue(QuoteType.ASK); } if( lastBid.doubleValue() > 0 && lastAsk.doubleValue() > 0 ) { return new BigDecimal(lastAsk.doubleValue() - ((lastAsk.doubleValue()-lastBid.doubleValue())/2.0)); } else { return BigDecimal.ZERO; } } else { if( showProperty == IHistoricalDataProvider.ShowProperty.MIDPOINT ) { if( quote.containsType(QuoteType.MIDPOINT) ) { return quote.getValue(QuoteType.MIDPOINT ); } else { return BigDecimal.ZERO; } } else { return quote.getValue(QuoteType.LAST); } } } protected  BarBuilder();  BarBuilder(SchedulerFactory schedulerFactory, RealtimeBarRequest request, IHistoricalDataProvider historicalDataProvider); void quoteRecieved(ILevel1Quote quote); @Override void addBarListener(RealtimeBarListener listener); @Override void removeBarListener(RealtimeBarListener listener); void buildBarAndFireEvents(); int getListenerCount(); void stop();  }
@Test public void testGetValue_Currency() { testBarBuilder.isCurrency = true; Ticker ticker = new GenericTicker("XYZ"); ZonedDateTime now = ZonedDateTime.now(); Map<QuoteType,BigDecimal> quoteValues = new HashMap<>(); Level1Quote quote = new Level1Quote(ticker, now, quoteValues); assertEquals(BigDecimal.ZERO, testBarBuilder.getValue(quote)); quoteValues.put(QuoteType.BID, BigDecimal.ONE); quote = new Level1Quote(ticker, now, quoteValues); assertEquals(BigDecimal.ZERO, testBarBuilder.getValue(quote)); quoteValues.clear(); testBarBuilder.lastBid = BigDecimal.ZERO; testBarBuilder.lastAsk = BigDecimal.ZERO; quoteValues.put(QuoteType.ASK, BigDecimal.TEN); quote = new Level1Quote(ticker, now, quoteValues); assertEquals(BigDecimal.ZERO, testBarBuilder.getValue(quote)); testBarBuilder.lastBid = BigDecimal.ZERO; testBarBuilder.lastAsk = BigDecimal.ZERO; quoteValues.put(QuoteType.BID, BigDecimal.ONE); quote = new Level1Quote(ticker, now, quoteValues); assertEquals(new BigDecimal(5.5), testBarBuilder.getValue(quote)); }
@Test public void testGetValue_NotCurrency_Midpoint() { testBarBuilder.isCurrency = false; testBarBuilder.showProperty = IHistoricalDataProvider.ShowProperty.MIDPOINT; Ticker ticker = new GenericTicker("XYZ"); ZonedDateTime now = ZonedDateTime.now(); Map<QuoteType,BigDecimal> quoteValues = new HashMap<>(); Level1Quote quote = new Level1Quote(ticker, now, quoteValues); assertEquals(BigDecimal.ZERO, testBarBuilder.getValue(quote)); quoteValues.put(QuoteType.MIDPOINT, BigDecimal.ONE); assertEquals(BigDecimal.ONE, testBarBuilder.getValue(quote)); }
@Test public void testGetValue_NotCurrency_NotMidpoint() { testBarBuilder.isCurrency = false; testBarBuilder.showProperty = IHistoricalDataProvider.ShowProperty.TRADES; Ticker ticker = new GenericTicker("XYZ"); ZonedDateTime now = ZonedDateTime.now(); Map<QuoteType,BigDecimal> quoteValues = new HashMap<>(); quoteValues.put(QuoteType.LAST, BigDecimal.ONE); Level1Quote quote = new Level1Quote(ticker, now, quoteValues); assertEquals(BigDecimal.ONE, testBarBuilder.getValue(quote)); }