예제 #1
0
        static void Main(string[] args)
        {
            O2GSession session = null;

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

                PrintSampleParams("GetOffers", loginParams, sampleParams);

                session = O2GTransport.createSession();
                session.useTableManager(O2GTableManagerMode.Yes, null);
                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)
                {
                    TableListener tableListener = new TableListener();

                    O2GTableManager       tableManager  = session.getTableManager();
                    O2GTableManagerStatus managerStatus = tableManager.getStatus();
                    while (managerStatus == O2GTableManagerStatus.TablesLoading)
                    {
                        Thread.Sleep(50);
                        managerStatus = tableManager.getStatus();
                    }

                    if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
                    {
                        throw new Exception("Cannot refresh all tables of table manager");
                    }

                    tableListener.SetInstrument(sampleParams.Instrument);
                    tableListener.SubscribeEvents(tableManager);

                    O2GOffersTable offers = null;
                    offers = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers);
                    tableListener.PrintOffers(offers, null);

                    // Do nothing 10 seconds, let offers print
                    Thread.Sleep(10000);

                    Console.WriteLine("Done!");

                    tableListener.UnsubscribeEvents(tableManager);

                    statusListener.Reset();
                    session.logout();
                    statusListener.WaitEvents();
                }
                session.unsubscribeSessionStatus(statusListener);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            O2GSession session = null;

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

                PrintSampleParams("GetOffers", loginParams, sampleParams);

                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);
                    responseListener.SetInstrument(sampleParams.Instrument);
                    session.subscribeResponse(responseListener);

                    O2GLoginRules loginRules = session.getLoginRules();
                    if (loginRules == null)
                    {
                        throw new Exception("Cannot get login rules");
                    }

                    O2GResponse response;
                    if (loginRules.isTableLoadedByDefault(O2GTableType.Offers))
                    {
                        response = loginRules.getTableRefreshResponse(O2GTableType.Offers);
                        if (response != null)
                        {
                            responseListener.PrintOffers(session, response, null);
                        }
                    }
                    else
                    {
                        O2GRequestFactory requestFactory = session.getRequestFactory();
                        if (requestFactory != null)
                        {
                            O2GRequest offersRequest = requestFactory.createRefreshTableRequest(O2GTableType.Offers);
                            responseListener.SetRequestID(offersRequest.RequestID);
                            session.sendRequest(offersRequest);
                            if (!responseListener.WaitEvents())
                            {
                                throw new Exception("Response waiting timeout expired");
                            }
                            response = responseListener.GetResponse();
                            if (response != null)
                            {
                                responseListener.PrintOffers(session, response, null);
                            }
                        }
                    }

                    // Do nothing 10 seconds, let offers print
                    Thread.Sleep(10000);
                    Console.WriteLine("Done!");

                    session.unsubscribeResponse(responseListener);
                    statusListener.Reset();
                    session.logout();
                    statusListener.WaitEvents();
                }
                session.unsubscribeSessionStatus(statusListener);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
        static void Main(string[] args)
        {
            O2GSession session = null;

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

                PrintSampleParams("GetOffers", loginParams, sampleParams);

                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);
                    responseListener.SetInstrument(sampleParams.Instrument);
                    session.subscribeResponse(responseListener);

                    O2GLoginRules loginRules = session.getLoginRules();
                    if (loginRules == null)
                    {
                        throw new Exception("Cannot get login rules");
                    }

                    O2GResponse response;
                    if (loginRules.isTableLoadedByDefault(O2GTableType.Offers))
                    {
                        response = loginRules.getTableRefreshResponse(O2GTableType.Offers);
                        if (response != null)
                        {
                            responseListener.PrintOffers(session, response, null);
                        }
                    }
                    else
                    {
                        O2GRequestFactory requestFactory = session.getRequestFactory();
                        if (requestFactory != null)
                        {
                            O2GRequest offersRequest = requestFactory.createRefreshTableRequest(O2GTableType.Offers);
                            responseListener.SetRequestID(offersRequest.RequestID);
                            session.sendRequest(offersRequest);
                            if (!responseListener.WaitEvents())
                            {
                                throw new Exception("Response waiting timeout expired");
                            }
                            response = responseListener.GetResponse();
                            if (response != null)
                            {
                                responseListener.PrintOffers(session, response, null);
                            }
                        }
                    }

                    // Do nothing 10 seconds, let offers print
                    Thread.Sleep(100000);
                    Console.WriteLine("Done!");

                    session.unsubscribeResponse(responseListener);
                    statusListener.Reset();
                    session.logout();
                    statusListener.WaitEvents();
                }
                session.unsubscribeSessionStatus(statusListener);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            O2GSession session = null;

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

                PrintSampleParams("GetOffers", loginParams, sampleParams);

                session = O2GTransport.createSession();
                session.useTableManager(O2GTableManagerMode.Yes, null);
                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)
                {
                    TableListener tableListener = new TableListener();

                    O2GTableManager tableManager = session.getTableManager();
                    O2GTableManagerStatus managerStatus = tableManager.getStatus();
                    while (managerStatus == O2GTableManagerStatus.TablesLoading)
                    {
                        Thread.Sleep(50);
                        managerStatus = tableManager.getStatus();
                    }

                    if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
                    {
                        throw new Exception("Cannot refresh all tables of table manager");
                    }

                    tableListener.SetInstrument(sampleParams.Instrument);
                    tableListener.SubscribeEvents(tableManager);

                    O2GOffersTable offers = null;
                    offers = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers);
                    tableListener.PrintOffers(offers, null);

                    // Do nothing 10 seconds, let offers print
                    Thread.Sleep(10000);

                    Console.WriteLine("Done!");

                    tableListener.UnsubscribeEvents(tableManager);

                    statusListener.Reset();
                    session.logout();
                    statusListener.WaitEvents();
                }
                session.unsubscribeSessionStatus(statusListener);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.ToString());
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }