Ejemplo n.º 1
0
        /// <summary>
        /// Find order by id and print it
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sAccountID"></param>
        /// <param name="sOrderID"></param>
        /// <param name="responseListener"></param>
        private static void FindOrder(O2GSession session, string sAccountID, string sOrderID, 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)
            {
                responseListener.SetRequestID(request.RequestID);
                session.sendRequest(request);
                if (!responseListener.WaitEvents())
                {
                    throw new Exception("Response waiting timeout expired");
                }
                O2GResponse orderResponse = responseListener.GetResponse();
                if (orderResponse != null)
                {
                    if (orderResponse.Type == O2GResponseType.GetOrders)
                    {
                        O2GResponseReaderFactory responseReaderFactory = session.getResponseReaderFactory();
                        bool bFound = false;
                        O2GOrdersTableResponseReader responseReader = responseReaderFactory.createOrdersTableReader(orderResponse);
                        for (int i = 0; i < responseReader.Count; i++)
                        {
                            O2GOrderRow orderRow = responseReader.getRow(i);
                            if (sOrderID.Equals(orderRow.OrderID))
                            {
                                Console.WriteLine("OrderID={0}; AccountID={1}; Type={2}; Status={3}; OfferID={4}; Amount={5}; BuySell={6}; Rate={7}",
                                                  orderRow.OrderID, orderRow.AccountID, orderRow.Type, orderRow.Status, orderRow.OfferID,
                                                  orderRow.Amount, orderRow.BuySell, orderRow.Rate);
                                bFound = true;
                                break;
                            }
                        }
                        if (!bFound)
                        {
                            Console.WriteLine("OrderID={0} is not found!", sOrderID);
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Cannot create request");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Find order by ID and print information about it
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sOrderID"></param>
        /// <param name="sAccountID"></param>
        /// <param name="responseListener"></param>
        private static void FindOrder(O2GSession session, string sOrderID, 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);

            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     responseFactory = session.getResponseReaderFactory();
                O2GOrdersTableResponseReader ordersReader    = responseFactory.createOrdersTableReader(response);
                for (int i = 0; i < ordersReader.Count; i++)
                {
                    O2GOrderRow order = ordersReader.getRow(i);
                    if (sOrderID.Equals(order.OrderID))
                    {
                        Console.WriteLine("Information for OrderID = {0}", sOrderID);
                        Console.WriteLine("Account: {0}", order.AccountID);
                        Console.WriteLine("Amount: {0}", order.Amount);
                        Console.WriteLine("Rate: {0}", order.Rate);
                        Console.WriteLine("Type: {0}", order.Type);
                        Console.WriteLine("Buy/Sell: {0}", order.BuySell);
                        Console.WriteLine("Stage: {0}", order.Stage);
                        Console.WriteLine("Status: {0}", order.Status);
                    }
                }
            }
            else
            {
                throw new Exception("Cannot get response");
            }
        }
Ejemplo n.º 3
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");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Check if order exists
        /// </summary>
        /// <param name="session"></param>
        /// <param name="sAccountID"></param>
        /// <param name="sOrderID"></param>
        /// <param name="responseListener"></param>
        /// <returns></returns>
        private static bool IsOrderExists(O2GSession session, string sAccountID, string sOrderID, 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 (sOrderID.Equals(orderRow.OrderID))
                {
                    bHasOrder = true;
                    break;
                }
            }
            return(bHasOrder);
        }