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 org.otfeed.*;
021    import org.otfeed.command.EquityInitCommand;
022    import org.otfeed.event.*;
023    
024    /**
025     * Sample application that submits EquityInit request.
026     * <p/>
027     * EquityInit request returns detailed info on an equity.
028     */
029    public class EquityInit {
030    
031            public static void main(String ... av) throws Exception {
032    
033                    if(av.length != 2) {
034                            System.out.println("USAGE: EquityInit <exchange> <symbol>");
035                            System.exit(-1);
036                    }
037    
038                    IConnection connection = Connector.connect();
039    
040                    String exchange = av[0];
041                    String symbol   = av[1];
042                    
043                    EquityInitCommand command = new EquityInitCommand();
044                    command.setExchangeCode(exchange);
045                    command.setSymbolCode(symbol);
046                    command.setDataDelegate(new IDataDelegate<OTEquityInit>() {
047                            public void onData(OTEquityInit data) {
048                                    System.out.println(data);
049                            }
050                    });
051                    command.setCompletionDelegate(new ICompletionDelegate() {
052                            public void onDataEnd(OTError error) {
053                                    if(error != null) {
054                                            System.out.println(error);
055                                    }
056                            }
057                    });
058    
059                    try {
060    
061                            IRequest request = connection.prepareRequest(command);
062                            request.submit();
063                            request.waitForCompletion();
064    
065                    } finally {
066                            connection.shutdown();
067                            connection.waitForCompletion();
068                    }
069            }
070    }