Package com.barchart.feed.base.bar.api

Examples of com.barchart.feed.base.bar.api.MarketDoBar


      final MarketTradeSequencing sequencing, final PriceValue price,
      final SizeValue size, final TimeValue time, final TimeValue date) {

    final MarketBarType barType = session == EXTENDED ? CURRENT_EXT
        : CURRENT;
    final MarketDoBar bar = loadBar(barType.field);

    // XXX this is disabled to force compatibility with ddf2
    // if (bar.get(BAR_TIME).compareTo(time) > 0) {
    // log.error("ignoring past trade");
    // return;
    // }

    eventAdd(barType.event);

    // Reset current bar if session day changes
    final TimeValue prevDate = bar.get(TRADE_DATE);

    if (session == DEFAULT && !prevDate.isNull() && !date.equals(prevDate)) {

      log.debug("New day code: old=" + prevDate + "; new=" + date);

      bar.set(MarketBarField.OPEN, price);
      bar.set(MarketBarField.HIGH, price);
      bar.set(MarketBarField.LOW, price);
      bar.set(MarketBarField.INTEREST, size);
      bar.set(MarketBarField.VOLUME, size);

      setState(MarketStateEntry.IS_SETTLED, false);

    } else {

      // ### volume

      final SizeValue volumeOld = bar.get(VOLUME);
      final SizeValue volumeNew = volumeOld.add(size);
      bar.set(VOLUME, volumeNew);
      eventAdd(NEW_VOLUME);

      // ### high

      // XXX disable for dd2 compatibility
      // final PriceValue high = bar.get(HIGH);
      // if (price.compareTo(high) > 0 || high.isNull()) {
      // bar.set(HIGH, price);
      // if (type == CURRENT) {
      // // events only for combo
      // eventAdd(NEW_HIGH);
      // }
      // }

      // ### low

      // XXX disable for dd2 compatibility
      // final PriceValue low = bar.get(LOW);
      // if (price.compareTo(low) < 0 || low.isNull()) {
      // bar.set(LOW, price);
      // if (type == CURRENT) {
      // // events only for combo
      // eventAdd(NEW_LOW);
      // }
      // }

    }

    // ### last

    // Only update last for normal in-sequence trades
    if (sequencing == NORMAL) {
      if (price.isNull()) {
        log.warn("null or zero price on trade message, not applying to bar");
      } else {
        bar.set(CLOSE, price);
        if (session == DEFAULT) {
          // events only for combo
          eventAdd(NEW_CLOSE);
        }
        // ### time
        bar.set(BAR_TIME, time);
      }
    } else {
      // XXX: Update high / low, or just wait for refresh?
    }

    bar.set(MarketBarField.TRADE_DATE, date);

  }
View Full Code Here


    final DDF_Session ddfSession = message.getSession();
   
    //

    final MarketBookTop top = market.get(MarketField.BOOK_TOP);
    final MarketDoBar barCurrent = market.loadBar(CURRENT.field);
    final MarketDoBar barPrevious = market.loadBar(PREVIOUS.field);

    //
    switch (param) {
   
    case TRADE_ASK_PRICE:  // NEW
      log.debug("Mapper saw TRADE_ASK_PRICE - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().get(InstrumentField.SYMBOL).toString());
     
      market.setTrade(ddfSession.type, ddfSession.session,
          ddfSession.sequencing, price, size, time, date);
     
      return null;
     
    case TRADE_BID_PRICE:  // NEW
      log.debug("Mapper saw TRADE_BID_PRICE - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().get(InstrumentField.SYMBOL).toString());
     
      market.setTrade(ddfSession.type, ddfSession.session,
          ddfSession.sequencing, price, size, time, date);
     
      return null;
   
    case TRADE_LAST_PRICE:
      market.setTrade(ddfSession.type, ddfSession.session,
          ddfSession.sequencing, price, size, time, date);
      return null;
     
    case ASK_LAST: // NEW
      log.debug("Mapper saw ASK_LAST - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().get(InstrumentField.SYMBOL).toString());
     
    case ASK_LAST_PRICE:
      final DefBookEntry topAskPrice = new DefBookEntry(MODIFY, ASK,
          DEFAULT, ENTRY_TOP, price, top.side(ASK).size());
      applyTop(topAskPrice, time, market);
      return null;

    case ASK_LAST_SIZE:
      final DefBookEntry topAskSize = new DefBookEntry(MODIFY, ASK,
          DEFAULT, ENTRY_TOP, top.side(ASK).price(), size);
      applyTop(topAskSize, time, market);
      return null;

    case BID_LAST: // NEW
      log.debug("Mapper saw BID_LAST - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().get(InstrumentField.SYMBOL).toString());
     
    case BID_LAST_PRICE:
      final DefBookEntry topBidPrice = new DefBookEntry(MODIFY, BID,
          DEFAULT, ENTRY_TOP, price, top.side(BID).size());
      applyTop(topBidPrice, time, market);
      return null;

    case BID_LAST_SIZE:
      final DefBookEntry topBidSize = new DefBookEntry(MODIFY, BID,
          DEFAULT, ENTRY_TOP, top.side(BID).price(), size);
      applyTop(topBidSize, time, market);
      return null;

    case CLOSE_LAST: // NEW
    case CLOSE_2_LAST: // NEW
    case CLOSE_ASK_PRICE:
    case CLOSE_BID_PRICE:
    case CLOSE_2_ASK_PRICE:
    case CLOSE_2_BID_PRICE:
      barCurrent.set(MarketBarField.CLOSE, price);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
      return null;

    case HIGH_LAST_PRICE:
    case HIGH_BID_PRICE:
    case YEAR_HIGH_PRICE:
      barCurrent.set(MarketBarField.HIGH, price);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
      return null;

    case LOW_LAST_PRICE:
    case LOW_ASK_PRICE:
    case YEAR_LOW_PRICE:
      barCurrent.set(MarketBarField.LOW, price);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
      return null;

    case VOLUME_LAST_SIZE:
      // TODO
      break;

    case VOLUME_PAST_SIZE:
      barPrevious.set(MarketBarField.VOLUME, size);
      barPrevious.set(MarketBarField.BAR_TIME, time);
      market.setBar(PREVIOUS, barPrevious);
      return null;

    case VOLUME_THIS_SIZE:
      barCurrent.set(MarketBarField.VOLUME, size);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
      return null;

    case OPEN_LAST_PRICE:
    case OPEN_ASK_PRICE:
    case OPEN_BID_PRICE:
    case OPEN_2_LAST_PRICE:
    case OPEN_2_ASK_PRICE:
    case OPEN_2_BID_PRICE:
      //
      barCurrent.set(MarketBarField.OPEN, price);
      barCurrent.set(MarketBarField.HIGH, price);
      barCurrent.set(MarketBarField.LOW, price);
      barCurrent.set(MarketBarField.CLOSE, price);
      barCurrent.set(MarketBarField.INTEREST, size);
      barCurrent.set(MarketBarField.VOLUME, size);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
      //
      market.setState(MarketStateEntry.IS_SETTLED, false);
      //
      return null;

    case INTEREST_LAST_SIZE:
      barCurrent.set(MarketBarField.INTEREST, size);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
      return null;

    case INTEREST_PAST_SIZE:
      barPrevious.set(MarketBarField.INTEREST, size);
      barPrevious.set(MarketBarField.BAR_TIME, time);
      market.setBar(PREVIOUS, barPrevious);

      return null;

    case PREVIOUS_LAST_PRICE:
      barPrevious.set(MarketBarField.CLOSE, price);
      barPrevious.set(MarketBarField.BAR_TIME, time);
      market.setBar(PREVIOUS, barPrevious);
      return null;

      /** only "final" sets the flag */
    case SETTLE_FINAL_PRICE:
View Full Code Here

  }

  @Override
  public Void visit(final DDF_EOD_Commodity message, final MarketDo market) {

    final MarketDoBar newBar = market.loadBar(MarketField.BAR_PREVIOUS);

    newBar.set(MarketBarField.OPEN, message.getPriceOpen());
    newBar.set(MarketBarField.HIGH, message.getPriceHigh());
    newBar.set(MarketBarField.LOW, message.getPriceLow());
    /* Note Last =/= Close in some cases */
    newBar.set(MarketBarField.CLOSE, message.getPriceLast());

    market.setBar(MarketBarType.PREVIOUS, newBar);

    return null;
  }
View Full Code Here

  }

  @Override
  public Void visit(final DDF_EOD_EquityForex message, final MarketDo market) {

    final MarketDoBar newBar = market.loadBar(MarketField.BAR_PREVIOUS);

    newBar.set(MarketBarField.OPEN, message.getPriceOpen());
    newBar.set(MarketBarField.HIGH, message.getPriceHigh());
    newBar.set(MarketBarField.LOW, message.getPriceLow());
    /* Note Last =/= Close in some cases */
    newBar.set(MarketBarField.CLOSE, message.getPriceLast());

    newBar.set(MarketBarField.VOLUME, message.getSizeVolume());

    market.setBar(MarketBarType.PREVIOUS, newBar);

    return null;
  }
View Full Code Here

  }

  @Override
  public Void visit(final DDF_Prior_IndividCmdy message, final MarketDo market) {

    final MarketDoBar newBar = market.loadBar(MarketField.BAR_PREVIOUS);

    newBar.set(MarketBarField.VOLUME, message.getSizeVolume());
    newBar.set(MarketBarField.INTEREST, message.getSizeOpenInterest());

    market.setBar(MarketBarType.PREVIOUS, newBar);

    return null;
  }
View Full Code Here

    /** Update CURRENT bar */
    {

      final MarketBarType type = CURRENT;

      final MarketDoBar bar = market.loadBar(type.field);

      final DDF_TradeDay tradeDay = message.getTradeDay();
      bar.set(MarketBarField.TRADE_DATE, tradeDay.tradeDate());

      final PriceValue priceOpen = message.getPriceOpen();
      final PriceValue priceHigh = message.getPriceHigh();
      final PriceValue priceLow = message.getPriceLow();
      final PriceValue priceClose = message.getPriceLast(); // XXX
      final PriceValue priceSettle = message.getPriceSettle();
      final SizeValue sizeVolume = message.getSizeVolume();

      applyBar(bar, MarketBarField.OPEN, priceOpen);
      applyBar(bar, MarketBarField.HIGH, priceHigh);
      applyBar(bar, MarketBarField.LOW, priceLow);
      applyBar(bar, MarketBarField.CLOSE, priceClose);
      applyBar(bar, MarketBarField.SETTLE, priceSettle);
      applyBar(bar, MarketBarField.VOLUME, sizeVolume);

      bar.set(MarketBarField.BAR_TIME, time);

      market.setBar(type, bar);

    }

    /** Update PREVIOUS bar */
    {

      final MarketBarType type = PREVIOUS;

      final MarketDoBar bar = market.loadBar(type.field);
      final PriceValue priceOpen = message.getPriceOpen();
      final PriceValue priceHigh = message.getPriceHigh();
      final PriceValue priceLow = message.getPriceLow();
      final PriceValue priceClose = message.getPriceLastPrevious();
      final PriceValue priceSettle = message.getPriceSettle();
      final SizeValue sizeVolume = message.getSizeVolumePrevious();
      final SizeValue sizeInterest = message.getSizeInterest(); // XXX

      applyBar(bar, MarketBarField.OPEN, priceOpen);
      applyBar(bar, MarketBarField.HIGH, priceHigh);
      applyBar(bar, MarketBarField.LOW, priceLow);
      applyBar(bar, MarketBarField.CLOSE, priceClose);
      applyBar(bar, MarketBarField.SETTLE, priceSettle);
      applyBar(bar, MarketBarField.VOLUME, sizeVolume);
      applyBar(bar, MarketBarField.INTEREST, sizeInterest);

      bar.set(MarketBarField.BAR_TIME, time);

      market.setBar(type, bar);

    }

View Full Code Here

    final DDF_Session session = message.getSession();

    final MarketBarType type = barTypeFrom(indicator, session);

    final MarketDoBar bar = market.loadBar(type.field);

    //
    final DDF_TradeDay tradeDay = message.getTradeDay();
    bar.set(MarketBarField.TRADE_DATE, tradeDay.tradeDate());
    //

    // extract

    final PriceValue priceOpen = message.getPriceOpen();
    final PriceValue priceHigh = message.getPriceHigh();
    final PriceValue priceLow = message.getPriceLow();
    final PriceValue priceClose = message.getPriceLast(); // XXX note: LAST
    final PriceValue priceSettle = message.getPriceSettle();
    final SizeValue sizeVolume = message.getSizeVolume();
    final SizeValue sizeInterest = message.getSizeInterest();

    // apply

    applyBar(bar, MarketBarField.OPEN, priceOpen);
    applyBar(bar, MarketBarField.HIGH, priceHigh);
    applyBar(bar, MarketBarField.LOW, priceLow);
    applyBar(bar, MarketBarField.CLOSE, priceClose);
    applyBar(bar, MarketBarField.SETTLE, priceSettle);
    applyBar(bar, MarketBarField.VOLUME, sizeVolume);
    applyBar(bar, MarketBarField.INTEREST, sizeInterest);

    //

    bar.set(MarketBarField.BAR_TIME, message.getTime());

    market.setBar(type, bar);

    return null;
  }
View Full Code Here

    final DDF_Session ddfSession = message.getSession();
   
    //

    final MarketBookTop top = market.get(MarketField.BOOK_TOP);
    final MarketDoBar barCurrent = market.loadBar(CURRENT.field);
    final MarketDoBar barPrevious = market.loadBar(PREVIOUS.field);

    //
    switch (param) {
   
    case TRADE_ASK_PRICE:  // NEW
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.TRADE);
     
      log.debug("Mapper saw TRADE_ASK_PRICE - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().symbol());
     
      market.setTrade(ddfSession.type, ddfSession.session,
          ddfSession.sequencing, price, size, time, date);

      return null;
     
    case TRADE_BID_PRICE:  // NEW
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.TRADE);
     
      log.debug("Mapper saw TRADE_BID_PRICE - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().symbol());
     
      market.setTrade(ddfSession.type, ddfSession.session,
          ddfSession.sequencing, price, size, time, date);
     
      return null;
   
    case TRADE_LAST_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.TRADE);
     
      market.setTrade(ddfSession.type, ddfSession.session,
          ddfSession.sequencing, price, size, time, date);
     
      return null;
     
    case ASK_LAST: // NEW
     
      log.debug("Mapper saw ASK_LAST - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().symbol());
     
    case ASK_LAST_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.BOOK_COMBINED);
     
      final DefBookEntry topAskPrice = new DefBookEntry(
          MODIFY, Book.Side.ASK,
          Book.Type.DEFAULT, ENTRY_TOP, price, top.side(Book.Side.ASK).sizeValue());
      applyTop(topAskPrice, time, market);
     
      return null;

    case ASK_LAST_SIZE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.BOOK_COMBINED);
     
      final DefBookEntry topAskSize = new DefBookEntry(
          MODIFY, Book.Side.ASK,
          Book.Type.DEFAULT, ENTRY_TOP, top.side(Book.Side.ASK).priceValue(), size);
      applyTop(topAskSize, time, market);
     
      return null;

    case BID_LAST: // NEW
      log.debug("Mapper saw BID_LAST - Price=" + price.toString() +
          " " + message.getSession() + " " + message.getTradeDay().toString() + " "
          + message.getInstrument().symbol());
     
    case BID_LAST_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.BOOK_COMBINED);
     
      final DefBookEntry topBidPrice = new DefBookEntry(
          MODIFY, Book.Side.BID,
          Book.Type.DEFAULT, ENTRY_TOP, price, top.side(Book.Side.BID).sizeValue());
      applyTop(topBidPrice, time, market);
     
      return null;

    case BID_LAST_SIZE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.BOOK_COMBINED);
     
      final DefBookEntry topBidSize = new DefBookEntry(
          MODIFY, Book.Side.BID,
          Book.Type.DEFAULT, ENTRY_TOP, top.side(Book.Side.BID).priceValue(), size);
      applyTop(topBidSize, time, market);
     
      return null;

    case CLOSE_LAST: // NEW
    case CLOSE_2_LAST: // NEW
    case CLOSE_ASK_PRICE:
    case CLOSE_BID_PRICE:
    case CLOSE_2_ASK_PRICE:
    case CLOSE_2_BID_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_CURRENT);
     
      barCurrent.set(MarketBarField.CLOSE, price);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
     
      return null;

    case HIGH_LAST_PRICE:
    case HIGH_BID_PRICE:
    case YEAR_HIGH_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_CURRENT);
     
      barCurrent.set(MarketBarField.HIGH, price);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
     
      return null;

    case LOW_LAST_PRICE:
    case LOW_ASK_PRICE:
    case YEAR_LOW_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_CURRENT);
     
      barCurrent.set(MarketBarField.LOW, price);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
     
      return null;

    case VOLUME_LAST_SIZE:
      // TODO
      break;

    case VOLUME_PAST_SIZE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_PREVIOUS);
     
      barPrevious.set(MarketBarField.VOLUME, size);
      barPrevious.set(MarketBarField.BAR_TIME, time);
      market.setBar(PREVIOUS, barPrevious);
     
      return null;

    case VOLUME_THIS_SIZE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_CURRENT);
     
      barCurrent.set(MarketBarField.VOLUME, size);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
     
      return null;

    case OPEN_LAST_PRICE:
    case OPEN_ASK_PRICE:
    case OPEN_BID_PRICE:
    case OPEN_2_LAST_PRICE:
    case OPEN_2_ASK_PRICE:
    case OPEN_2_BID_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_CURRENT);
     
      //
      barCurrent.set(MarketBarField.OPEN, price);
      barCurrent.set(MarketBarField.HIGH, price);
      barCurrent.set(MarketBarField.LOW, price);
      barCurrent.set(MarketBarField.CLOSE, price);
      barCurrent.set(MarketBarField.INTEREST, size);
      barCurrent.set(MarketBarField.VOLUME, size);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
      //
      market.setState(MarketStateEntry.IS_SETTLED, false);
      //
     
      return null;

    case INTEREST_LAST_SIZE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_CURRENT);
     
      barCurrent.set(MarketBarField.INTEREST, size);
      barCurrent.set(MarketBarField.BAR_TIME, time);
      market.setBar(CURRENT, barCurrent);
     
      return null;

    case INTEREST_PAST_SIZE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_PREVIOUS);
     
      barPrevious.set(MarketBarField.INTEREST, size);
      barPrevious.set(MarketBarField.BAR_TIME, time);
      market.setBar(PREVIOUS, barPrevious);

      return null;

    case PREVIOUS_LAST_PRICE:
     
      /* Update changed comonents */
      market.clearChanges();
      market.setChange(Component.DEFAULT_PREVIOUS);
     
      barPrevious.set(MarketBarField.CLOSE, price);
      barPrevious.set(MarketBarField.BAR_TIME, time);
      market.setBar(PREVIOUS, barPrevious);
     
      return null;

      /** only "final" sets the flag */
 
View Full Code Here

    /* Update changed comonents */
    market.clearChanges();
    market.setChange(Component.DEFAULT_PREVIOUS);
   
    final MarketDoBar newBar = market.loadBar(MarketField.BAR_PREVIOUS);

    newBar.set(MarketBarField.OPEN, message.getPriceOpen());
    newBar.set(MarketBarField.HIGH, message.getPriceHigh());
    newBar.set(MarketBarField.LOW, message.getPriceLow());
    /* Note Last =/= Close in some cases */
    newBar.set(MarketBarField.CLOSE, message.getPriceLast());

    market.setBar(MarketBarType.PREVIOUS, newBar);

    return null;
  }
View Full Code Here

   
    /* Update changed comonents */
    market.clearChanges();
    market.setChange(Component.DEFAULT_PREVIOUS);
   
    final MarketDoBar newBar = market.loadBar(MarketField.BAR_PREVIOUS);

    newBar.set(MarketBarField.OPEN, message.getPriceOpen());
    newBar.set(MarketBarField.HIGH, message.getPriceHigh());
    newBar.set(MarketBarField.LOW, message.getPriceLow());
    /* Note Last =/= Close in some cases */
    newBar.set(MarketBarField.CLOSE, message.getPriceLast());

    newBar.set(MarketBarField.VOLUME, message.getSizeVolume());

    market.setBar(MarketBarType.PREVIOUS, newBar);
   
    return null;
  }
View Full Code Here

TOP

Related Classes of com.barchart.feed.base.bar.api.MarketDoBar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.