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.util.Date;
020
021 import org.otfeed.*;
022 import org.otfeed.command.*;
023 import org.otfeed.event.*;
024
025 /**
026 * Requests live feed of book events.
027 * For example, calling it with parameters
028 * <pre>
029 * is AAPL
030 * </pre>
031 * during market hours of Island Book will produce live feed of book events.
032 *
033 * @author Anonymous Contributor.
034 */
035 public class BookStream {
036
037 public static void main(String ... args) throws Throwable {
038
039 if(args.length != 2) {
040 System.out.println("USAGE: " + BookStream.class.getName() + " <exchangeName> <symbolName>");
041 System.exit(-1);
042 }
043
044 System.out.println("# generated by " + BookStream.class + " on " + (new Date()));
045 System.out.println("#");
046 System.out.println("# stream data for: " + args[0] + "/" + args[1]);
047
048 BookStreamCommand command = new BookStreamCommand(args[0],args[1]);
049 command.setCancelDelegate(new IDataDelegate<OTBookCancel>() {
050 public void onData(OTBookCancel data) {
051 System.out.println(data);
052 }
053 });
054 command.setChangeDelegate(new IDataDelegate<OTBookChange>() {
055 public void onData(OTBookChange data) {
056 System.out.println(data);
057 }
058 });
059 command.setDeleteDelegate(new IDataDelegate<OTBookDelete>() {
060 public void onData(OTBookDelete data) {
061 System.out.println(data);
062 }
063 });
064 command.setExecuteDelegate(new IDataDelegate<OTBookExecute>() {
065 public void onData(OTBookExecute data) {
066 System.out.println(data);
067 }
068 });
069 command.setOrderDelegate(new IDataDelegate<OTBookOrder>() {
070 public void onData(OTBookOrder data) {
071 System.out.println(data);
072 }
073 });
074 command.setPriceLevelDelegate(new IDataDelegate<OTBookPriceLevel>() {
075 public void onData(OTBookPriceLevel data) {
076 System.out.println(data);
077 }
078 });
079 command.setPurgeDelegate(new IDataDelegate<OTBookPurge>() {
080 public void onData(OTBookPurge data) {
081 System.out.println(data);
082 }
083 });
084 command.setReplaceDelegate(new IDataDelegate<OTBookReplace>() {
085 public void onData(OTBookReplace data) {
086 System.out.println(data);
087 }
088 });
089
090 command.setCompletionDelegate(new ICompletionDelegate() {
091 public void onDataEnd(OTError error) {
092 if(error != null) {
093 System.out.println("# Error: " + error);
094 }
095 }
096 });
097
098 System.out.println("#");
099
100 IConnection connection = Connector.connect();
101
102 try {
103 IRequest request = connection.prepareRequest(command);
104 request.submit();
105
106 request.waitForCompletion();
107 } finally {
108 connection.shutdown();
109 connection.waitForCompletion();
110 }
111 }
112 }
113