Source code

    001/*
    002# Licensed Materials - Property of IBM
    003# Copyright IBM Corp. 2015
    004 */
    005package vwap;
    006
    007import java.math.BigDecimal;
    008
    009import com.ibm.streams.operator.Tuple;
    010import com.ibm.streamsx.topology.TStream;
    011import com.ibm.streamsx.topology.spl.SPLStream;
    012
    013public class Quote extends Ticker {
    014    /**
    015     *
    016     */
    017    private static final long serialVersionUID = -8355672072795288713L;
    018    final BigDecimal bidprice;
    019    final BigDecimal askprice;
    020    final BigDecimal asksize;
    021
    022    public Quote(Tuple tuple) {
    023        super(tuple);
    024        bidprice = tuple.getBigDecimal("bidprice");
    025        askprice = tuple.getBigDecimal("askprice");
    026        asksize = tuple.getBigDecimal("asksize");
    027    }
    028
    029    public String toString() {
    030        return "QUOTE: " + getTicker() + " bidprice=" + bidprice + " askprice="
    031                + askprice + " asksize=" + asksize;
    032    }
    033
    034    /**
    035     * Convert a trade SPL tuple to a Quote object.
    036     */
    037    public static Quote convertToTrade(Tuple tuple) {
    038        if ("Quote".equals(tuple.getString("ttype")))
    039            return new Quote(tuple);
    040        return null;
    041
    042    }
    043
    044    /**
    045     * Get the stream of quotes from the SPL stream.
    046     * The stream is keyed by the ticker symbol.
    047     */
    048    public static TStream<Quote> getQuotes(SPLStream tradeQuotes) {
    049        return tradeQuotes.transform(Quote::convertToTrade);
    050    }
    051}