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.samples;
019    
020    import java.util.Date;
021    
022    import org.otfeed.IConnection;
023    import org.otfeed.IRequest;
024    import org.otfeed.command.TodaysOHLCommand;
025    import org.otfeed.event.ICompletionDelegate;
026    import org.otfeed.event.IDataDelegate;
027    import org.otfeed.event.OTError;
028    import org.otfeed.event.OTTodaysOHL;
029    
030    /**
031     * Sample application: requests current OHL (Open/High/Low) data.
032     */
033    public class TodaysOHL {
034    
035            public static void main(String ... args) throws Exception {
036    
037                    if(args.length != 2) {
038                            System.out.println("USAGE: TodayOHL <exchangeName> <symbolName>");
039                            System.exit(-1);
040                    }
041    
042                    System.out.println("# generated by " + TodaysOHL.class + " on " + FormatUtil.DATE_FORMAT_AS_STRING.format(new Date()));
043                    System.out.println("#");
044                    System.out.println("# today's ohl data for: " + args[0] + "/" + args[1]);
045                    System.out.println("#");
046                    
047                    TodaysOHLCommand command = new TodaysOHLCommand();
048                    command.setExchangeCode(args[0]);
049                    command.setSymbolCode(args[1]);
050                    command.setDataDelegate(new IDataDelegate<OTTodaysOHL>() {
051                            public void onData(OTTodaysOHL data) {
052                                    System.out.println(data);
053                            }
054                    });
055    
056                    command.setCompletionDelegate(new ICompletionDelegate() {
057                            public void onDataEnd(OTError error) {
058                                    if(error != null) {
059                                            System.out.println("# Error: " + error);
060                                    }
061                            }
062                    });
063                    
064                    IConnection connection = Connector.connect();
065                    
066                    try {
067                            IRequest request = connection.prepareRequest(command);
068    
069                            request.submit();
070                            request.waitForCompletion();
071    
072                    } finally {
073    
074                            connection.shutdown();
075                            connection.waitForCompletion();
076                    }
077            }
078    }