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

com.quotemedia.streamer.client.impl.QmciMessageMapper Maven / Gradle / Ivy

Go to download

Java streaming client that provides easy-to-use client APIs to connect and subscribe to QuoteMedia's market data streaming services. https://quotemedia.com/

The newest version!
package com.quotemedia.streamer.client.impl;

import com.quotemedia.datacache.data.QMLongDecimal;
import com.quotemedia.datacache.data.RangeIndicator;
import com.quotemedia.datacache.messaging.GenericDataMessage;
import com.quotemedia.datacache.messaging.impl.Alert;
import com.quotemedia.datacache.messaging.impl.BookOrder;
import com.quotemedia.datacache.messaging.impl.PriceLevel;
import com.quotemedia.datacache.messaging.impl.DerivativeInfo;
import com.quotemedia.datacache.messaging.impl.IVGreeks;
import com.quotemedia.datacache.messaging.impl.ImbalanceStatus;
import com.quotemedia.datacache.messaging.impl.Interval;
import com.quotemedia.datacache.messaging.impl.LimitUpLimitDown;
import com.quotemedia.datacache.messaging.impl.MMQuote;
import com.quotemedia.datacache.messaging.impl.NethousePosition;
import com.quotemedia.datacache.messaging.impl.PriceData;
import com.quotemedia.datacache.messaging.impl.PurgeBook;
import com.quotemedia.datacache.messaging.impl.Quote;
import com.quotemedia.datacache.messaging.impl.Trade;
import com.quotemedia.qitch.QITCH;
import com.quotemedia.streamer.messages.market.DataMessage;
import com.quotemedia.streamer.messages.market.ImbalanceType;
import com.quotemedia.streamer.messages.market.InstrumentType;
import com.quotemedia.streamer.messages.market.OrderSide;
import com.quotemedia.streamer.messages.market.Tick;
import com.quotemedia.streamer.messages.market.impl.*;
import com.quotemedia.streamer.messages.marketdata.qitch.LimitUpLimitDownDef;
import com.quotemedia.streamer.messages.qmci.Dividend;
import com.quotemedia.streamer.messages.qmci.Earnings;
import com.quotemedia.streamer.messages.qmci.LastSale;
import com.quotemedia.streamer.messages.qmci.News;
import com.quotemedia.streamer.messages.qmci.Split;
import com.quotemedia.streamer.messages.qmci.SymbolChanged;
import com.quotemedia.streamer.messages.qmci.SymbolInfo;
import com.quotemedia.streamer.messages.qmci.SymbolStatus;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * This class defines the mapping between {@link com.quotemedia.datacache.messaging.GenericDataMessage} implementations
 * and {@link com.quotemedia.streamer.messages.market.DataMessage} implementations.
 * 

* Classes extending {@link com.quotemedia.datacache.messaging.GenericDataMessage} are considered internal and therefore * may not be exposed via an external API. */ public final class QmciMessageMapper { private final Map, Mapping> mappings; public QmciMessageMapper() { final DataMessageMapping datamessage = new DataMessageMapping(); final PriceMapping price = new PriceMapping(); final QMDecimalMapping qmDecimal = new QMDecimalMapping(); final QMLongDecimalMapping qmLongDecimal = new QMLongDecimalMapping(); this.mappings = new HashMap<>(); this.mappings.put(com.quotemedia.datacache.messaging.impl.PurgeBook.class, new PurgeBookMapping(datamessage)); this.mappings.put(com.quotemedia.datacache.messaging.impl.BookDelete.class, new BookDeleteMapping(datamessage)); this.mappings.put(com.quotemedia.datacache.messaging.impl.Quote.class, new QuoteMapping(price, qmDecimal)); this.mappings.put(com.quotemedia.datacache.messaging.impl.Interval.class, new IntervalMapping(price, qmLongDecimal)); this.mappings.put(com.quotemedia.datacache.messaging.impl.MMQuote.class, new MMQuoteMapping(price, qmDecimal)); this.mappings.put(com.quotemedia.datacache.messaging.impl.BookOrder.class, new BookOrderMapping(price)); this.mappings.put(PriceLevel.class, new PriceLevelMapping(price)); this.mappings.put(com.quotemedia.datacache.messaging.impl.PriceData.class, new PriceDataMapping(price, qmDecimal, qmLongDecimal)); this.mappings.put(com.quotemedia.datacache.messaging.impl.NethousePosition.class, new NethousePositionMapping(price)); this.mappings.put(com.quotemedia.datacache.messaging.impl.Trade.class, new TradeMapping(price, qmDecimal, qmLongDecimal)); this.mappings.put(com.quotemedia.streamer.messages.qmci.SymbolInfo.class, new SymbolInfoMapping()); this.mappings.put(com.quotemedia.streamer.messages.qmci.SymbolStatus.class, new SymbolStatusMapping(price)); this.mappings.put(com.quotemedia.datacache.messaging.impl.DerivativeInfo.class, new DerivativeInfoMapping(price)); this.mappings.put(LastSale.class, new LastSaleMapping(price, qmLongDecimal)); this.mappings.put(LimitUpLimitDown.class, new LimitUpLimitDownMapping(price)); this.mappings.put(com.quotemedia.datacache.messaging.impl.IVGreeks.class, new IVGreeksMapping()); this.mappings.put(com.quotemedia.datacache.messaging.impl.ImbalanceStatus.class, new ImbalanceStatusMapping(price)); this.mappings.put(com.quotemedia.datacache.messaging.impl.Alert.class, new AlertMapping()); this.mappings.put(News.class, new NewsMapping()); this.mappings.put(com.quotemedia.streamer.messages.qmci.Dividend.class, new DividendMapping(price)); this.mappings.put(com.quotemedia.streamer.messages.qmci.Earnings.class, new EarningsMapping()); this.mappings.put(com.quotemedia.streamer.messages.qmci.Split.class, new SplitMapping()); this.mappings.put(com.quotemedia.streamer.messages.qmci.SymbolChanged.class, new SymbolChangedMapping()); } /** * Maps an instance of {@link com.quotemedia.datacache.messaging.GenericDataMessage} and its state * to an instance of {@link com.quotemedia.streamer.messages.market.DataMessage}.
* If no mapping is defined for {@code object} {@code null} is returned. This makes backward compatibility * maintenance easier. * Additional messages sent from server to client will simply be ignored. * * @param in the message to be mapped. * @return the mapped message. */ public final DataMessage map(final Object in) { if (in == null) { return null; } final Mapping m = this.mappings.get(in.getClass()); if (m == null) { return null; } return m.map(in, m.newimpl()); } /** * Implementations of this interface define the mapping between an instance of {@link I} to an instance of {@link O}. */ private interface Mapping { /** * Called when a new instace of {@link O} is required. * * @return the new instance. */ O newimpl(); /** * Maps an instance of {@link I} an its state to an instance of of {@link O}. * * @param in the instance to map. * @param out the instance to map to. * @return the mapped instance. */ DataMessage map(final I in, final O out); } /** * */ private static final class PurgeBookMapping implements Mapping { private final DataMessageMapping datamessage; public PurgeBookMapping(final DataMessageMapping datamessage) { this.datamessage = datamessage; } @Override public final PurgeBookImpl newimpl() { return new PurgeBookImpl(); } @Override public DataMessage map(final PurgeBook in, final PurgeBookImpl out) { this.datamessage.map(in, out); out.setSymbol(in.getSymbol()); return out; } } /** * */ private static final class BookDeleteMapping implements Mapping { private final DataMessageMapping datamessage; public BookDeleteMapping(final DataMessageMapping datamessage) { this.datamessage = datamessage; } @Override public final BookDeleteImpl newimpl() { return new BookDeleteImpl(); } @Override public final DataMessageImpl map(final com.quotemedia.datacache.messaging.impl.BookDelete in, final BookDeleteImpl out) { this.datamessage.map(in, out); out.setSymbol(in.getSymbol()); out.setOrderReference(in.getOrderReference()); out.setTimestamp(in.getTimestamp()); return out; } } /** * */ private static final class QuoteMapping implements Mapping { private final PriceMapping price; private final QMDecimalMapping qmDecimal; public QuoteMapping(final PriceMapping price, final QMDecimalMapping qmDecimal) { this.price = price; this.qmDecimal = qmDecimal; } @Override public final QuoteImpl newimpl() { return new QuoteImpl(); } @Override public final DataMessageImpl map(final Quote in, final QuoteImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setAskCondition(in.getAskCondition()); out.setAskExcode(in.getAskExcode()); out.setAskPrice(price.map(in.getAskPrice())); out.setAskSize(this.qmDecimal.map(in.getDecimalAskSize())); out.setBidCondition(in.getBidCondition()); out.setBidExcode(in.getBidExcode()); out.setBidPrice(this.price.map(in.getBidPrice())); out.setBidSize(this.qmDecimal.map(in.getDecimalBidSize())); out.setIndicator(in.getIndicator()); out.setSharesPerSizeUnit(in.getSharesPerSizeUnit()); return out; } } /** * */ private static final class IntervalMapping implements Mapping { private final PriceMapping price; private final QMLongDecimalMapping qmLongDecimal; public IntervalMapping(final PriceMapping price, final QMLongDecimalMapping qmLongDecimal) { this.price = price; this.qmLongDecimal = qmLongDecimal; } @Override public IntervalImpl newimpl() { return new IntervalImpl(); } @Override public final DataMessageImpl map(final Interval in, final IntervalImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setHigh(price.map(in.getHigh())); out.setLast(price.map(in.getLast())); out.setLastTime(in.getLastTime()); out.setLow(price.map(in.getLow())); out.setOpen(price.map(in.getOpen())); out.setOpenTime(in.getOpenTime()); out.setStartTime(in.getStartTime()); out.setTradeValue(in.getTradeValue()); out.setVolume(this.qmLongDecimal.map(in.getDecimalVolume())); out.setVWAP(price.map(in.getVWAP())); out.setPeriodMs(in.getPeriodMs()); return out; } } /** * */ private static final class MMQuoteMapping implements Mapping { private final PriceMapping price; private final QMDecimalMapping qmDecimal; public MMQuoteMapping(final PriceMapping price, final QMDecimalMapping qmDecimal) { this.price = price; this.qmDecimal = qmDecimal; } @Override public final MMQuoteImpl newimpl() { return new MMQuoteImpl(); } @Override public final DataMessageImpl map(final MMQuote in, final MMQuoteImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setAskChange(this.price.map(in.getAskChange())); out.setAskPrice(this.price.map(in.getAskPrice())); out.setAskSize(this.qmDecimal.map(in.getDecimalAskSize())); out.setBidChange(this.price.map(in.getBidChange())); out.setBidPrice(this.price.map(in.getBidPrice())); out.setBidSize(this.qmDecimal.map(in.getDecimalBidSize())); out.setIndicator(in.getIndicator()); out.setMarketMakerId(in.getMarketMakerID()); out.setSharesPerSizeUnit(in.getSharesPerSizeUnit()); return out; } } /** * */ private static final class BookOrderMapping implements Mapping { private final PriceMapping price; public BookOrderMapping(final PriceMapping price) { this.price = price; } @Override public final BookOrderImpl newimpl() { return new BookOrderImpl(); } @Override public final DataMessageImpl map(final BookOrder in, final BookOrderImpl out) { out.setSymbol(in.getSymbol()); out.setExcode(in.getExcode()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setFlags(in.getFlags()); out.setLastUpdate(in.getLastUpdate()); out.setMarketMakerId(in.getMarketMakerID()); out.setOrderId(in.getOrderID()); out.setOrderReference(in.getOrderReference()); out.setOrderSide(OrderSideMapping.map(in.getOrderSide())); out.setPrice(this.price.map(in.getPrice())); out.setSize(in.getSize()); out.setDisplay(in.isDisplay()); out.setOrderChangeType(BookOrderChangeTypeMapping.map(in.getOrderChangeType())); return out; } } /** * */ private static final class PriceLevelMapping implements Mapping { private final PriceMapping price; public PriceLevelMapping(final PriceMapping price) { this.price = price; } @Override public final PriceLevelImpl newimpl() { return new PriceLevelImpl(); } @Override public final DataMessageImpl map(final PriceLevel in, final PriceLevelImpl out) { out.setSymbol(in.getSymbol()); out.setExcode(in.getExcode()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setOrderSide(OrderSideMapping.map(in.getOrderSide())); out.setPrice(this.price.map(in.getPrice())); out.setSize(in.getSize()); out.setCount(in.getCount()); out.setBookType(in.getBookType()); out.setChangeType(PriceLevelChangeTypeMapping.map(in.getChangeType())); return out; } } /** * */ private static final class PriceDataMapping implements Mapping { private final PriceMapping price; private final QMDecimalMapping qmDecimal; private final QMLongDecimalMapping qmLongDecimal; public PriceDataMapping(final PriceMapping price, final QMDecimalMapping qmDecimal, final QMLongDecimalMapping qmLongDecimal) { this.price = price; this.qmDecimal = qmDecimal; this.qmLongDecimal = qmLongDecimal; } @Override public final PriceDataImpl newimpl() { return new PriceDataImpl(); } @Override public final DataMessageImpl map(final PriceData in, final PriceDataImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setAccumulatedPrice(this.price.map(in.getAccumulatedPrice())); out.setAccumulatedTradeValue(this.price.map(in.getAccumulatedTradeValue())); out.setAccumulatedVolume(this.qmLongDecimal.map(in.getDecimalAccumulatedVolume())); out.setChange(this.price.map(in.getChange())); out.setClose(this.price.map(in.getClose())); out.setHigh(this.price.map(in.getHigh())); out.setLast(this.price.map(in.getLast())); out.setLastTradeSize(this.qmDecimal.map(in.getDecimalLastTradeSize())); out.setLastTradeTime(in.getLastTradeTime()); out.setLow(this.price.map(in.getLow())); out.setOpen(this.price.map(in.getOpen())); out.setPercentChange(in.getPercentChange()); out.setPreviousClose(this.price.map(in.getPreviousClose())); out.setTick(TickMapping.map(in.getTick())); out.setTradeCount(in.getTicVolume()); out.setTWAP(this.price.map(in.getTWAP())); out.setVWAP(this.price.map(in.getVWAP())); out.setVwapVolume(this.qmLongDecimal.map(in.getDecimalVWAPVolume())); out.setAnnualHigh(in.isAnnualHigh()); out.setAnnualLow(in.isAnnualLow()); out.setPreMarketTradeTime(in.getPreMarketTradeTime()); out.setPreMarketLast(this.price.map(in.getPreMarketLast())); out.setPreMarketVolume(this.qmLongDecimal.map(in.getDecimalPreMarketVolume())); out.setPreMarketChange(this.price.map(in.getPreMarketChange())); out.setPreMarketPercentChange(in.getPreMarketPercentChange()); out.setPostMarketTradeTime(in.getPostMarketTradeTime()); out.setPostMarketLast(this.price.map(in.getPostMarketLast())); out.setPostMarketVolume(this.qmLongDecimal.map(in.getDecimalPostMarketVolume())); out.setPostMarketChange(this.price.map(in.getPostMarketChange())); out.setPostMarketPercentChange(in.getPostMarketPercentChange()); out.setLastTradeExcode(in.getLastTradeExcode()); out.setCurrencyID(in.getCurrencyID()); return out; } } /** * */ private static final class NethousePositionMapping implements Mapping { private final PriceMapping price; public NethousePositionMapping(final PriceMapping price) { this.price = price; } @Override public final NethousePositionImpl newimpl() { return new NethousePositionImpl(); } @Override public final DataMessageImpl map(final NethousePosition in, final NethousePositionImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setBuyBlockTransactions(in.getBuyBlockTransactions()); out.setBuyBlockValue(this.price.map(in.getBuyBlockValue())); out.setBuyBlockVolume(in.getBuyBlockVolume()); out.setBuyTransactions(in.getBuyTransactions()); out.setBuyValue(this.price.map(in.getBuyValue())); out.setBuyVolume(in.getBuyVolume()); out.setMarketMakerId(in.getMarketMakerID()); out.setSellBlockTransactions(in.getSellBlockTransactions()); out.setSellBlockValue(this.price.map(in.getSellBlockValue())); out.setSellBlockVolume(in.getSellBlockVolume()); out.setSellTransactions(in.getSellTransactions()); out.setSellValue(this.price.map(in.getSellValue())); out.setSellVolume(in.getSellVolume()); return out; } } /** * */ private static final class TradeMapping implements Mapping { private final PriceMapping price; private final QMDecimalMapping qmDecimal; private final QMLongDecimalMapping qmLongDecimal; public TradeMapping(final PriceMapping price, final QMDecimalMapping qmDecimal, final QMLongDecimalMapping qmLongDecimal) { this.price = price; this.qmDecimal = qmDecimal; this.qmLongDecimal = qmLongDecimal; } @Override public final TradeImpl newimpl() { return new TradeImpl(); } @Override public final DataMessageImpl map(final Trade in, final TradeImpl out) { out.setSymbol(in.getSymbol()); out.setExcode(in.getExcode()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setAccumumlatedVolume(this.qmLongDecimal.map(in.getDecimalAccumulatedVolume())); out.setBuyerId(in.getBuyerID()); out.setFlags(in.getFlags()); out.setIndicator(in.getIndicator()); out.setMatchId(in.getMatchID()); out.setPrice(this.price.map(in.getPrice())); out.setRangeIndicator(RangeIndicatorMapping.map(in.getRangeIndicator())); out.setSellerId(in.getSellerID()); out.setSequenceNumber(in.getSequenceNumber()); out.setSize(this.qmDecimal.map(in.getDecimalSize())); out.setTick(TickMapping.map(in.getTick())); out.setVWAP(this.price.map(in.getVWAP())); return out; } } /** * */ private static final class SymbolInfoMapping implements Mapping { @Override public SymbolInfoImpl newimpl() { return new SymbolInfoImpl(); } @Override public DataMessage map(final SymbolInfo in, final SymbolInfoImpl out) { out.setSymbol(in.getSymbol()); out.setExcode(in.getExcode()); out.setLocateCode(in.getLocateCode()); out.setInstrumenttype(InstrumentTypeMapping.map(in.getInstrumentType())); out.setCurrendyId(in.getCurrencyId()); out.setHaltStatus(in.getHaltStatus()); out.setHaltIndicator(in.getHaltIndicator()); out.setRegSHOStatus(in.getRegSHOStatus()); out.setPqe(in.getPqe()); out.setCaveatEmptor(in.getCaveatEmptor()); out.setBoardLotSize(in.getBoardLotSize()); return out; } } /** * */ private static final class SymbolStatusMapping implements Mapping { private final PriceMapping price; public SymbolStatusMapping(PriceMapping price) { this.price = price; } @Override public SymbolStatusImpl newimpl() { return new SymbolStatusImpl(); } @Override public DataMessage map(final SymbolStatus in, final SymbolStatusImpl out) { out.setSymbol(in.getSymbol()); out.setHaltIndicator(in.getHaltIndicator()); out.setHaltStatus(in.getHaltStatus()); out.setRegSHOStatus(in.getRegSHOStatus()); out.setClosingCalculatedPrice(this.price.map(in.getClosingCalculatedPrice())); out.setEffectiveTime(in.getEffectiveTime()); out.setOpeningTime(in.getOpeningTime()); out.setNote(in.getNote()); return out; } } private static final class DerivativeInfoMapping implements Mapping { private final PriceMapping price; public DerivativeInfoMapping(final PriceMapping price) { this.price = price; } @Override public DerivativeInfoImpl newimpl() { return new DerivativeInfoImpl(); } @Override public DataMessage map(final DerivativeInfo in, final DerivativeInfoImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setRootSymbol(in.getRootSymbol()); out.setExpiration(in.getExpiration()); out.setDelivery(in.getDelivery()); out.setOpenInterest(in.getOpenInterest()); out.setContractSize(in.getContractSize()); out.setCallPutIndicator(in.getCallPutIndicator()); out.setMinTickSize(this.price.map(in.getMinTickSize())); return out; } } private static final class LastSaleMapping implements Mapping { private final PriceMapping price; private final QMLongDecimalMapping qmLongDecimal; public LastSaleMapping(final PriceMapping price, final QMLongDecimalMapping qmLongDecimal) { this.price = price; this.qmLongDecimal = qmLongDecimal; } @Override public LastSaleImpl newimpl() { return new LastSaleImpl(); } @Override public DataMessage map(final LastSale in, final LastSaleImpl out) { out.setTimestamp(in.getTimestamp()); out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setLast(this.price.map(in.getLast())); out.setPreviousClose(this.price.map(in.getPreviousClose())); out.setAccumulatedVolume(this.qmLongDecimal.map(in.getDecimalAccumulatedVolume())); out.setChange(this.price.map(in.getChange())); out.setPercentChange(in.getPercentChange()); out.setTick(TickMapping.map(in.getTick())); out.setLastTradeExcode(in.getLastTradeExcode()); return out; } } private static final class LimitUpLimitDownMapping implements Mapping { private final PriceMapping price; private LimitUpLimitDownMapping(final PriceMapping price) { this.price = price; } @Override public LimitUpLimitDownImpl newimpl() { return new LimitUpLimitDownImpl(); } @Override public DataMessage map(final LimitUpLimitDown in, final LimitUpLimitDownImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setEffectiveTime(in.getEffectiveTime()); out.setLowerLimit(price.map(in.getLowerLimit())); out.setUpperLimit(price.map(in.getUpperLimit())); out.setIsBidNotExecutable(QITCH.isSet(in.getPriceBandIndicator(), LimitUpLimitDownDef.Flags.BID_NOT_EXECUTABLE)); out.setIsAskNotExecutable(QITCH.isSet(in.getPriceBandIndicator(), LimitUpLimitDownDef.Flags.ASK_NOT_EXECUTABLE)); return out; } } private static final class IVGreeksMapping implements Mapping { @Override public IVGreeksImpl newimpl() { return new IVGreeksImpl(); } @Override public DataMessage map(IVGreeks in, IVGreeksImpl out) { out.setSymbol(in.getSymbol()); out.setLastCalculation(new Date(in.getLastCalculation())); out.setDelta(in.getDelta()); out.setGamma(in.getGamma()); out.setVega(in.getVega()); out.setRho(in.getRho()); out.setTheta(in.getTheta()); out.setImpliedVolatility(in.getStrikeIV()); out.setImpliedVolatilityChange(in.getStrikeIVChange()); out.setBidImpliedVolatility(in.getBidIV()); out.setAskImpliedVolatility(in.getAskIV()); out.setMark(in.getMark()); out.setIntrinsicValue(in.getIntrinsicValue()); out.setExtrinsicValue(in.getExtrinsicValue()); out.setPreviousMark(in.getPreviousMark()); out.setMarkChange(in.getMarkChange()); out.setMarkChangePercent(in.getMarkChangePercent()); return out; } } private static final class ImbalanceStatusMapping implements Mapping { private final PriceMapping price; private ImbalanceStatusMapping(final PriceMapping price) { this.price = price; } @Override public ImbalanceStatusImpl newimpl() { return new ImbalanceStatusImpl(); } @Override public DataMessage map(ImbalanceStatus in, ImbalanceStatusImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setImbalanceType(ImbalanceTypeMapping.map(in.getImbalanceType())); out.setSide(OrderSideMapping.map(in.getSide())); out.setReferencePrice(price.map(in.getReferencePrice())); out.setSize(in.getSize()); out.setPairedVolume(in.getPairedVolume()); out.setNearIndicativePrice(price.map(in.getNearIndicativePrice())); out.setFarIndicativePrice(price.map((in.getFarIndicativePrice()))); out.setPriceVariation(in.getPriceVariation()); return out; } } /** * */ private static final class AlertMapping implements Mapping { @Override public final AlertImpl newimpl() { return new AlertImpl(); } @Override public final DataMessageImpl map(final Alert in, final AlertImpl out) { out.setSymbol(in.getSymbol()); out.setLocateCode(in.getLocateCode()); out.setTimestamp(in.getTimestamp()); out.setInstrumenttype(InstrumentTypeMapping.map(in.getInstrumentType())); out.setAlertId(in.getAlertId()); out.setTriggerValue(in.getTriggerValue()); return out; } } /** * */ private static final class NewsMapping implements Mapping { @Override public final NewsImpl newimpl() { return new NewsImpl(); } @Override public final DataMessageImpl map(final News in, final NewsImpl out) { //TODO return out; } } private static final class DividendMapping implements Mapping { private final PriceMapping price; private DividendMapping(final PriceMapping price) { this.price = price; } @Override public DividendImpl newimpl() { return new DividendImpl(); } @Override public DataMessage map(Dividend in, DividendImpl out) { out.setOccuredOn(in.getOccuredOn()); out.setSymbolId(in.getSymbolId()); out.setSymbol(in.getSymbol()); out.setAmount(price.map(in.getAmount())); out.setDeclarationDate(in.getDeclarationDate()); out.setExecutionDate(in.getExecutionDate()); out.setRecordDate(in.getRecordDate()); out.setPaymentDate(in.getPaymentDate()); out.setPaymentType(in.getPaymentType()); out.setFrequency(in.getFrequency()); return out; } } private static final class EarningsMapping implements Mapping { private EarningsMapping() { } @Override public EarningsImpl newimpl() { return new EarningsImpl(); } @Override public DataMessage map(Earnings in, EarningsImpl out) { out.setOccuredOn(in.getOccuredOn()); out.setSymbolId(in.getSymbolId()); out.setSymbol(in.getSymbol()); out.setFiscalYear(in.getFiscalYear()); out.setQuarter(in.getQuarter()); out.setEarningsPerShare(in.getEarningsPerShare()); out.setAnnouncementDate(in.getAnnouncementDate()); out.setAnnouncementTimeOfDay(in.getAnnouncementTimeOfDay()); out.setAnnouncementUrl(in.getAnnouncementUrl()); return out; } } private static final class SplitMapping implements Mapping { private SplitMapping() { } @Override public SplitImpl newimpl() { return new SplitImpl(); } @Override public DataMessage map(Split in, SplitImpl out) { out.setOccuredOn(in.getOccuredOn()); out.setSymbolId(in.getSymbolId()); out.setSymbol(in.getSymbol()); out.setExecutionDate(in.getExecutionDate()); out.setDeclarationDate(in.getDeclarationDate()); out.setRecordDate(in.getRecordDate()); out.setPaymentDate(in.getPaymentDate()); out.setRatio(in.getRatio()); out.setRatioNumerator(in.getRatioNumerator()); out.setRatioDenominator(in.getRatioDenominator()); return out; } } private static final class SymbolChangedMapping implements Mapping { private SymbolChangedMapping() { } @Override public SymbolChangedImpl newimpl() { return new SymbolChangedImpl(); } @Override public DataMessage map(SymbolChanged in, SymbolChangedImpl out) { out.setSymbolId(in.getSymbolId()); out.setSymbol(in.getSymbol()); out.setOldSymbol(in.getOldSymbol()); out.setNewSymbol(in.getNewSymbol()); out.setDay(in.getDay()); return out; } } /** * */ private static final class DataMessageMapping { private DataMessageImpl map(final GenericDataMessage in, final DataMessageImpl out) { return out; } } /** * */ private static abstract class InstrumentTypeMapping { public static final InstrumentType map(final com.quotemedia.datacache.data.InstrumentType in) { if (in == null) { return null; } switch (in) { case BOND: return InstrumentType.BOND; case CASH: return InstrumentType.CASH; case COMPOSITE: return InstrumentType.COMPOSITE; case FUTURE: return InstrumentType.FUTURE; case FUTURE_OPTION: return InstrumentType.FUTURE_OPTION; case FOREX: return InstrumentType.FOREX; case INDEX: return InstrumentType.INDEX; case MUTUAL_FUND: return InstrumentType.MUTUAL_FUND; case MONEY_MARKET_FUND: return InstrumentType.MONEY_MARKET_FUND; case MARKET_STAT: return InstrumentType.MARKET_STAT; case EQUITY: return InstrumentType.EQUITY; case EQUITY_OPTION: return InstrumentType.EQUITY_OPTION; case GOVT_BOND: return InstrumentType.GOVT_BOND; case MUNI_BOND: return InstrumentType.MUNI_BOND; case CORP_BOND: return InstrumentType.CORP_BOND; case ETF: return InstrumentType.ETF; case FUTURE_SPREAD: return InstrumentType.FUTURE_SPREAD; case OPTION_ROOT: return InstrumentType.OPTION_ROOT; case UNKNOWN: return InstrumentType.UNKNOWN; case RATE: return InstrumentType.RATE; default: return null; } } } /** * */ private static abstract class ImbalanceTypeMapping { public static final ImbalanceType map(final com.quotemedia.datacache.data.ImbalanceType in) { if (in == null) { return null; } switch (in) { case None: return ImbalanceType.NONE; case Market: return ImbalanceType.MARKET; case MOC: return ImbalanceType.MOC; case Regulatory: return ImbalanceType.REGULATORY_IMBALANCE; case Opening: return ImbalanceType.OPENING_IMBALANCE; case Unknown: return ImbalanceType.UNKNOWN; case IPO: return ImbalanceType.IPO_IMBALANCE; case Halt: return ImbalanceType.HALT_IMBALANCE; case Equilibrium: return ImbalanceType.EQUILIBRIUM; default: return null; } } } /** * */ private static abstract class OrderSideMapping { public static final OrderSide map(final com.quotemedia.datacache.data.OrderSide in) { if (com.quotemedia.datacache.data.OrderSide.BUYSIDE == in) { return OrderSide.BUYSIDE; } else if (com.quotemedia.datacache.data.OrderSide.SELLSIDE == in) { return OrderSide.SELLSIDE; } else { return null; } } } /** * */ private static final class PriceMapping { public final Double map(final com.quotemedia.datacache.data.Price in) { return in != null ? in.doubleValue() : null; } } /** * */ private static final class QMDecimalMapping { public final Double map(final com.quotemedia.datacache.data.QMDecimal in) { return in != null ? in.doubleValue() : null; } } /** * */ private static final class QMLongDecimalMapping { public final Double map(final com.quotemedia.datacache.data.QMLongDecimal in) { return in != null ? in.doubleValue() : null; } } /** * */ private static abstract class TickMapping { public static final Tick map(final com.quotemedia.datacache.data.Tick in) { if (com.quotemedia.datacache.data.Tick.DOWN == in) { return Tick.DOWN; } else if (com.quotemedia.datacache.data.Tick.NONE == in) { return Tick.NONE; } else if (com.quotemedia.datacache.data.Tick.UP == in) { return Tick.UP; } else { return null; } } } private static abstract class BookOrderChangeTypeMapping { public static com.quotemedia.streamer.messages.market.BookOrder.ChangeType map(final BookOrder.ORDERCHANGE_TYPE in) { switch (in) { case ADD: return com.quotemedia.streamer.messages.market.BookOrder.ChangeType.ADD; case CANCEL: return com.quotemedia.streamer.messages.market.BookOrder.ChangeType.CANCEL; case EXECUTE: return com.quotemedia.streamer.messages.market.BookOrder.ChangeType.EXECUTE; case MODIFY: return com.quotemedia.streamer.messages.market.BookOrder.ChangeType.MODIFY; default: return null; } } } private static abstract class PriceLevelChangeTypeMapping { public static com.quotemedia.streamer.messages.market.PriceLevel.ChangeType map(final PriceLevel.CHANGE_TYPE in) { switch (in) { case ADD: return com.quotemedia.streamer.messages.market.PriceLevel.ChangeType.ADD; case MODIFY: return com.quotemedia.streamer.messages.market.PriceLevel.ChangeType.MODIFY; case REMOVE: return com.quotemedia.streamer.messages.market.PriceLevel.ChangeType.REMOVE; case CLEAR: return com.quotemedia.streamer.messages.market.PriceLevel.ChangeType.CLEAR; default: return null; } } } /** * */ private static abstract class RangeIndicatorMapping { public static final com.quotemedia.streamer.messages.market.Trade.RangeIndicator map(final RangeIndicator in) { if (RangeIndicator.BUYSIDE == in) { return com.quotemedia.streamer.messages.market.Trade.RangeIndicator.BUYSIDE; } else if (RangeIndicator.SELLSIDE == in) { return com.quotemedia.streamer.messages.market.Trade.RangeIndicator.SELLSIDE; } else if (RangeIndicator.INRANGE == in) { return com.quotemedia.streamer.messages.market.Trade.RangeIndicator.INRANGE; } else if (RangeIndicator.UNKNOWN == in) { return com.quotemedia.streamer.messages.market.Trade.RangeIndicator.UNKNOWN; } else { return null; } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy