示例#1
0
            public void Execute(DataSet dataSet)
            {
                // create route instruction for the order based only on data from the dataset
                System.Console.WriteLine("Created route to broker '" + this.brokerCode + "' for DataSet: " + dataSet.getName());

                // Get the order
                Orders          os    = this.ruleMSXTest.emsx.orders;
                DataPoint       dp    = dataSet.getDataPoint("OrderNo");
                DataPointSource dps   = dp.GetSource();
                string          ordno = dps.GetValue().ToString();
                Order           o     = os.getBySequenceNo(Convert.ToInt32(ordno));

                if (o != null)
                {
                    Request req = this.ruleMSXTest.emsx.createRequest("RouteEx");
                    req.Set("EMSX_SEQUENCE", o.field("EMSX_SEQUENCE").value());
                    req.Set("EMSX_AMOUNT", o.field("EMSX_AMOUNT").value());
                    req.Set("EMSX_BROKER", brokerCode);
                    req.Set("EMSX_HAND_INSTRUCTION", "ANY");
                    req.Set("EMSX_ORDER_TYPE", o.field("EMSX_ORDER_TYPE").value());
                    req.Set("EMSX_TICKER", o.field("EMSX_TICKER").value());
                    req.Set("EMSX_TIF", o.field("EMSX_TIF").value());
                    System.Console.WriteLine("Sending request: " + req.ToString());

                    this.ruleMSXTest.emsx.sendRequest(req, this);
                }
            }
示例#2
0
    /*****************************************************************************
    *  Function    : IsBPipeAuthorized
    *  Description : This function authorize the token. A valid Identiy will contain
    *             the user/application credentials on authorization success.
    *             Returns false on failure.
    *  Arguments   : token string from GenerateToken(), reference to Identity
    *  Returns     : bool
    *****************************************************************************/
    private bool IsBPipeAuthorized(string token, out Identity identity)
    {
        bool isAuthorized = false;
        bool isRunning    = true;

        identity = null;

        if (!d_session.OpenService(AUTH_SVC))
        {
            System.Console.Error.WriteLine("Failed to open " + AUTH_SVC);
            return(isAuthorized = false);
        }
        Service authService = d_session.GetService(AUTH_SVC);


        Request authRequest = authService.CreateAuthorizationRequest();

        authRequest.Set("token", token);
        identity = d_session.CreateIdentity();
        EventQueue authEventQueue = new EventQueue();

        d_session.SendAuthorizationRequest(authRequest, identity, authEventQueue, new CorrelationID(1));

        while (isRunning)
        {
            Event eventObj = authEventQueue.NextEvent();
            System.Console.WriteLine("processEvent");
            if (eventObj.Type == Event.EventType.RESPONSE || eventObj.Type == Event.EventType.REQUEST_STATUS)
            {
                foreach (Message msg in eventObj)
                {
                    if (msg.MessageType == AUTHORIZATION_SUCCESS)
                    {
                        System.Console.WriteLine("Authorization SUCCESS");

                        isAuthorized = true;
                        isRunning    = false;
                        break;
                    }
                    else if (msg.MessageType == AUTHORIZATION_FAILURE)
                    {
                        System.Console.WriteLine("Authorization FAILED");
                        System.Console.WriteLine(msg);
                        isRunning = false;
                    }
                    else
                    {
                        System.Console.WriteLine(msg);
                    }
                }
            }
        }
        return(isAuthorized);
    }
示例#3
0
        /// <summary>
        /// Gets the Bloomberg data via the specified request type
        /// </summary>
        /// <param name="instruments">The list of instruments to retrieve data for</param>
        /// <param name="dataFromDate">The start date of the data being requested</param>
        /// <param name="dataToDate">The end date of the data being requested</param>
        /// <param name="requestType">The type of request i.e. Reference/Historical</param>
        private void GetBloombergData(List <BloombergDataInstrument> instruments, DateTime dataFromDate, DateTime dataToDate, string requestType)
        {
            try {
                sentLimitEmail = false;
                Initialise(BLP_REF, instruments.Count);
                BB.Service service = session.GetService(BLP_REF);

                guids    = new List <Guid>();
                sentToBB = instruments;                 // new List<BloombergDataInstrument>();
                ShowCompletionPercentage(0, instruments.Count);

                foreach (BloombergDataInstrument bbdi in instruments)
                {
                    BB.Request request = service.CreateRequest(requestType);

                    if (requestType == BLP_HISTORICAL_REQUEST)
                    {
                        request.Set("startDate", dataFromDate.ToString("yyyyMMdd"));
                        request.Set("endDate", dataToDate.ToString("yyyyMMdd"));
                    }
                    BB.Element securities = request.GetElement(BLP_SECURITIES);

                    // check for sedol ticker which must be in the correct format
                    string ticker = bbdi.Ticker;
                    if (ticker.EndsWith("SEDOL1"))
                    {
                        ticker = @"/SEDOL1/" + ticker.Replace(" SEDOL1", string.Empty);
                    }

                    // set all the securities to fetch
                    securities.AppendValue(ticker);

                    // set all the fields
                    BB.Element fields = request.GetElement(BLP_FIELDS);
                    foreach (string field in bbdi.BBFields.Keys)
                    {
                        fields.AppendValue(field);

                        // now do the overrides - if they exist
                        if (bbdi.BBFields[field].FieldOverrides != null)
                        {
                            BB.Element requestOverrides = request.GetElement(BLP_OVERRIDES);
                            foreach (string oField in bbdi.BBFields[field].FieldOverrides.Keys)
                            {
                                object oValue = bbdi.BBFields[field].FieldOverrides[oField];
                                // now add in the override oField and oValue
                                BB.Element ovr = requestOverrides.AppendElement();
                                ovr.SetElement(FIELD_ID, oField);
                                ovr.SetElement(VALUE, oValue.ToString());
                            }
                        }
                    }
                    session.SendRequest(request, new BB.CorrelationID(bbdi.GUID));
                }

                UpdateStatus(string.Format("Sent {0} instruments\\requests to Bloomberg", sentToBB.Count));
            } catch (Exception ex) {
                UpdateStatus(ex.Message);
                throw new Exception("An error occurred whilst sending requests to Bloomberg - " + ex.Message, ex);
            }
        }
示例#4
0
        /// <summary>
        /// Authorize should be called before any requests are sent. Called by init.
        /// </summary>
        /// <param name="identity"></param>
        /// <param name="session"></param>
        private static void Authorize(out Identity identity, Session session)
        {
            identity = session.CreateIdentity();
            if (!session.OpenService(AUTH_SERVICE))
            {
                throw new Exception(
                          string.Format("Failed to open auth service: {0}",
                                        AUTH_SERVICE));
            }
            Service authService = session.GetService(AUTH_SERVICE);

            EventQueue tokenEventQueue = new EventQueue();

            session.GenerateToken(new CorrelationID(tokenEventQueue), tokenEventQueue);
            string token = null;
            // Generate token responses will come on the dedicated queue. There would be no other
            // messages on that queue.
            Event eventObj = tokenEventQueue.NextEvent(
                Convert.ToInt32(WAIT_TIME.TotalMilliseconds));

            if (eventObj.Type == Event.EventType.TOKEN_STATUS ||
                eventObj.Type == Event.EventType.REQUEST_STATUS)
            {
                foreach (Message msg in eventObj)
                {
                    System.Console.WriteLine(msg);
                    if (msg.MessageType == TOKEN_SUCCESS)
                    {
                        token = msg.GetElementAsString(TOKEN_ELEMENT);
                    }
                }
            }
            if (token == null)
            {
                throw new Exception("Failed to get token");
            }

            Request authRequest = authService.CreateAuthorizationRequest();

            authRequest.Set(TOKEN_ELEMENT, token);

            session.SendAuthorizationRequest(authRequest, identity, null);

            TimeSpan ts = WAIT_TIME;

            for (DateTime startTime = DateTime.UtcNow;
                 ts.TotalMilliseconds > 0;
                 ts = ts - (DateTime.UtcNow - startTime))
            {
                eventObj = session.NextEvent(Convert.ToInt32(ts.TotalMilliseconds));
                // Since no other requests were sent using the session queue, the response can
                // only be for the Authorization request
                if (eventObj.Type != Event.EventType.RESPONSE &&
                    eventObj.Type != Event.EventType.PARTIAL_RESPONSE &&
                    eventObj.Type != Event.EventType.REQUEST_STATUS)
                {
                    continue;
                }

                foreach (Message msg in eventObj)
                {
                    System.Console.WriteLine(msg);
                    if (msg.MessageType != AUTHORIZATION_SUCCESS)
                    {
                        throw new Exception("Authorization Failed");
                    }
                }
                return;
            }
            throw new Exception("Authorization Failed");
        }