001    /**
002     * Copyright 2007 Mike Kroutikov.
003     *
004     * This program is free software; you can redistribute it and/or modify
005     *   it under the terms of the Lesser GNU General Public License as 
006     *   published by the Free Software Foundation; either version 3 of
007     *   the License, or (at your option) any later version.
008     *
009     *   This program is distributed in the hope that it will be useful,
010     *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     *   Lesser GNU General Public License for more details.
013     *
014     *   You should have received a copy of the Lesser GNU General Public License
015     *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
016     *   
017     *   Derived from code developed by Opentick Corporation, http://www.opentick.com.
018     */
019    
020    package org.otfeed.event;
021    
022    import static org.otfeed.event.IdentityUtil.equalsTo;
023    import static org.otfeed.event.IdentityUtil.safeCompare;
024    import static org.otfeed.event.IdentityUtil.safeHashCode;
025    
026    import java.io.Serializable;
027    import java.util.Date;
028    
029    /**
030     * This class provides the level II quote provided by a market maker for NASDAQ equities, or regional quotes for listed stocks.
031     * The market maker ID (MMID) identifies which specific market participant has changed his quote.
032     * In the case of NASDAQ, the MMID is a string identifying the market maker. From SIAC and OPRA,
033     * the quotes are from regional exchanges, and the MMID identifies the exchange that the regional quote comes from.
034     */
035    public final class OTMMQuote implements Comparable<OTMMQuote>, Serializable {
036     
037            private static final long serialVersionUID = -4591121602837458929L;
038            
039            private Date timestamp;
040        private int bidSize;
041        private int askSize;
042        private double bidPrice;
043        private double askPrice;
044        private String MMID;
045        private char indicator;
046        private String exchange;
047        private String symbol;
048    
049        /**
050         * Default constructor.
051         */
052        public OTMMQuote() { }
053    
054        /**
055         * Constructor.
056         * @param timestamp Time when the event occurred.
057         * @param bidSize Number of round lots in the bid.
058         * @param bidPrice Bid price.
059         * @param askSize Number of round lots in the ask.
060         * @param askPrice Ask price.
061         * @param MMID Market Maker ID.
062         * @param indicator Indicator.
063         * @param exchange
064         * @param symbol Symbol code.
065         */
066        public OTMMQuote(Date timestamp, 
067                    int bidSize, 
068                    double bidPrice, 
069                    int askSize, 
070                    double askPrice, 
071                    String MMID, 
072                    char indicator, 
073                    String exchange, 
074                    String symbol) {
075            this.timestamp = timestamp;
076            this.bidSize = bidSize;
077            this.bidPrice = bidPrice;
078            this.askSize = askSize;
079            this.askPrice = askPrice;
080            this.MMID = MMID;
081            this.indicator = indicator;
082            this.exchange = exchange;
083            this.symbol = symbol;
084        }
085    
086         /**
087         * 
088         * @return Time when the event occurred.
089         */
090        public Date getTimestamp() {
091            return timestamp;
092        }
093    
094        /**
095         * Sets time of the event.
096         * @param timestamp Time when the event occurred.
097         */
098        public void setTimestamp(Date timestamp) {
099            this.timestamp = timestamp;
100        }
101    
102        /**
103         * 
104         * @return Number of round lots in the bid.
105         */
106        public int getBidSize() {
107            return bidSize;
108        }
109    
110        /**
111         * Sets ask price.
112         * @param bidSize Ask price.
113         */
114        public void setBidSize(int bidSize) {
115            this.bidSize = bidSize;
116        }
117    
118        /**
119         *
120         * @return Bid price.
121         */
122        public double getBidPrice() {
123            return bidPrice;
124        }
125    
126        /**
127         * Sets bid price.
128         * @param bidPrice Bid price.
129         */
130        public void setBidPrice(double bidPrice) {
131            this.bidPrice = bidPrice;
132        }
133    
134        /**
135         *
136         * @return Number of round lots in the ask.
137         */
138        public int getAskSize() {
139            return askSize;
140        }
141    
142        /**
143         * Sets number of round lots in the ask.
144         * @param askSize Number of round lots in the ask.
145         */
146        public void setAskSize(int askSize) {
147            this.askSize = askSize;
148        }
149    
150        /**
151         *
152         * @return Ask price.
153         */
154        public double getAskPrice() {
155            return askPrice;
156        }
157    
158        /**
159         * Sets ask price.
160         * @param askPrice Ask price.
161         */
162        public void setAskPrice(double askPrice) {
163            this.askPrice = askPrice;
164        }
165    
166        /**
167         *
168         * @return Market Maker ID.
169         */
170        public String getMMID() {
171            return MMID;
172        }
173    
174        /**
175         * Sets market maker id.
176         * @param MMID Market Maker ID.
177         */
178        public void setMMID(String MMID) {
179            this.MMID = MMID;
180        }
181    
182        /**
183         * 
184         * @return Indicator.
185         */
186        public char getIndicator() {
187            return indicator;
188        }
189    
190        /**
191         * Sets indicator.
192         * @param indicator Indicator.
193         */
194        public void setIndicator(char indicator) {
195            this.indicator = indicator;
196        }
197    
198        /**
199         * 
200         * @return Exchange code.
201         */
202        public String getExchange() {
203            return exchange;
204        }
205    
206        /**
207         * Sets exchange code.
208         * @param exchange Exchange code.
209         */
210        public void setExchange(String exchange) {
211            this.exchange = exchange;
212        }
213    
214        /**
215         * 
216         * @return Symbol code; this field is provided for option chains only, because there can be more than one symbol appropriate to the requested underlyer and expiry date.
217         */
218        public String getSymbol() {
219            return symbol;
220        }
221    
222        /**
223         * Symbol code.
224         * @param symbol Symbol code.
225         */
226        public void setSymbol(String symbol) {
227            this.symbol = symbol;
228        }
229    
230        @Override
231            public String toString() {
232            return "OTMMQuote: timestamp=" + timestamp + ", askprice=" + askPrice + ", bidprice=" + bidPrice + ", asksize=" + askSize + ", bidsize=" + bidSize + ", mmid=" + MMID + ", indicator=" + indicator + ", exchange=" + exchange + ", symbol=" + symbol;
233        }
234    
235        @Override
236            public int hashCode() {
237            return safeHashCode(timestamp) 
238                    + 3 * safeHashCode(bidSize) 
239                    + 5 * safeHashCode(askSize) 
240                    + 7 * safeHashCode(bidPrice)
241                    + 11 * safeHashCode(askPrice)
242                    + 13 * safeHashCode(MMID)
243                    + 17 * safeHashCode(indicator)
244                    + 29 * safeHashCode(exchange)
245                    + 31 * safeHashCode(symbol);
246        }
247            
248        @Override
249            public boolean equals(Object o) {
250            return equalsTo(this, o);
251        }
252        
253            public int compareTo(OTMMQuote other) {
254                    int rc;
255    
256                    if((rc = safeCompare(timestamp, other.timestamp)) != 0) {
257                            return rc;
258                    }
259                    
260                    if((rc = safeCompare(bidSize, other.bidSize)) != 0) {
261                            return rc;
262                    }
263                    
264                    if((rc = safeCompare(askSize, other.askSize)) != 0) {
265                            return rc;
266                    }
267    
268                    if((rc = safeCompare(bidPrice, other.bidPrice)) != 0) {
269                            return rc;
270                    }
271    
272                    if((rc = safeCompare(askPrice, other.askPrice)) != 0) {
273                            return rc;
274                    }
275    
276                    if((rc = safeCompare(MMID, other.MMID)) != 0) {
277                            return rc;
278                    }
279                    
280                    if((rc = safeCompare(indicator, other.indicator)) != 0) {
281                            return rc;
282                    }
283    
284                    if((rc = safeCompare(exchange, other.exchange)) != 0) {
285                            return rc;
286                    }
287    
288                    if((rc = safeCompare(symbol, other.symbol)) != 0) {
289                            return rc;
290                    }
291    
292                    return 0;
293            }
294    }