001 /**
002 * Copyright 2007 Mike Kroutikov and contributors.
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 package org.otfeed.samples;
018
019 import java.text.DateFormat;
020 import java.text.SimpleDateFormat;
021 import java.util.Date;
022
023 import org.otfeed.*;
024 import org.otfeed.command.*;
025 import org.otfeed.event.*;
026
027 /**
028 * Requests historical book data at tick resolution.
029 *
030 * @author Anonymous Contributor.
031 */
032 public class HistBooks {
033
034 public static void main(String ... args) throws Throwable {
035
036 if(args.length != 4) {
037 System.out.println("USAGE: " + HistBooks.class.getName() + " <exchangeName> <symbolName> <startDate> <endDate>");
038 System.exit(-1);
039 }
040
041 DateFormat format = new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss");
042 Date start = format.parse(args[2]);
043 Date end = format.parse(args[3]);
044 System.out.println("# generated by " + HistBooks.class + " on " + (new Date()));
045 System.out.println("#");
046 System.out.println("# history data for: " + args[0] + "/" + args[1]);
047
048 HistBooksCommand command = new HistBooksCommand(args[0],args[1],start,end);
049
050 command.setCancelDelegate(new IDataDelegate<OTBookCancel>() {
051 public void onData(OTBookCancel data) {
052 System.out.println(data);
053 }
054 });
055 command.setChangeDelegate(new IDataDelegate<OTBookChange>() {
056 public void onData(OTBookChange data) {
057 System.out.println(data);
058 }
059 });
060 command.setDeleteDelegate(new IDataDelegate<OTBookDelete>() {
061 public void onData(OTBookDelete data) {
062 System.out.println(data);
063 }
064 });
065 command.setExecuteDelegate(new IDataDelegate<OTBookExecute>() {
066 public void onData(OTBookExecute data) {
067 System.out.println(data);
068 }
069 });
070 command.setOrderDelegate(new IDataDelegate<OTBookOrder>() {
071 public void onData(OTBookOrder data) {
072 System.out.println(data);
073 }
074 });
075 command.setPriceLevelDelegate(new IDataDelegate<OTBookPriceLevel>() {
076 public void onData(OTBookPriceLevel data) {
077 System.out.println(data);
078 }
079 });
080 command.setPurgeDelegate(new IDataDelegate<OTBookPurge>() {
081 public void onData(OTBookPurge data) {
082 System.out.println(data);
083 }
084 });
085 command.setReplaceDelegate(new IDataDelegate<OTBookReplace>() {
086 public void onData(OTBookReplace data) {
087 System.out.println(data);
088 }
089 });
090
091 command.setCompletionDelegate(new ICompletionDelegate() {
092 public void onDataEnd(OTError error) {
093 if(error != null) {
094 System.out.println("# Error: " + error);
095 }
096 }
097 });
098
099 System.out.println("# start timestamp: " + start);
100 System.out.println("# end timestamp: " + end);
101 System.out.println("#");
102
103 IConnection connection = Connector.connect();
104
105 try {
106 IRequest request = connection.prepareRequest(command);
107 request.submit();
108
109 request.waitForCompletion();
110 } finally {
111 connection.shutdown();
112 connection.waitForCompletion();
113 }
114 }
115 }
116