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    
018    package org.otfeed.command;
019    
020    import java.util.Date;
021    
022    import org.otfeed.event.IDataDelegate;
023    import org.otfeed.event.OTOHLC;
024    import org.otfeed.protocol.ICommand;
025    
026    /**
027     * Request for the historical aggregated {@link OTOHLC OHLC} (open-high-low-close) data.
028     * <p/>
029     * The aggregation span varies from 2 ticks to years. Default
030     * aggregation span is 1 day.
031     * <p/>
032     * Generates {@link OTOHLC ohlc} events.
033     * <p/>
034     * For the request to receive raw ticks data (not aggregated),
035     * see {@link HistTicksCommand}.
036     */
037    public final class HistDataCommand 
038                    extends ExchangeSymbolAndDatesHolder implements ICommand {
039    
040            /**
041             * Creates new historical data command, initializing all 
042             * its properties.
043             * 
044             * @param exchangeCode echange code.
045             * @param symbolCode symbol code.
046             * @param startDate start date.
047             * @param endDate end date.
048             * @param aggregationSpan aggregation time span.
049             * @param dataDelegate delegate.
050             */
051            public HistDataCommand(String exchangeCode,
052                            String symbolCode,
053                            Date startDate,
054                            Date endDate,
055                            AggregationSpan aggregationSpan,
056                            IDataDelegate<OTOHLC> dataDelegate) {
057                    setExchangeCode(exchangeCode);
058                    setSymbolCode(symbolCode);
059                    setStartDate(startDate);
060                    setEndDate(endDate);
061                    setAggregationSpan(aggregationSpan);
062                    setDataDelegate(dataDelegate);
063            }
064            
065            /**
066             * Default constructor. 
067             * Initializes {@link #getAggregationSpan aggregationSpan}
068             * to its default value of 1 day.
069             * All other properties must be set explicitly before
070             * using this command object.
071             */
072            public HistDataCommand() {
073                    this(null, null, null, null, 
074                                    AggregationSpan.days(1), null);
075            }
076    
077            /**
078             * Creates new historical data command with default
079             * aggregation interval of one day.
080             * 
081             * {@link #getAggregationSpan Aggreagation span}
082             * is set to one day.
083             * 
084             * @param exchangeCode exchange code.
085             * @param symbolCode symbol code.
086             * @param startDate start date.
087             * @param endDate end date.
088             * @param dataDelegate data delegate.
089             */
090            public HistDataCommand(String exchangeCode,
091                            String symbolCode, 
092                            Date startDate,
093                            Date endDate,
094                            IDataDelegate<OTOHLC> dataDelegate) {
095                    this(exchangeCode, symbolCode, 
096                                    startDate, endDate,
097                                    AggregationSpan.days(1), 
098                                    dataDelegate);
099            }
100            
101            private AggregationSpan aggregationSpan;
102            
103            /**
104             * Determines the length of the aggregation interval, e.g.
105             * {@link AggregationSpan#hours}.
106             * 
107             * @return aggregation span.
108             */
109            public AggregationSpan getAggregationSpan() {
110                    return aggregationSpan;
111            }
112            
113            /**
114             * Sets aggregation span.
115             * 
116             * @param val
117             */
118            public void setAggregationSpan(AggregationSpan val) {
119                    aggregationSpan = val;
120            }
121    
122            private IDataDelegate<OTOHLC> dataDelegate;
123    
124            /**
125             * Delegate to receive {@link OTOHLC} events.
126             * This parameter is mandatory.
127             * 
128             * @return delegate.
129             */
130            public IDataDelegate<OTOHLC> getDataDelegate() {
131                    return dataDelegate;
132            }
133    
134            /**
135             * Sets delegate.
136             * 
137             * @param dataDelegate delegate.
138             */
139            public void setDataDelegate(IDataDelegate<OTOHLC> dataDelegate) {
140                    this.dataDelegate = dataDelegate;
141            }
142    }