@Test public void testbuildBarDataSizeString_Days() { assertEquals("1 day", HistoricalDataUtils.buildBarDataSizeString(1, LengthUnit.DAY)); try { HistoricalDataUtils.buildBarDataSizeString(2, LengthUnit.DAY); fail(); } catch (InvalidBarSizeException ex) { // this should happen } }
@Test public void testbuildBarDataSizeString_Seconds() { assertEquals("1 sec", HistoricalDataUtils.buildBarDataSizeString(1, LengthUnit.SECOND)); assertEquals("5 secs", HistoricalDataUtils.buildBarDataSizeString(5, LengthUnit.SECOND)); assertEquals("15 secs", HistoricalDataUtils.buildBarDataSizeString(15, LengthUnit.SECOND)); assertEquals("30 secs", HistoricalDataUtils.buildBarDataSizeString(30, LengthUnit.SECOND)); try { HistoricalDataUtils.buildBarDataSizeString(31, LengthUnit.SECOND); fail(); } catch (InvalidBarSizeException ex) { // this should happen } }
@Test public void testShowPropertyToString() { assertEquals("ASK", HistoricalDataUtils.showPropertyToString(ShowProperty.ASK)); assertEquals("BID", HistoricalDataUtils.showPropertyToString(ShowProperty.BID)); assertEquals("MIDPOINT", HistoricalDataUtils.showPropertyToString(ShowProperty.MIDPOINT)); assertEquals("TRADES", HistoricalDataUtils.showPropertyToString(ShowProperty.TRADES)); try { HistoricalDataUtils.showPropertyToString(null); fail(); } catch (IllegalStateException ex) { // this should happen } }
@Test public void testBuildDurationString() { try { HistoricalDataUtils.buildDurationString(1, LengthUnit.TICK); fail(); } catch (IllegalStateException ex) { // this should happen } assertEquals("1 S", HistoricalDataUtils.buildDurationString(1, LengthUnit.SECOND)); try { HistoricalDataUtils.buildDurationString(1, LengthUnit.MINUTE); fail(); } catch (IllegalStateException ex) { // this should happen. } try { HistoricalDataUtils.buildDurationString(1, LengthUnit.HOUR); fail(); } catch (IllegalStateException ex) { // this should happen } assertEquals("1 D", HistoricalDataUtils.buildDurationString(1, LengthUnit.DAY)); assertEquals("1 W", HistoricalDataUtils.buildDurationString(1, LengthUnit.WEEK)); assertEquals("1 M", HistoricalDataUtils.buildDurationString(1, LengthUnit.MONTH)); assertEquals("1 Y", HistoricalDataUtils.buildDurationString(1, LengthUnit.YEAR)); }
@Test public void testBuildBarData() { int requestId = 1; GregorianCalendar cal = new GregorianCalendar(); LocalDateTime date = LocalDateTime.ofInstant(cal.getTime().toInstant(), ZoneId.systemDefault()); double open = 1; double high = 2; double low = 0.5; double close = 1.5; int volume = 100; int count = 1; double wap = 1.0; boolean hasGaps = true; HistoricalData data = new HistoricalData(requestId, cal, open, high, low, close, volume, count, wap, hasGaps); BarData bar = HistoricalDataUtils.buildBarData(data); assertEquals(close, bar.getClose(), 0); assertEquals(open, bar.getOpen(), 0); assertEquals(high, bar.getHigh(), 0); assertEquals(low, bar.getLow(), 0); assertEquals(volume, bar.getVolume()); assertEquals(date, bar.getDateTime()); }
@Test public void testBuildBarDataSizeString_InvalidSize() { try { HistoricalDataUtils.buildBarDataSizeString(1, LengthUnit.WEEK); fail(); } catch (InvalidBarSizeException ex) { // this should happen } }
@Test public void testbuildBarDataSizeString_Minutes() { assertEquals("1 min", HistoricalDataUtils.buildBarDataSizeString(1, LengthUnit.MINUTE)); assertEquals("2 mins", HistoricalDataUtils.buildBarDataSizeString(2, LengthUnit.MINUTE)); assertEquals("5 mins", HistoricalDataUtils.buildBarDataSizeString(5, LengthUnit.MINUTE)); assertEquals("15 mins", HistoricalDataUtils.buildBarDataSizeString(15, LengthUnit.MINUTE)); assertEquals("30 mins", HistoricalDataUtils.buildBarDataSizeString(30, LengthUnit.MINUTE)); try { HistoricalDataUtils.buildBarDataSizeString(31, LengthUnit.MINUTE); fail(); } catch (InvalidBarSizeException ex) { // this should happen } }