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

com.barchart.feed.ddf.message.provider.DF_28_BookTop 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.base.book.enums.MarketBookAction.MODIFY;
import static com.barchart.util.common.ascii.ASCII.COMMA;

import java.nio.ByteBuffer;

import com.barchart.feed.api.model.data.Book;
import com.barchart.feed.api.model.meta.Instrument;
import com.barchart.feed.base.book.api.MarketBook;
import com.barchart.feed.base.book.api.MarketDoBookEntry;
import com.barchart.feed.base.provider.DefBookEntry;
import com.barchart.feed.base.values.api.PriceValue;
import com.barchart.feed.base.values.api.SizeValue;
import com.barchart.feed.base.values.provider.ValueConst;
import com.barchart.feed.ddf.message.api.DDF_MarketBookTop;
import com.barchart.feed.ddf.message.api.DDF_MessageVisitor;
import com.barchart.feed.ddf.message.enums.DDF_MessageType;
import com.barchart.feed.ddf.util.HelperDDF;
import com.barchart.feed.ddf.util.enums.DDF_Fraction;

// TODO: Auto-generated Javadoc
class DF_28_BookTop extends BaseMarket implements DDF_MarketBookTop {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.barchart.feed.ddf.message.provider.Base#accept(com.barchart.feed.
	 * ddf.message.api.DDF_MessageVisitor, java.lang.Object)
	 */
	@Override
	public  Result accept(
			final DDF_MessageVisitor visitor, final Param param) {
		return visitor.visit(this, param);
	}

	DF_28_BookTop() {
		super(DDF_MessageType.BOOK_TOP);
	}

	DF_28_BookTop(final DDF_MessageType messageType) {
		super(messageType);
	}

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

	protected long priceBid = HelperDDF.DDF_EMPTY;
	protected long priceAsk = HelperDDF.DDF_EMPTY;

	protected long sizeBid = HelperDDF.DDF_EMPTY;
	protected long sizeAsk = HelperDDF.DDF_EMPTY;

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

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBookTop#getPriceBid()
	 */
	@Override
	public PriceValue getPriceBid() {
		return HelperDDF.newPriceDDF(priceBid, getFraction());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBookTop#getSizeBid()
	 */
	@Override
	public SizeValue getSizeBid() {
		return HelperDDF.newSizeDDF(sizeBid);
	}

	//

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBookTop#getPriceAsk()
	 */
	@Override
	public PriceValue getPriceAsk() {
		return HelperDDF.newPriceDDF(priceAsk, getFraction());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.barchart.feed.ddf.message.api.DDF_MarketBookTop#getSizeAsk()
	 */
	@Override
	public SizeValue getSizeAsk() {
		return HelperDDF.newSizeDDF(sizeAsk);
	}

	//

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.barchart.feed.ddf.message.api.DDF_MarketBookTop#entry(com.barchart
	 * .feed.base.api.market.enums.MarketBookSide)
	 */
	@Override
	public final MarketDoBookEntry entry(final Instrument instrument, final Book.Side side) {

		final PriceValue price;
		final SizeValue size;

		switch (side) {
		case BID:
			price = getPriceBid();
			size = getSizeBid();
			break;
		case ASK:
			price = getPriceAsk();
			size = getSizeAsk();
			break;
		default:
			assert false : "invalid side";
			price = ValueConst.NULL_PRICE;
			size = ValueConst.NULL_SIZE;
			break;
		}

		final MarketDoBookEntry entry = new DefBookEntry(
				MODIFY, 
				side, 
				Book.Type.DEFAULT,
				MarketBook.ENTRY_TOP, 
				price, 
				size);

		return entry;

	}

	/*
	 * ,()(,)()||
	 * 
	 * ,,,,
	 * 
	 * ||||




© 2015 - 2024 Weber Informatics LLC | Privacy Policy