コード例 #1
0
  @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);
  }
コード例 #2
0
  @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));
  }
コード例 #3
0
ファイル: ZoneRules.java プロジェクト: CodeingBoy/Java8CN
 /**
  * Gets the amount of daylight savings in use for the specified instant in this zone.
  *
  * <p>This provides access to historic information on how the amount of daylight savings has
  * changed over time. This is the difference between the standard offset and the actual offset.
  * Typically the amount is zero during winter and one hour during summer. Time-zones are
  * second-based, so the nanosecond part of the duration will be zero.
  *
  * <p>This default implementation calculates the duration from the {@link
  * #getOffset(java.time.Instant) actual} and {@link #getStandardOffset(java.time.Instant)
  * standard} offsets.
  *
  * @param instant the instant to find the daylight savings for, not null, but null may be ignored
  *     if the rules have a single offset for all instants
  * @return the difference between the standard and actual offset, not null
  */
 public Duration getDaylightSavings(Instant instant) {
   if (savingsInstantTransitions.length == 0) {
     return Duration.ZERO;
   }
   ZoneOffset standardOffset = getStandardOffset(instant);
   ZoneOffset actualOffset = getOffset(instant);
   return Duration.ofSeconds(actualOffset.getTotalSeconds() - standardOffset.getTotalSeconds());
 }
コード例 #4
0
ファイル: ZoneRules.java プロジェクト: CodeingBoy/Java8CN
  private Object getOffsetInfo(LocalDateTime dt) {
    if (savingsInstantTransitions.length == 0) {
      return standardOffsets[0];
    }
    // check if using last rules
    if (lastRules.length > 0
        && dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
      ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
      Object info = null;
      for (ZoneOffsetTransition trans : transArray) {
        info = findOffsetInfo(dt, trans);
        if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
          return info;
        }
      }
      return info;
    }

    // using historic rules
    int index = Arrays.binarySearch(savingsLocalTransitions, dt);
    if (index == -1) {
      // before first transition
      return wallOffsets[0];
    }
    if (index < 0) {
      // switch negative insert position to start of matched range
      index = -index - 2;
    } else if (index < savingsLocalTransitions.length - 1
        && savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
      // handle overlap immediately following gap
      index++;
    }
    if ((index & 1) == 0) {
      // gap or overlap
      LocalDateTime dtBefore = savingsLocalTransitions[index];
      LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
      ZoneOffset offsetBefore = wallOffsets[index / 2];
      ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
      if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
        // gap
        return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
      } else {
        // overlap
        return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
      }
    } else {
      // normal (neither gap or overlap)
      return wallOffsets[index / 2 + 1];
    }
  }
コード例 #5
0
ファイル: ZoneRules.java プロジェクト: CodeingBoy/Java8CN
 private int findYear(long epochSecond, ZoneOffset offset) {
   // inline for performance
   long localSecond = epochSecond + offset.getTotalSeconds();
   long localEpochDay = Math.floorDiv(localSecond, 86400);
   return LocalDate.ofEpochDay(localEpochDay).getYear();
 }