Esempio n. 1
0
        static void Main(string[] args)
        {
            O2GSession session = null;

            try
            {
                LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings);

                PrintSampleParams("PrintTable", loginParams);

                session        = O2GTransport.createSession();
                statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin);
                session.subscribeSessionStatus(statusListener);
                statusListener.Reset();
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    responseListener = new ResponseListener();
                    session.subscribeResponse(responseListener);
                    O2GAccountRow account = GetAccount(session);
                    if (account != null)
                    {
                        PrintOrders(session, account.AccountID, responseListener);
                        Console.WriteLine("Done!");
                    }
                    else
                    {
                        throw new Exception("No valid accounts");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    if (statusListener.Connected)
                    {
                        if (responseListener != null)
                        {
                            session.unsubscribeResponse(responseListener);
                        }
                        statusListener.Reset();
                        session.logout();
                        statusListener.WaitEvents();
                    }
                    session.unsubscribeSessionStatus(statusListener);
                    session.Dispose();
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            O2GSession session = null;

            try
            {
                LoginParams loginParams = new LoginParams(ConfigurationManager.AppSettings);

                PrintSampleParams("PrintTable", loginParams);

                session = O2GTransport.createSession();
                SessionStatusListener statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin);
                session.subscribeSessionStatus(statusListener);
                statusListener.Reset();
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    ResponseListener responseListener = new ResponseListener();
                    session.subscribeResponse(responseListener);
                    O2GAccountRow account = GetAccount(session);
                    if (account != null)
                    {
                        PrintOrders(session, account.AccountID, responseListener);
                        Console.WriteLine("Done!");
                    }
                    else
                    {
                        throw new Exception("No valid accounts");
                    }
                    statusListener.Reset();
                    session.logout();
                    statusListener.WaitEvents();
                    session.unsubscribeResponse(responseListener);
                }
                session.unsubscribeSessionStatus(statusListener);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Print trades table for account
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sAccountID"></param>
        /// <param name="responseListener"></param>
        private static void PrintTrades(O2GSession session, string sAccountID, ResponseListener responseListener)
        {
            O2GRequestFactory requestFactory = session.getRequestFactory();

            if (requestFactory == null)
            {
                throw new Exception("Cannot create request factory");
            }
            O2GRequest request = requestFactory.createRefreshTableRequestByAccount(O2GTableType.Trades, sAccountID);

            if (request != null)
            {
                Console.WriteLine("Trades table for account {0}", sAccountID);
                responseListener.SetRequestID(request.RequestID);
                session.sendRequest(request);
                if (!responseListener.WaitEvents())
                {
                    throw new Exception("Response waiting timeout expired");
                }
                O2GResponse response = responseListener.GetResponse();
                if (response != null)
                {
                    O2GResponseReaderFactory     responseReaderFactory = session.getResponseReaderFactory();
                    O2GTradesTableResponseReader responseReader        = responseReaderFactory.createTradesTableReader(response);
                    for (int i = 0; i < responseReader.Count; i++)
                    {
                        O2GTradeRow tradeRow = responseReader.getRow(i);
                        Console.WriteLine("TradeID: {0}, Amount: {1}, Dividends: {2}", tradeRow.TradeID, tradeRow.Amount, tradeRow.Dividends);
                    }
                }
                else
                {
                    throw new Exception("Cannot get response");
                }
            }
            else
            {
                throw new Exception("Cannot create request");
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Print orders table for account
 /// </summary>
 /// <param name="session"></param>
 /// <param name="sAccountID"></param>
 /// <param name="responseListener"></param>
 private static void PrintOrders(O2GSession session, string sAccountID, ResponseListener responseListener)
 {
     O2GRequestFactory requestFactory = session.getRequestFactory();
     if (requestFactory == null)
     {
         throw new Exception("Cannot create request factory");
     }
     O2GRequest request = requestFactory.createRefreshTableRequestByAccount(O2GTableType.Orders, sAccountID);
     if (request != null)
     {
         Console.WriteLine("Orders table for account {0}", sAccountID);
         responseListener.SetRequestID(request.RequestID);
         session.sendRequest(request);
         if (!responseListener.WaitEvents())
         {
             throw new Exception("Response waiting timeout expired");
         }
         O2GResponse response = responseListener.GetResponse();
         if (response != null)
         {
             O2GResponseReaderFactory responseReaderFactory = session.getResponseReaderFactory();
             O2GOrdersTableResponseReader responseReader = responseReaderFactory.createOrdersTableReader(response);
             for (int i = 0; i < responseReader.Count; i++)
             {
                 O2GOrderRow orderRow = responseReader.getRow(i);
                 Console.WriteLine("OrderID: {0}, Status: {1}, Amount: {2}", orderRow.OrderID, orderRow.Status, orderRow.Amount);
             }
         }
         else
         {
             throw new Exception("Cannot get response");
         }
     }
     else
     {
         throw new Exception("Cannot create request");
     }
 }
        static void Main(string[] args)
        {
            O2GSession            session          = null;
            SessionStatusListener statusListener   = null;
            ResponseListener      responseListener = null;

            try
            {
                Console.WriteLine("PrintTable sample\n");

                ArgumentParser argParser = new ArgumentParser(args, "PrintTable");

                argParser.AddArguments(ParserArgument.Login,
                                       ParserArgument.Password,
                                       ParserArgument.Url,
                                       ParserArgument.Connection,
                                       ParserArgument.SessionID,
                                       ParserArgument.Pin,
                                       ParserArgument.TableType);

                argParser.ParseArguments();

                if (!argParser.AreArgumentsValid)
                {
                    argParser.PrintUsage();
                    return;
                }

                argParser.PrintArguments();

                LoginParams  loginParams  = argParser.LoginParams;
                SampleParams sampleParams = argParser.SampleParams;

                session        = O2GTransport.createSession();
                statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin);
                session.subscribeSessionStatus(statusListener);
                statusListener.Reset();
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    O2GResponseType responseType = string.Equals(sampleParams.TableType, SampleParams.OrdersTable) == true ?
                                                   O2GResponseType.GetOrders : O2GResponseType.GetTrades;

                    responseListener = new ResponseListener(responseType);
                    session.subscribeResponse(responseListener);
                    O2GAccountRow account = GetAccount(session);
                    if (account != null)
                    {
                        if (responseType == O2GResponseType.GetOrders)
                        {
                            PrintOrders(session, account.AccountID, responseListener);
                        }
                        else
                        {
                            PrintTrades(session, account.AccountID, responseListener);
                        }

                        Console.WriteLine("Done!");
                    }
                    else
                    {
                        throw new Exception("No valid accounts");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    if (statusListener.Connected)
                    {
                        statusListener.Reset();
                        session.logout();
                        statusListener.WaitEvents();
                        if (responseListener != null)
                        {
                            session.unsubscribeResponse(responseListener);
                        }
                    }
                    session.unsubscribeSessionStatus(statusListener);
                    session.Dispose();
                }
            }
        }