コード例 #1
0
        /// <summary>
        /// Update margin requirements
        /// </summary>
        /// <param name="session"></param>
        /// <param name="responseListener"></param>
        private static void UpdateMargins(O2GSession session, ResponseListener responseListener)
        {
            O2GRequest        request        = null;
            O2GRequestFactory requestFactory = session.getRequestFactory();

            if (requestFactory == null)
            {
                throw new Exception("Cannot create request factory");
            }
            O2GValueMap valueMap = requestFactory.createValueMap();

            valueMap.setString(O2GRequestParamsEnum.Command, Constants.Commands.UpdateMarginRequirements);
            request = requestFactory.createOrderRequest(valueMap);
            responseListener.SetRequestID(request.RequestID);
            session.sendRequest(request);
            if (!responseListener.WaitEvents())
            {
                throw new Exception("Response waiting timeout expired");
            }
            O2GResponse response = responseListener.GetResponse();

            if (response != null && response.Type == O2GResponseType.MarginRequirementsResponse)
            {
                O2GResponseReaderFactory responseFactory = session.getResponseReaderFactory();
                if (responseFactory != null)
                {
                    responseFactory.processMarginRequirementsResponse(response);
                    Console.WriteLine("Margin requirements have been updated");
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            O2GSession session = null;

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

                PrintSampleParams("SubscriptionStatus", 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.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;

                    O2GOfferRow offer = GetOffer(session, sampleParams.Instrument);
                    if (offer == null)
                    {
                        throw new Exception(string.Format("The instrument '{0}' is not valid", sampleParams.Instrument));
                    }

                    O2GRequest request = CreateSetSubscriptionStatusRequest(session, offer.OfferID, sampleParams.Status, responseListener);
                    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();
                    if (response != null && response.Type == O2GResponseType.CommandResponse)
                    {
                        Console.WriteLine("Subscription status for '{0}' is set to '{1}'", sampleParams.Instrument, sampleParams.Status);
                    }

                    PrintMargins(session, account, offer);
                    UpdateMargins(session, responseListener);
                    PrintMargins(session, account, offer);
                    Console.WriteLine("Done!");

                    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();
                }
            }
        }