@Test public void testQuoteReceived_AllPricesInitialized_OrdersNotPlaced_AfterTradeTime() { ZonedDateTime local = ZonedDateTime.of(2015, 6, 15, 0, 0, 0, 0, ZoneId.systemDefault()); ZoneOffset offset = local.getOffset(); ZonedDateTime zdt = ZonedDateTime.of(2015, 6, 15, 21, 50, 0, 0, ZoneId.of("Z")); System.out.println("Offset: " + offset.getTotalSeconds() / 3600); int hour = strategy.timeToPlaceOrders.getHour() + (-offset.getTotalSeconds() / (3600)); zdt = zdt.withHour(hour); zdt = zdt.plusMinutes(1); ILevel1Quote mockQuote = mock(ILevel1Quote.class); strategy.longShortPairMap.put(longTicker, shortTicker); when(mockQuote.getType()).thenReturn(QuoteType.LAST); when(mockQuote.getTicker()).thenReturn(longTicker); when(mockQuote.getValue()).thenReturn(BigDecimal.ONE); when(mockQuote.getTimeStamp()).thenReturn(zdt); doReturn(true).when(strategy).setAllPricesInitialized(); doNothing() .when(strategy) .placeMOCOrders(any(Ticker.class), any(Ticker.class), any(ZonedDateTime.class)); strategy.ordersPlaced = false; strategy.quoteRecieved(mockQuote); assertTrue(strategy.ordersPlaced); verify(strategy).setAllPricesInitialized(); verify(strategy).placeMOCOrders(longTicker, shortTicker, zdt); }
@Test public void testQuoteReceived_AllPricesInitialized_OrdersNotPlaced_IsBeforeTradeTime() { ZonedDateTime local = ZonedDateTime.of(2015, 6, 15, 0, 0, 0, 0, ZoneId.systemDefault()); ZoneOffset offset = local.getOffset(); ZonedDateTime zdt = ZonedDateTime.of(2015, 6, 15, 20, 30, 0, 0, ZoneId.of("Z")); System.out.println("Offset: " + offset.getTotalSeconds() / 3600); int hour = strategy.timeToPlaceOrders.getHour() + (-offset.getTotalSeconds() / (3600)); System.out.println("Offset hour: " + hour); zdt = zdt.withHour(hour); ILevel1Quote mockQuote = mock(ILevel1Quote.class); Ticker ticker = new StockTicker("ABC"); when(mockQuote.getType()).thenReturn(QuoteType.LAST); when(mockQuote.getTicker()).thenReturn(ticker); when(mockQuote.getValue()).thenReturn(BigDecimal.ONE); when(mockQuote.getTimeStamp()).thenReturn(zdt); doReturn(true).when(strategy).setAllPricesInitialized(); strategy.ordersPlaced = false; strategy.quoteRecieved(mockQuote); assertFalse(strategy.ordersPlaced); verify(strategy).setAllPricesInitialized(); verify(strategy, never()) .placeMOCOrders(any(Ticker.class), any(Ticker.class), any(ZonedDateTime.class)); }
@Test public void testQuoteRecieved_NotLast() { ILevel1Quote mockQuote = mock(ILevel1Quote.class); when(mockQuote.getType()).thenReturn(QuoteType.VOLUME); strategy.quoteRecieved(mockQuote); verify(strategy, never()).setAllPricesInitialized(); verify(mockQuote, never()).getTimeStamp(); }
@Test public void testQuoteReceived_NotAllPricesInitialized_OrdersNotPlaced() { ZonedDateTime zdt = ZonedDateTime.of(2015, 6, 15, 15, 30, 0, 0, ZoneId.of("Z")); ILevel1Quote mockQuote = mock(ILevel1Quote.class); Ticker ticker = new StockTicker("ABC"); when(mockQuote.getType()).thenReturn(QuoteType.LAST); when(mockQuote.getTicker()).thenReturn(ticker); when(mockQuote.getValue()).thenReturn(BigDecimal.ONE); when(mockQuote.getTimeStamp()).thenReturn(zdt); doReturn(false).when(strategy).setAllPricesInitialized(); strategy.ordersPlaced = false; strategy.quoteRecieved(mockQuote); assertFalse(strategy.ordersPlaced); verify(strategy).setAllPricesInitialized(); verify(strategy, never()) .placeMOCOrders(any(Ticker.class), any(Ticker.class), any(ZonedDateTime.class)); }