Ejemplo n.º 1
0
        /// <summary>
        /// Check if contingency group exists
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sAccountID"></param>
        /// <param name="sOrderID"></param>
        /// <param name="responseListener"></param>
        /// <returns></returns>
        private static bool IsContingencyExists(O2GSession session, string sAccountID, string sContingencyID, ResponseListener responseListener)
        {
            bool bHasOrder = false;
            O2GRequestFactory requestFactory = session.getRequestFactory();

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

            if (request == null)
            {
                throw new Exception("Cannot create request");
            }
            responseListener.SetRequestID(request.RequestID);
            session.sendRequest(request);
            if (!responseListener.WaitEvents())
            {
                throw new Exception("Response waiting timeout expired");
            }
            O2GResponse response = responseListener.GetResponse();
            O2GResponseReaderFactory     responseReaderFactory = session.getResponseReaderFactory();
            O2GOrdersTableResponseReader responseReader        = responseReaderFactory.createOrdersTableReader(response);

            for (int i = 0; i < responseReader.Count; i++)
            {
                O2GOrderRow orderRow = responseReader.getRow(i);
                if (sContingencyID.Equals(orderRow.ContingentOrderID))
                {
                    bHasOrder = true;
                    break;
                }
            }
            return(bHasOrder);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Check if contingency group exists
 /// </summary>
 /// <param name="session"></param>
 /// <param name="sAccountID"></param>
 /// <param name="sOrderID"></param>
 /// <param name="responseListener"></param>
 /// <returns></returns>
 private static bool IsContingencyExists(O2GSession session, string sAccountID, string sContingencyID, ResponseListener responseListener)
 {
     bool bHasOrder = false;
     O2GRequestFactory requestFactory = session.getRequestFactory();
     if (requestFactory == null)
     {
         throw new Exception("Cannot create request factory");
     }
     O2GRequest request = requestFactory.createRefreshTableRequestByAccount(O2GTableType.Orders, sAccountID);
     if (request == null)
     {
         throw new Exception("Cannot create request");
     }
     responseListener.SetRequestID(request.RequestID);
     session.sendRequest(request);
     if (!responseListener.WaitEvents())
     {
         throw new Exception("Response waiting timeout expired");
     }
     O2GResponse response = responseListener.GetResponse();
     O2GResponseReaderFactory responseReaderFactory = session.getResponseReaderFactory();
     O2GOrdersTableResponseReader responseReader = responseReaderFactory.createOrdersTableReader(response);
     for (int i = 0; i < responseReader.Count; i++)
     {
         O2GOrderRow orderRow = responseReader.getRow(i);
         if (sContingencyID.Equals(orderRow.ContingentOrderID))
         {
             bHasOrder = true;
             break;
         }
     }
     return bHasOrder;
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            O2GSession session = null;
            int        iContingencyGroupType = 1; // OCO group

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

                PrintSampleParams("JoinExistingGroup", loginParams, sampleParams);

                session        = O2GTransport.createSession();
                statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin);
                session.subscribeSessionStatus(statusListener);
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    responseListener = new ResponseListener(session);
                    session.subscribeResponse(responseListener);

                    O2GAccountRow account = GetAccount(session, sampleParams.AccountID);
                    if (account == null)
                    {
                        if (string.IsNullOrEmpty(sampleParams.AccountID))
                        {
                            throw new Exception("No valid accounts");
                        }
                        else
                        {
                            throw new Exception(string.Format("The account '{0}' is not valid", sampleParams.AccountID));
                        }
                    }
                    sampleParams.AccountID = account.AccountID;

                    O2GRequest request = AddOrderIntoGroupRequest(session, sampleParams.AccountID, sampleParams.ContingencyID, sampleParams.OrderID, iContingencyGroupType);
                    if (request == null)
                    {
                        throw new Exception("Cannot create request");
                    }

                    List <string> orderIDList = new List <string>();
                    orderIDList.Add(sampleParams.OrderID);
                    foreach (string sOrderID in orderIDList)
                    {
                        if (!IsOrderExists(session, sampleParams.AccountID, sOrderID, responseListener))
                        {
                            throw new Exception(string.Format("Order '{0}' does not exist", sOrderID));
                        }
                    }
                    if (!IsContingencyExists(session, sampleParams.AccountID, sampleParams.ContingencyID, responseListener))
                    {
                        throw new Exception(string.Format("Contingency group '{0}' does not exist", sampleParams.ContingencyID));
                    }
                    responseListener.SetOrderIDs(orderIDList);
                    session.sendRequest(request);
                    if (responseListener.WaitEvents())
                    {
                        Console.WriteLine("Done!");
                    }
                    else
                    {
                        throw new Exception("Response waiting timeout expired");
                    }
                }
            }
            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();
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            O2GSession session = null;
            int iContingencyGroupType = 1; // OCO group

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

                PrintSampleParams("JoinExistingGroup", loginParams, sampleParams);

                session = O2GTransport.createSession();
                SessionStatusListener statusListener = new SessionStatusListener(session, loginParams.SessionID, loginParams.Pin);
                session.subscribeSessionStatus(statusListener);
                session.login(loginParams.Login, loginParams.Password, loginParams.URL, loginParams.Connection);
                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    ResponseListener responseListener = new ResponseListener(session);
                    session.subscribeResponse(responseListener);

                    O2GAccountRow account = GetAccount(session, sampleParams.AccountID);
                    if (account == null)
                    {
                        if (string.IsNullOrEmpty(sampleParams.AccountID))
                        {
                            throw new Exception("No valid accounts");
                        }
                        else
                        {
                            throw new Exception(string.Format("The account '{0}' is not valid", sampleParams.AccountID));
                        }
                    }
                    sampleParams.AccountID = account.AccountID;

                    O2GRequest request = AddOrderIntoGroupRequest(session, sampleParams.AccountID, sampleParams.ContingencyID, sampleParams.OrderID, iContingencyGroupType);
                    if (request == null)
                    {
                        throw new Exception("Cannot create request");
                    }

                    List<string> orderIDList = new List<string>();
                    orderIDList.Add(sampleParams.OrderID);
                    foreach (string sOrderID in orderIDList)
                    {
                        if (!IsOrderExists(session, sampleParams.AccountID, sOrderID, responseListener))
                        {
                            throw new Exception(string.Format("Order '{0}' does not exist", sOrderID));
                        }
                    }
                    if (!IsContingencyExists(session, sampleParams.AccountID, sampleParams.ContingencyID, responseListener))
                    {
                        throw new Exception(string.Format("Contingency group '{0}' does not exist", sampleParams.ContingencyID));
                    }
                    responseListener.SetOrderIDs(orderIDList);
                    session.sendRequest(request);
                    if (responseListener.WaitEvents())
                    {
                        Console.WriteLine("Done!");
                    }
                    else
                    {
                        throw new Exception("Response waiting timeout expired");
                    }

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