Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011-2012 Barchart, Inc. <http://www.barchart.com/> All rights reserved. Licensed under the OSI BSD License. http://www.opensource.org/licenses/bsd-license.php
  
  package com.barchart.feed.ddf.market.provider;
  
 import static com.barchart.feed.base.bar.enums.MarketBarType.CURRENT;
 import static com.barchart.feed.base.bar.enums.MarketBarType.PREVIOUS;
 import static com.barchart.feed.base.book.api.MarketBook.ENTRY_TOP;
 import static com.barchart.feed.base.book.enums.MarketBookAction.MODIFY;
 import static com.barchart.feed.ddf.message.provider.DDF_MessageService.isClear;
 import static com.barchart.feed.ddf.message.provider.DDF_MessageService.isEmpty;
 
 
 import  com.barchart.feed.api.model.data.Book;
 import  com.barchart.feed.api.model.data.Market.Component;
 import  com.barchart.feed.base.bar.api.MarketDoBar;
 import  com.barchart.feed.base.bar.enums.MarketBarField;
 import  com.barchart.feed.base.bar.enums.MarketBarType;
 import  com.barchart.feed.base.book.api.MarketBook;
 import  com.barchart.feed.base.book.api.MarketBookTop;
 import  com.barchart.feed.base.book.api.MarketDoBookEntry;
 import  com.barchart.feed.base.book.enums.MarketBookAction;
 import  com.barchart.feed.base.cuvol.api.MarketDoCuvolEntry;
 import  com.barchart.feed.base.market.api.MarketDo;
 import  com.barchart.feed.base.market.enums.MarketField;
 import  com.barchart.feed.base.provider.DefBookEntry;
 import  com.barchart.feed.base.state.enums.MarketStateEntry;
 import  com.barchart.feed.base.trade.enums.MarketTradeSequencing;
 import  com.barchart.feed.base.values.api.BooleanValue;
 import  com.barchart.feed.base.values.api.PriceValue;
 import  com.barchart.feed.base.values.api.SizeValue;
 import  com.barchart.feed.base.values.api.TimeValue;
 import  com.barchart.feed.base.values.provider.ValueConst;
 import  com.barchart.util.common.anno.ThreadSafe;
 
 @ThreadSafe
 class MapperDDF implements DDF_MessageVisitor<Void, MarketDo> {
 
 	protected final Logger log = LoggerFactory.getLogger(getClass());
 
 	public Void visit(final DDF_ControlResponse messagefinal MarketDo market) {
 		// not used
 		return null;
 	}
 
 	public Void visit(final DDF_ControlTimestamp messagefinal MarketDo market) {
 		// TODO: need to set this as the default for subsequent messages without
 		// a timestamp
 		return null;
 	}
 
 	public Void visit(final DDF_MarketBook messagefinal MarketDo market) {
 
 		market.clearChanges();
 
 		final MarketDoBookEntry[] entries = message.entries();
 		final TimeValue time = message.getTime();
 
 		market.setBookSnapshot(entriestime);
 
 		return null;
 	}
 
 	public Void visit(final DDF_MarketBookTop messagefinal MarketDo market) {
		market.clearChanges();
		final TimeValue time = message.getTime();
		message.getTime();
		applyTop(message.entry(market.instrument(), Book.Side.BID), timemarket);
		applyTop(message.entry(market.instrument(), Book.Side.ASK), timemarket);
		return null;
	}
	public Void visit(final DDF_MarketCondition messagefinal MarketDo market) {
		// TODO properly update market state
		.error("TODO : \n{}"message);
		return null;
	}
	public Void visit(final DDF_MarketCuvol messagefinal MarketDo market) {
		market.clearChanges();
		final MarketDoCuvolEntry[] entries = message.entries();
		final TimeValue time = message.getTime();
		market.setCuvolSnapshot(entriestime);
		return null;
	}
	public Void visit(final DDF_MarketParameter messagefinal MarketDo market) {
		market.clearChanges();
		final DDF_ParamType param = message.getParamType();
		final TimeValue time = message.getTime();
		final TimeValue date = message.getTradeDay().tradeDate();
		final DDF_Session ddfSession = message.getSession();
		final PriceValue price;
		final SizeValue size;
		switch (param.kind) {
			default:
			case :
				price = ValueConst.NULL_PRICE;
				size = message.getAsSize();
				break;
			case :
				price = message.getAsPrice();
				size = ValueConst.NULL_SIZE;
				break;
		}
		// Roll session if needed
		final MarketBarType type = market.ensureBar(date);
		final MarketBookTop top = market.get(MarketField.BOOK_TOP);
		final MarketDoBar bar = market.loadBar(type.field);
		switch (param) {
				market.setTrade(ddfSession.typeddfSession.session,
						ddfSession.sequencingpricesizetimedate);
				return null;
				market.setTrade(ddfSession.typeddfSession.session,
						ddfSession.sequencingpricesizetimedate);
				return null;
				market.setTrade(ddfSession.typeddfSession.session,
						ddfSession.sequencingpricesizetimedate);
				return null;
			case :
				final DefBookEntry topAskPrice = new DefBookEntry(
						MODIFY, Book.Side.ASK,
						Book.Type.DEFAULT, ENTRY_TOP, pricetop.side(Book.Side.ASK).sizeValue());
				applyTop(topAskPricetimemarket);
				return null;
				final DefBookEntry topAskSize = new DefBookEntry(
						MODIFY, Book.Side.ASK,
						Book.Type.DEFAULT, ENTRY_TOP, top.side(Book.Side.ASK).priceValue(), size);
				applyTop(topAskSizetimemarket);
				return null;
			case :
				final DefBookEntry topBidPrice = new DefBookEntry(
						MODIFY, Book.Side.BID,
						Book.Type.DEFAULT, ENTRY_TOP, pricetop.side(Book.Side.BID).sizeValue());
				applyTop(topBidPricetimemarket);
				return null;
				final DefBookEntry topBidSize = new DefBookEntry(
						MODIFY, Book.Side.BID,
						Book.Type.DEFAULT, ENTRY_TOP, top.side(Book.Side.BID).priceValue(), size);
				applyTop(topBidSizetimemarket);
				return null;
				bar.set(MarketBarField.CLOSE, price);
				bar.set(MarketBarField.BAR_TIME, time);
				market.setBar(typebar);
				return null;
				bar.set(MarketBarField.HIGH, price);
				bar.set(MarketBarField.BAR_TIME, time);
				market.setBar(typebar);
				return null;
				bar.set(MarketBarField.LOW, price);
				bar.set(MarketBarField.BAR_TIME, time);
				market.setBar(typebar);
				return null;
				if (type == CURRENT) {
					final MarketDoBar barPrevious = market.loadBar(PREVIOUS.field);
					barPrevious.set(MarketBarField.VOLUME, size);
					barPrevious.set(MarketBarField.BAR_TIME, time);
					market.setBar(PREVIOUS, barPrevious);
				}
				return null;
				bar.set(MarketBarField.VOLUME, size);
				bar.set(MarketBarField.BAR_TIME, time);
				market.setBar(typebar);
				return null;
				bar.set(MarketBarField.OPEN, price);
				bar.set(MarketBarField.HIGH, price);
				bar.set(MarketBarField.LOW, price);
				bar.set(MarketBarField.CLOSE, price);
				bar.set(MarketBarField.INTEREST, size);
				bar.set(MarketBarField.VOLUME, size);
				bar.set(MarketBarField.BAR_TIME, time);
				bar.set(MarketBarField.SETTLE, ValueConst.NULL_PRICE);
				bar.set(MarketBarField.IS_SETTLED, ValueConst.FALSE_BOOLEAN);
				market.setBar(typebar);
				return null;
				bar.set(MarketBarField.INTEREST, size);
				bar.set(MarketBarField.BAR_TIME, time);
				market.setBar(typebar);
				return null;
				if (type == CURRENT) {
					final MarketDoBar barPrevious = market.loadBar(PREVIOUS.field);
					barPrevious.set(MarketBarField.INTEREST, size);
					barPrevious.set(MarketBarField.BAR_TIME, time);
					market.setBar(PREVIOUS, barPrevious);
				}
				return null;
				if (type == CURRENT) {
					final MarketDoBar barPrevious = market.loadBar(PREVIOUS.field);
					barPrevious.set(MarketBarField.CLOSE, price);
					barPrevious.set(MarketBarField.BAR_TIME, time);
					market.setBar(PREVIOUS, barPrevious);
				}
				return null;
				bar.set(MarketBarField.IS_SETTLED, ValueConst.TRUE_BOOLEAN);
				/* Fall through */
				/* Update changed comonents */
				market.clearChanges();
				market.setChange(Component.DEFAULT_CURRENT);
				bar.set(MarketBarField.SETTLE, price);
				bar.set(MarketBarField.BAR_TIME, time);
				market.setBar(typebar);
				return null;
				bar.set(MarketBarField.VWAP, price);
				market.setBar(typebar);
				return null;
			default:
				.debug("@@@ TODO : {} \n{}"parammessage.getTime().toString() + " " + message);
		}
		return null;
	}

via feed XQ snapshot or web URL lookup.

Parameters:
message the message
market the market
Returns:
the void
	public Void visit(final DDF_MarketQuote messagefinal MarketDo market) {
		market.clearChanges();
		final DDF_QuoteState state = message.getState();
		final DDF_QuoteMode mode = message.getMode();

Handle quote publish state
		{
			switch (mode) {
				case :
				case :
				case :
					market.setState(MarketStateEntry.IS_PUBLISH_REALTIME, false);
					market.setState(MarketStateEntry.IS_PUBLISH_DELAYED, true);
					break;
				case :
					market.setState(MarketStateEntry.IS_PUBLISH_REALTIME, true);
					market.setState(MarketStateEntry.IS_PUBLISH_DELAYED, false);
					break;
				default:
					break;
			}
		}

Process Sessions
		{
			final DDF_MarketSession[] sessionArray = message.sessions();
			for (final DDF_MarketSession session : sessionArray) {
				final DDF_Indicator indicator = session.getIndicator();
				.debug("DDF_Indicator for session {} : {} "session
						.getSession().name(), indicator.name());
				switch (indicator) {
					case :
						visit(sessionmarketstate == .);
						break;
					case :
						visit(sessionmarketfalse);
						break;
					default:
						// log.error("@@@ unsupported indicator : {}", indicator);
						break;
				}
			}
		}

Process top of book
		{
			final DDF_MarketBookTop bookTop = message;
			visit(bookTopmarket);
		}
		return null;
	}

via xml quote.

Parameters:
message the message
market the market
Returns:
the void
	public Void visit(final DDF_MarketSession messagefinal MarketDo market) {
		return visit(messagemarketfalse);
	}
	public Void visit(final DDF_MarketSession messagefinal MarketDo market,
			final boolean forceSettle) {
		// ### process snapshot
		final DDF_MarketSnapshot snapshot = message;
		final DDF_Indicator indicator = message.getIndicator();
		visit(snapshotmarketindicatorforceSettle);
		return null;
	}
	public Void visit(final DDF_EOD_Commodity messagefinal MarketDo market) {
		market.clearChanges();
		final MarketBarType type = market.ensureBar(message.getTradeDay().tradeDate());
		final MarketDoBar bar = market.loadBar(type.field);
		bar.set(MarketBarField.OPEN, message.getPriceOpen());
		bar.set(MarketBarField.HIGH, message.getPriceHigh());
		bar.set(MarketBarField.LOW, message.getPriceLow());
		/* Note Last =/= Close in some cases */
		bar.set(MarketBarField.CLOSE, message.getPriceLast());
		market.setBar(typebar);
		return null;
	}
	public Void visit(final DDF_EOD_EquityForex messagefinal MarketDo market) {
		market.clearChanges();
		final MarketBarType type = market.ensureBar(message.getTradeDay().tradeDate());
		final MarketDoBar bar = market.loadBar(type.field);
		bar.set(MarketBarField.OPEN, message.getPriceOpen());
		bar.set(MarketBarField.HIGH, message.getPriceHigh());
		bar.set(MarketBarField.LOW, message.getPriceLow());
		/* Note Last =/= Close in some cases */
		bar.set(MarketBarField.CLOSE, message.getPriceLast());
		bar.set(MarketBarField.VOLUME, message.getSizeVolume());
		market.setBar(typebar);
		return null;
	}
	public Void visit(final DDF_Prior_IndividCmdy messagefinal MarketDo market) {
		market.clearChanges();
		final MarketBarType type = market.ensureBar(message.getTradeDay().tradeDate());
		final MarketDoBar bar = market.loadBar(type.field);
		bar.set(MarketBarField.VOLUME, message.getSizeVolume());
		bar.set(MarketBarField.INTEREST, message.getSizeOpenInterest());
		market.setBar(typebar);
		return null;
	}
	public Void visit(final DDF_Prior_TotCmdy messagefinal MarketDo market) {
		// TODO No support for total volume/OI yet
		return null;
	}
	public Void visit(final DDF_EOD_CommoditySpread messagefinal MarketDo market) {
		// TODO No support for EOD spreads yet
		return null;
	}

via feed message 21, 22, 23, 24.

Parameters:
message the message
market the market
Returns:
the void
	public Void visit(final DDF_MarketSnapshot messagefinal MarketDo market) {
		market.clearChanges();
		final TimeValue date = message.getTradeDay().tradeDate();
		final TimeValue time = message.getTime();

Update top of book
		{
			final PriceValue priceBid = message.getPriceBid();
			final PriceValue priceAsk = message.getPriceAsk();
			final MarketDoBookEntry entryBid = new DefBookEntry(
					MODIFY, Book.Side.BID,
					Book.Type.DEFAULT, ENTRY_TOP, priceBid, ValueConst.NULL_SIZE);
			final MarketDoBookEntry entryAsk = new DefBookEntry(
					MODIFY, Book.Side.ASK,
					Book.Type.DEFAULT, ENTRY_TOP, priceAsk, ValueConst.NULL_SIZE);
			applyTop(entryBidtimemarket);
			applyTop(entryAsktimemarket);
		}
		final PriceValue settle = message.getPriceSettle();
		BooleanValue settled = null;
		// Check settled flag
		if (isClear(settle)) {
			settled = ValueConst.FALSE_BOOLEAN;
else if (!isEmpty(settle)) {
			settled = ValueConst.TRUE_BOOLEAN;
		}
		market.setSnapshot(date,
				message.getPriceOpen(),
				message.getPriceHigh(),
				message.getPriceLow(),
				message.getPriceLast(),
				settle,
				message.getSizeVolume(),
				message.getSizeInterest(),
				message.getVWAP(),
				settled,
				message.getTime());
		return null;
	}

via xml quote >> xml session
	protected Void visit(
			final DDF_MarketSnapshot message,
			final MarketDo market
			final DDF_Indicator indicator) {
		return visit(messagemarketindicatorfalse);
	}
	protected Void visit(
			final DDF_MarketSnapshot message,
			final MarketDo market
			final DDF_Indicator indicator,
			final boolean forceSettle) {
		market.clearChanges();
		final TimeValue date = message.getTradeDay().tradeDate();
		final PriceValue settle = message.getPriceSettle();
		BooleanValue settled = null;
		// Check settled flag
		if (settle == .) {
			settled = ValueConst.FALSE_BOOLEAN;
else if (settle == .) {
else if (indicator == . || forceSettle) {
			settled = ValueConst.TRUE_BOOLEAN;
		}
		market.setSnapshot(date,
				message.getPriceOpen(),
				message.getPriceHigh(),
				message.getPriceLow(),
				message.getPriceLast(),
				settle,
				message.getSizeVolume(),
				message.getSizeInterest(),
				message.getVWAP(),
				settled,
				message.getTime());
		/*
		 * If a previous update, set in bar current.
		 */
		/* Commented out to see if there are any cases where the current bar's previous value isn't correct 
		 * This most likely can be deleted if it doesn't cause problems elsewhere */
//		if (indicator == DDF_Indicator.PREVIOUS && !settle.isZero()) {
//			market.loadBar(MarketBarType.CURRENT.field).set(MarketBarField.CLOSE_PREVIOUS, settle);
//		}
		return null;
	}
	public Void visit(final DDF_MarketTrade messagefinal MarketDo market) {
		market.clearChanges();
		final DDF_MessageType tradeType = message.getMessageType();
		final TimeValue time = message.getTime();
		final TimeValue date = message.getTradeDay().tradeDate();
		final DDF_Session ddfSession = message.getSession();
		PriceValue price = message.getPrice();
		SizeValue size = message.getSize();
		if (isClear(price) || isEmpty(price)) {
			price = ValueConst.NULL_PRICE;
			size = ValueConst.NULL_SIZE;
		}
		if (isClear(size) || isEmpty(size)) {
			size = ValueConst.NULL_SIZE;
		}
		switch (tradeType) {
			case :
				// message "27" : normal trade
				market.setTrade(ddfSession.typeddfSession.session,
						ddfSession.sequencingpricesizetimedate);
				break;
			case :
				// message "2Z" : volume updates for stocks
				// Override sequencing since the feed translator seems to be
				// looking at sale conditions we don't have
				market.setTrade(ddfSession.typeddfSession.session,
						MarketTradeSequencing.UNSEQUENCED_VOLUME, pricesizetimedate);
				break;
			default:
				.error("unsupported trade message type");
				break;
		}
		//
		return null;
	}
	// ##################################
	protected void applyTop(MarketDoBookEntry entry,
			final TimeValue timefinal MarketDo market) {
		/* ddf signals by special price values */
		final PriceValue price = entry.priceValue();
		/* ",," a.k.a comma-comma; ddf value not provided */
		if (isEmpty(price)) {
			return;
		}
		/* ",-," a.k.a comma-dash-comma; ddf command : remove */
		if (isClear(price)) {
			entry = new DefBookEntry(
					MarketBookAction.REMOVE, entry.side(),
					Book.Type.DEFAULT, MarketBook.ENTRY_TOP,
					ValueConst.NULL_PRICE, ValueConst.NULL_SIZE);
		}
		market.setBookUpdate(entrytime);
	}
New to GrepCode? Check out our FAQ X