All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.barchart.feed.ddf.message.provider.BaseMarket Maven / Gradle / Ivy

/**
 * Copyright (C) 2011-2012 Barchart, Inc. 
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */
package com.barchart.feed.ddf.message.provider;

import static com.barchart.feed.ddf.message.provider.CodecHelper.*;
import static com.barchart.util.common.ascii.ASCII.*;

import java.nio.ByteBuffer;

import org.joda.time.DateTimeZone;

import com.barchart.feed.api.model.meta.Exchange;
import com.barchart.feed.api.model.meta.Instrument;
import com.barchart.feed.api.model.meta.id.InstrumentID;
import com.barchart.feed.base.provider.Symbology;
import com.barchart.feed.base.provider.ValueConverter;
import com.barchart.feed.base.values.api.TextValue;
import com.barchart.feed.base.values.api.TimeValue;
import com.barchart.feed.base.values.provider.ValueBuilder;
import com.barchart.feed.ddf.instrument.provider.DDF_FeedInstProvider;
import com.barchart.feed.ddf.message.api.DDF_MarketBase;
import com.barchart.feed.ddf.message.enums.DDF_MessageType;
import com.barchart.feed.ddf.message.enums.DDF_Session;
import com.barchart.feed.ddf.message.enums.DDF_TradeDay;
import com.barchart.feed.ddf.symbol.api.DDF_Symbol;
import com.barchart.feed.ddf.symbol.enums.DDF_Exchange;
import com.barchart.feed.ddf.symbol.enums.DDF_SpreadType;
import com.barchart.feed.ddf.symbol.provider.DDF_SymbolService;
import com.barchart.feed.ddf.symbol.provider.DDF_Symbology;
import com.barchart.feed.ddf.util.ClockDDF;
import com.barchart.feed.ddf.util.enums.DDF_Fraction;
import com.barchart.feed.meta.instrument.DefaultInstrument;
import com.barchart.util.common.ascii.ASCII;
import com.barchart.util.value.api.Fraction;

// TODO: Auto-generated Javadoc
abstract class BaseMarket extends Base implements DDF_MarketBase {

	BaseMarket() {
		//
	}

	BaseMarket(final DDF_MessageType messageType) {
		setMessageType(messageType);
	}

	// //////////////////////////////////////

	private byte ordExchange = DDF_Exchange.UNKNOWN.ord;
	private byte ordFraction = DDF_Fraction.UNKNOWN.ord;
	private byte ordTradeDay = DDF_TradeDay.UNKNOWN.ord;
	private byte ordSession = DDF_Session.UNKNOWN.ord;
	private byte ordSpread = DDF_SpreadType.UNKNOWN.ord;

	protected byte delay = DDF_NO_DELAY;

	protected byte[][] symbolArray;

	// //////////////////////////////////////

	// NOTE: invokes resolver
	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getInstrument()
	 */
	@Override
	public Instrument getInstrument() {

		return DDF_FeedInstProvider.fromMessage(stub);

	}

	/*
	 * Lazy eval instrument stub
	 */
	private final Instrument stub = new DefaultInstrument(InstrumentID.NULL) {

		/* GUID is symbol for now */
		@Override
		public String marketGUID() {
			return Symbology.formatSymbol(getId().toString());
		}

		@Override
		public SecurityType securityType() {
			return getExchange().kind.asSecType();
		}

		@Override
		public String symbol() {
			return Symbology.formatSymbol(getId().toString());
		}

		@Override
		public Exchange exchange() {
			return getExchange().asExchange();
		}

		@Override
		public String exchangeCode() {
			return new String(new byte[] {
					getExchange().code
			});
		}

		@Override
		public Fraction displayFraction() {
			return ValueConverter.fraction(getFraction().fraction);
		}

	};

	@Override
	public final TimeValue getTime() {
		return ValueBuilder.newTime(millisUTC);
	}

	// NOTE: invokes parser
	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getSymbol()
	 */
	@Override
	public final DDF_Symbol getSymbol() {
		return DDF_SymbolService.find(getId());
	}

	//

	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getDelay()
	 */
	@Override
	public final int getDelay() {
		return delay;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getFraction()
	 */
	@Override
	public final DDF_Fraction getFraction() {
		return DDF_Fraction.fromOrd(ordFraction);
	}

	protected final void setFraction(final DDF_Fraction frac) {
		ordFraction = frac.ord;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getExchange()
	 */
	@Override
	public DDF_Exchange getExchange() {
		return DDF_Exchange.fromOrd(ordExchange);
	}

	protected final void setExchange(final DDF_Exchange exchange) {
		ordExchange = exchange.ord;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getSession()
	 */
	@Override
	public final DDF_Session getSession() {
		return DDF_Session.fromOrd(ordSession);
	}

	protected final void setSession(final DDF_Session session) {
		ordSession = session.ord;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getTradeDay()
	 */
	@Override
	public final DDF_TradeDay getTradeDay() {
		return DDF_TradeDay.fromOrd(ordTradeDay);
	}

	protected final void setTradeDay(final DDF_TradeDay day) {
		ordTradeDay = day.ord;
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getSpreadType()
	 */
	@Override
	public final DDF_SpreadType getSpreadType() {
		return DDF_SpreadType.fromOrd(ordSpread);
	}

	protected final void setSpread(final DDF_SpreadType spread) {
		ordSpread = spread.ord;
	}

	//

	protected final byte[] getSymbolFull() {
		return DDF_Symbology.byteArrayFromSymbolArray(symbolArray);
	}

	protected final byte[] getSymbolMain() {
		if (symbolArray == null || symbolArray.length == 0) {
			return DDF_Symbology.DDF_NO_NAME;
		}
		return symbolArray[0];
	}

	/*
	 * non spread: 
	 *
	 * or
	 *
	 * for spread: __..._
	 */
	/*
	 * (non-Javadoc)
	 *
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBase#getId()
	 */
	@Override
	public TextValue getId() {
		return ValueBuilder.newText(getSymbolFull());
	}

	// ######################

	/*
	 * ,()(,)()||
	 *
	 * ... body ...
	 *
	 * ||||




© 2015 - 2024 Weber Informatics LLC | Privacy Policy