Ejemplo n.º 1
0
        public void run(PerSecurityWS ps)
        {
            try
            {
                // Setting header for the request
                GetFundamentalsHeaders getFundHeaders = new GetFundamentalsHeaders();
                GetDataHeaders getDataHeaders = new GetDataHeaders();
                getDataHeaders.closingvaluesSpecified = true;
                getDataHeaders.closingvalues = true;
                getDataHeaders.secmasterSpecified = true;
                getDataHeaders.secmaster = true;
                getDataHeaders.derivedSpecified = true;
                getDataHeaders.derived = true;

                // Setting instruments for the request
			Instrument ticker = new Instrument();
			ticker.id = "IBM US";
			ticker.type = InstrumentType.TICKER;
			ticker.yellowkey = MarketSector.Equity;

			Instrument bbUniqueId = new Instrument();
			bbUniqueId.id = "EQ0086119600001000";
			bbUniqueId.type = InstrumentType.BB_UNIQUE;
			Instrument[] instr = new Instrument[] { ticker, bbUniqueId };
			
			String[] field = new String[] { "TOP_ANALYST_PERFORM_RANK_TRR" };


                // Sending submit get data request
			SubmitGetDataRequest sbmtGetDtReq = new SubmitGetDataRequest();
			sbmtGetDtReq.headers = getDataHeaders;
			sbmtGetDtReq.fields = field;
			Instruments instrmnts = new Instruments();
			instrmnts.instrument = instr;
			sbmtGetDtReq.instruments = instrmnts;
			Console.WriteLine("Sending submit get bulk data request");
			SubmitGetDataResponse sbmtGetDtResp = ps
					.submitGetDataRequest(sbmtGetDtReq);
			Console.WriteLine("Submit get data request status: "
					+ sbmtGetDtResp.statusCode.description
					+ "  response ID: " + sbmtGetDtResp.responseId);


                // Sending retrieve get data request
			RetrieveGetDataRequest rtvGetDtReq = new RetrieveGetDataRequest();
			rtvGetDtReq.responseId = sbmtGetDtResp.responseId;
			RetrieveGetDataResponse rtvGetDtResp = new RetrieveGetDataResponse();
            Console.WriteLine("Sending retrieve get data request");
			
			// Keep polling for response till the data is available
			do {
                System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
				rtvGetDtResp = ps.retrieveGetDataResponse(rtvGetDtReq);

			} while (rtvGetDtResp.statusCode.code == PerSecurity.DATA_NOT_AVAILABLE);
			

                // Display data
			if (rtvGetDtResp.statusCode.code == PerSecurity.SUCCESS) {
				Console.WriteLine("Retrieve get data request successful. Response ID: "
						+ rtvGetDtResp.responseId);
				for (int i = 0; i < rtvGetDtResp.instrumentDatas.Length; i++) {
                    InstrumentData data = rtvGetDtResp.instrumentDatas[i];
					Console.WriteLine(data.instrument.id);
					Data[] datas = data.data;
					for (int j = 0; j < datas.Length; j++) {
						//Displaying bulk data
						if (datas[j].isArray) {

							for (int k = 0; k < datas[j].bulkarray.Length; k++)
                                for (int l = 0; l < datas[j].bulkarray[k].data.Length; l++) {
                                    Console.WriteLine(datas[j].bulkarray[k].data[l].type
													+ ": "
                                                    + datas[j].bulkarray[k].data[l].value);
								}
						} 
						//Displaying non-bulk data
						else
							Console.WriteLine(datas[j].value);
                        	}
				}
			} else if (rtvGetDtResp.statusCode.code == PerSecurity.REQUEST_ERROR)
                Console.WriteLine("Error in submitted request");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 2
0
		public void run(PerSecurityWS ps)
		{
			
			//Set request header
			GetDataHeaders getDataHeaders = new GetDataHeaders();
			getDataHeaders.secmaster = true;
            getDataHeaders.secmasterSpecified = true;
			getDataHeaders.closingvalues = true;
			getDataHeaders.closingvaluesSpecified = true;
			
			//Defining the instruments for the bulk request
			Instrument ticker = new Instrument();
			ticker.id = "IBM US";
			ticker.yellowkeySpecified = true;
			ticker.yellowkey = MarketSector.Equity;
			ticker.typeSpecified = false;
			ticker.type = InstrumentType.TICKER;

			
			Console.WriteLine("Submit get Data request");
			SubmitGetDataRequest sbmtGtDtreq = new SubmitGetDataRequest();
			sbmtGtDtreq.headers = getDataHeaders;
			sbmtGtDtreq.fields = new string[]{"TOP_ANALYST_PERFORM_RANK_TRR"};//Bulk field 
            Instruments instrs = new Instruments();
            instrs.instrument = new Instrument[] { ticker };
            sbmtGtDtreq.instruments = instrs;
			try
			{
				SubmitGetDataResponse sbmtGtDtresp = ps.submitGetDataRequest(sbmtGtDtreq);
				System.Console.WriteLine("Request ID = "  + sbmtGtDtresp.requestId + " " + sbmtGtDtresp.responseId);
				System.Console.WriteLine("status of Get Data request :  " + sbmtGtDtresp.statusCode.description);
			
				Console.WriteLine("Retrieve get data request");
				RetrieveGetDataRequest rtrvGtDrReq = new RetrieveGetDataRequest();
				rtrvGtDrReq.responseId = sbmtGtDtresp.responseId;
				RetrieveGetDataResponse rtrvGtDrResp = new RetrieveGetDataResponse();
				do
				{
					System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
					rtrvGtDrResp = ps.retrieveGetDataResponse(rtrvGtDrReq);
			}
				while(rtrvGtDrResp.statusCode.code==PerSecurity.DATA_NOT_AVAILABLE);
                if(rtrvGtDrResp.statusCode.code==PerSecurity.SUCCESS){
				Console.WriteLine("Response ID " +  rtrvGtDrResp.responseId);
                for (int i = 0; i < rtrvGtDrResp.instrumentDatas.Length; i++)
                {
                    System.Console.WriteLine("Data for :" + rtrvGtDrResp.instrumentDatas[i].instrument.id +
                        "  " + rtrvGtDrResp.instrumentDatas[i].instrument.yellowkey);
                    for (int j = 0; j < rtrvGtDrResp.instrumentDatas[i].data.Length; j++)
                    {
                        if (rtrvGtDrResp.instrumentDatas[i].data[j].isArray == true)
                        {
                            for (int k = 0; k < rtrvGtDrResp.instrumentDatas[i].data[j].bulkarray.Length; k++)
                            {
                                Console.WriteLine("-------------------------");
                                for (int l = 0; l < rtrvGtDrResp.instrumentDatas[i].data[j].
                                    bulkarray[k].data.Length; l++)
                                    Console.WriteLine(rtrvGtDrResp.instrumentDatas[i].
                                        data[j].bulkarray[k].data[l].value);
                            }
                        }
                        else

                            System.Console.WriteLine("	" + sbmtGtDtreq.fields[j] + " : " +
                                rtrvGtDrResp.instrumentDatas[i].data[j].value);
                    }
                }
				}
                else if (rtrvGtDrResp.statusCode.code == PerSecurity.REQUEST_ERROR)
                {
                    Console.WriteLine("Error in the submitted request");
                }
			}
			catch(Exception e)
			{
				Console.WriteLine(e.Message);
			}
		}
        public void run(PerSecurityWS ps)
        {

            //Setting request header information	
            GetDataHeaders getDataHeaders = new GetDataHeaders();
            getDataHeaders.secmaster = true;
            getDataHeaders.secmasterSpecified = true;
            getDataHeaders.closingvalues = true;
            getDataHeaders.closingvaluesSpecified = true;
            getDataHeaders.derived = true;
            getDataHeaders.derivedSpecified = true;
            getDataHeaders.exclusive_pricing_srcSpecified = true;
            getDataHeaders.exclusive_pricing_src = true;

            //Setting Instrument information
            Instrument bbUniqueId = new Instrument();
            bbUniqueId.id = "EQ0086119600001000";
            bbUniqueId.type = InstrumentType.BB_UNIQUE;
            bbUniqueId.typeSpecified = true;

            Instrument ticker = new Instrument();
            ticker.id = "IBM";
            ticker.yellowkey = MarketSector.Equity;
            ticker.yellowkeySpecified = true;
            ticker.type = InstrumentType.TICKER;
            ticker.typeSpecified = true;

            
            //Setting the get data request parameter
            SubmitGetDataRequest sbmtGtDtreq = new SubmitGetDataRequest();
            sbmtGtDtreq.headers = getDataHeaders;
               sbmtGtDtreq.fields = new string[] { "ID_BB_UNIQUE", "TICKER", "PX_LAST", "PX_ASK", "PX_BID", "VWAP_DT" };
            Instruments instrs = new Instruments();
            instrs.instrument = new Instrument[] { ticker, bbUniqueId };
            sbmtGtDtreq.instruments = new Instruments();
            sbmtGtDtreq.instruments = instrs;

            try
            {
                Console.WriteLine("Submit Get Data Request");
                SubmitGetDataResponse sbmtGtDtresp = ps.submitGetDataRequest(sbmtGtDtreq);
                System.Console.WriteLine("status " + sbmtGtDtresp.statusCode.description);
                System.Console.WriteLine("Submit Get Data request -  response ID = " + sbmtGtDtresp.responseId);

                //retrieve get data request. The response ID sent for the request is the response ID
                //received from SubmitGetDataRequest()
                Console.WriteLine("Retrieve data request");
                RetrieveGetDataRequest rtrvGtDrReq = new RetrieveGetDataRequest();
                rtrvGtDrReq.responseId = sbmtGtDtresp.responseId;
                RetrieveGetDataResponse rtrvGtDrResp = new RetrieveGetDataResponse();

                //Keep sending the request if status is 100
                do
                {
                    System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
                    rtrvGtDrResp = ps.retrieveGetDataResponse(rtrvGtDrReq);
                }
                while (rtrvGtDrResp.statusCode.code == PerSecurity.DATA_NOT_AVAILABLE);

                if (rtrvGtDrResp.statusCode.code == PerSecurity.SUCCESS)
                {
                    //Displaying the RetrieveGetDataResponse
                    for (int i = 0; i < rtrvGtDrResp.instrumentDatas.Length; i++)
                    {
                        Console.WriteLine("Data for :" + rtrvGtDrResp.instrumentDatas[i].instrument.id +
                            "  " + rtrvGtDrResp.instrumentDatas[i].instrument.yellowkey);
                        for (int j = 0; j < rtrvGtDrResp.instrumentDatas[i].data.Length; j++)
                        {
                            if (rtrvGtDrResp.instrumentDatas[i].data[j].isArray == true)
                            {
                                //In case this is a bulk field request
                                for (int k = 0; k < rtrvGtDrResp.instrumentDatas[i].data[j].bulkarray.Length; k++)
                                {
                                    Console.WriteLine("-------------------------");
                                    for (int l = 0; l < rtrvGtDrResp.instrumentDatas[i].data[j].
                                        bulkarray[k].data.Length; l++)
                                        Console.WriteLine(rtrvGtDrResp.
                                            instrumentDatas[i].data[j].bulkarray[k].data[l].value);
                                }
                            }
                            else
                                Console.WriteLine("	" + sbmtGtDtreq.fields[j] + " : " + rtrvGtDrResp.
                                    instrumentDatas[i].data[j].value);
                        }
                    }
                }
                else if (rtrvGtDrResp.statusCode.code == PerSecurity.REQUEST_ERROR)
                    Console.WriteLine("Error in the submitted request");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "   " + e.StackTrace);
            }
        }
Ejemplo n.º 4
0
        public bool Run(int jobKeyCode, string yellowkey, PerSecurityWS ps, DataTable dtKickouts, string[] fields, ref XmlDocument xdocNewInvestmentData, ref XmlDocument xdocNewInvestmentDataNoBbg, string InvestmentField)
        {
            #region prepare request

            Instruments instrs = new Instruments();
            List<Instrument> instrsList = new List<Instrument>();
            Dictionary<string, string> assetTypes = new Dictionary<string, string>();
            Dictionary<string, string> sourceInvestments = new Dictionary<string, string>();
            Hashtable htInvType2AssetType = InitAssetTypeMap();
            Hashtable htIntlOptions = new Hashtable();
            GetDataHeaders getDataHeaders = new GetDataHeaders();

            try
            {
                //Setting request header information	
                getDataHeaders.secmaster = true;
                getDataHeaders.secmasterSpecified = true;
                getDataHeaders.closingvalues = true;
                getDataHeaders.closingvaluesSpecified = true;
                getDataHeaders.derived = true;
                getDataHeaders.derivedSpecified = true;

                foreach (DataRow dr in dtKickouts.Rows)
                {
                    assetTypes[dr["Investment"].ToString()] = htInvType2AssetType[dr["SourceInvestmentType"].ToString()].ToString();
                    sourceInvestments[dr["Investment"].ToString()] = dr["SourceInvestment"].ToString();

                    if (SuppressBloombergQuery(dr) == false)
                    {
                        Instrument istr = new Instrument();
                        //istr.id = dr["Investment"].ToString();
                        istr.id = dr[InvestmentField].ToString();

                        switch (dr["SourceInvestmentType"].ToString())
                        {
                            case "FIGOVI":
                                istr.type = InstrumentType.ISIN;
                                break;

                            default:
                                istr.type = InstrumentType.TICKER;
                                break;

                        }
                        istr.typeSpecified = true;
                        AssignYellowKey(dr, ref istr, ref htIntlOptions);

                        instrsList.Add(istr);
                    }
                    else
                    {
                        XmlNode xnodeInvestmentWoBbg = null;
                        XmlNode nodeInvestmentAttributeWoBbg = null;

                        xnodeInvestmentWoBbg = xdocNewInvestmentDataNoBbg.CreateElement("Investment");

                        nodeInvestmentAttributeWoBbg = xdocNewInvestmentDataNoBbg.CreateElement("Investment");
                        //nodeInvestmentAttributeWoBbg.InnerXml = dr["Investment"].ToString();
                        nodeInvestmentAttributeWoBbg.InnerXml = dr[InvestmentField].ToString();
                        xnodeInvestmentWoBbg.AppendChild(nodeInvestmentAttributeWoBbg);

                        nodeInvestmentAttributeWoBbg = xdocNewInvestmentDataNoBbg.CreateElement("SourceInvestment");
                        if (sourceInvestments.ContainsKey(dr["Investment"].ToString()))
                            nodeInvestmentAttributeWoBbg.InnerXml = sourceInvestments[dr["Investment"].ToString()];
                        else
                            nodeInvestmentAttributeWoBbg.InnerXml = dr["Investment"].ToString();
                        xnodeInvestmentWoBbg.AppendChild(nodeInvestmentAttributeWoBbg);

                        XmlNode sourceInvestmentTypeNode = xdocNewInvestmentDataNoBbg.CreateElement("SourceInvestmentType");
                        DataRow[] drKickoutRows = dtKickouts.Select("SourceInvestment='" + nodeInvestmentAttributeWoBbg.InnerXml + "'");
                        if (drKickoutRows.Length > 0)
                            sourceInvestmentTypeNode.InnerXml = drKickoutRows[0]["SourceInvestmentType"].ToString();
                        xnodeInvestmentWoBbg.AppendChild(sourceInvestmentTypeNode);


                        //foreach(DataColumn dc in dr.Table.Columns)
                        //    if (dc.ColumnName != "Investment")
                        //    {
                        //        xnodeInvestmentWoBbg = xdocNewInvestmentData.CreateElement(dc.ColumnName);
                        //        xnodeInvestmentWoBbg.InnerXml = dr[dc.ColumnName].ToString();
                        //        xnodeInvestmentWoBbg.AppendChild(xnodeInvestmentWoBbg);
                        //    }

                        //set up investment node(s) for GV load
                        BuildGenevaInvestment(jobKeyCode, dtKickouts, xdocNewInvestmentDataNoBbg, ref xnodeInvestmentWoBbg, assetTypes, htIntlOptions);

                        //add to list of new investments
                        xdocNewInvestmentDataNoBbg.SelectSingleNode("//InvestmentRecords").AppendChild(xnodeInvestmentWoBbg);
                    }
                }
                instrs.instrument = instrsList.ToArray();
            }
            catch (Exception ex)
            {
				log.ErrorFormat(jobKeyCode,"{0}", ex);
				log.ErrorFormat(jobKeyCode,"{0}", ex.StackTrace);
            }

            #endregion

            #region submit request

            SubmitGetDataRequest sbmtGtDtreq = new SubmitGetDataRequest();
            sbmtGtDtreq.headers = getDataHeaders;
            sbmtGtDtreq.fields = fields; 
            sbmtGtDtreq.instruments = instrs;

            #region unused
            //Instrument bbUniqueId = new Instrument();
            //bbUniqueId.id = "GB0003252318";
            //bbUniqueId.type = InstrumentType.ISIN;
            //bbUniqueId.typeSpecified = true;

            //Setting the get data request parameter
//            SubmitGetDataRequest sbmtGtDtreq = new SubmitGetDataRequest();
//            sbmtGtDtreq.headers = getDataHeaders;

         //   sbmtGtDtreq.fields = new string[] { "ID_BB_UNIQUE", "TICKER", "PX_LAST", "PX_ASK", "PX_BID", "VWAP_DT" };
//            sbmtGtDtreq.fields = new string[] { "ID_BB_UNIQUE", "PX_LAST"};

//          Instruments instrs = new Instruments();
//            System.Collections.Generic.List<Instrument> instrsList = new System.Collections.Generic.List<Instrument>();
        //    instrsList.Add(ticker);
//            instrsList.Add(bbUniqueId);
            //instrs.instrument = new Instrument[] { ticker, bbUniqueId };
//            instrs.instrument = new Instrument[] {bbUniqueId };
//            sbmtGtDtreq.instruments = new Instruments();
            //            sbmtGtDtreq.instruments = instrs;
            #endregion

            XmlNode xnodeInvestment = null;
            XmlNode nodeInvestmentAttribute = null;

            try
            {
                log.Info(jobKeyCode, "Submit Get Data Request");
                SubmitGetDataResponse sbmtGtDtresp = ps.submitGetDataRequest(sbmtGtDtreq);
                log.Info(jobKeyCode, "status " + sbmtGtDtresp.statusCode.description);
                log.Info(jobKeyCode, "Submit Get Data request -  response ID = " + sbmtGtDtresp.responseId);

                //retrieve get data request. The response ID sent for the request is the response ID
                //received from SubmitGetDataRequest()
                log.Info(jobKeyCode, "Retrieve data request");
                RetrieveGetDataRequest rtrvGtDrReq = new RetrieveGetDataRequest();
                rtrvGtDrReq.responseId = sbmtGtDtresp.responseId;
                RetrieveGetDataResponse rtrvGtDrResp = new RetrieveGetDataResponse();

                //Keep sending the request if status is 100, up to 10 mins
                DateTime dtStart = DateTime.Now;
                do
                {
                    System.Threading.Thread.Sleep(Bits.ModulesNS.SecMasterDataRetrieveHeavy.POLL_INTERVAL);
                    rtrvGtDrResp = ps.retrieveGetDataResponse(rtrvGtDrReq);
                    if (dtStart.AddMinutes(10) < DateTime.Now)
                        throw new Exception("Timeout exceeded.  Bloomberg DLWS unavailable.");
                }
                while (rtrvGtDrResp.statusCode.code == Bits.ModulesNS.SecMasterDataRetrieveHeavy.DATA_NOT_AVAILABLE);

            #endregion

                #region process response

                if (rtrvGtDrResp.statusCode.code == Bits.ModulesNS.SecMasterDataRetrieveHeavy.SUCCESS)
                {
					//BAMSym back conversion
					if (dtKickouts.Columns.Contains("Symbol") && dtKickouts.Select("Symbol<>Investment").Length > 0)
					{
						foreach(DataRow drBamSym in dtKickouts.Select("Symbol<>Investment"))
						{
							for (int i = 0; i < rtrvGtDrResp.instrumentDatas.Length; i++)
							{
								if (rtrvGtDrResp.instrumentDatas[i].instrument.id.ToString().ToUpper() == drBamSym["Symbol"].ToString().ToUpper()
									&& rtrvGtDrResp.instrumentDatas[i].instrument.yellowkey.ToString().ToUpper() == drBamSym["FeedSymbol"].ToString().ToUpper())
								{
									rtrvGtDrResp.instrumentDatas[i].instrument.id =drBamSym["Investment"].ToString();
								}
							}
						}
					}


                    //Displaying and building the output for RetrieveGetDataResponse
                    for (int i = 0; i < rtrvGtDrResp.instrumentDatas.Length; i++)
                    {
                        //prepare new investment
                        xnodeInvestment = xdocNewInvestmentData.CreateElement("Investment");
                        log.Info(jobKeyCode, "Data for :" + rtrvGtDrResp.instrumentDatas[i].instrument.id +
                            "  " + rtrvGtDrResp.instrumentDatas[i].instrument.yellowkey);

                        //add all request fields to investment node
                        nodeInvestmentAttribute = xdocNewInvestmentData.CreateElement("Investment");
                        nodeInvestmentAttribute.InnerXml = rtrvGtDrResp.instrumentDatas[i].instrument.id;
                        xnodeInvestment.AppendChild(nodeInvestmentAttribute);

                        nodeInvestmentAttribute = xdocNewInvestmentData.CreateElement("SourceInvestment");
                        if (sourceInvestments.ContainsKey(rtrvGtDrResp.instrumentDatas[i].instrument.id))
                            nodeInvestmentAttribute.InnerXml = sourceInvestments[rtrvGtDrResp.instrumentDatas[i].instrument.id];
                        else
                            nodeInvestmentAttribute.InnerXml = rtrvGtDrResp.instrumentDatas[i].instrument.id;
                        xnodeInvestment.AppendChild(nodeInvestmentAttribute);

                        XmlNode sourceInvestmentTypeNode = xdocNewInvestmentData.CreateElement("SourceInvestmentType");
                        DataRow[] drKickoutRows = dtKickouts.Select("SourceInvestment='" + nodeInvestmentAttribute.InnerXml + "'");
                        if (drKickoutRows.Length > 0)
                            sourceInvestmentTypeNode.InnerXml = drKickoutRows[0]["SourceInvestmentType"].ToString();
                        xnodeInvestment.AppendChild(sourceInvestmentTypeNode);

                        //accumulate bbg response data for investment
                        for (int j = 0; j < rtrvGtDrResp.instrumentDatas[i].data.Length; j++)
                        {
                            if (rtrvGtDrResp.instrumentDatas[i].data[j].isArray == true)
                            {
                                //In case this is a bulk field request
                                for (int k = 0; k < rtrvGtDrResp.instrumentDatas[i].data[j].bulkarray.Length; k++)
                                {
                                    log.Info(jobKeyCode, "-------------------------");
                                    for (int l = 0; l < rtrvGtDrResp.instrumentDatas[i].data[j].
                                        bulkarray[k].data.Length; l++)
                                        log.Info(jobKeyCode, rtrvGtDrResp.
                                            instrumentDatas[i].data[j].bulkarray[k].data[l].value);
                                }
                            }
                            else
                            {
                                nodeInvestmentAttribute = xdocNewInvestmentData.CreateElement(sbmtGtDtreq.fields[j]);
                                nodeInvestmentAttribute.InnerText = rtrvGtDrResp.instrumentDatas[i].data[j].value;
                                xnodeInvestment.AppendChild(nodeInvestmentAttribute);
                                log.Info(jobKeyCode, "	" + sbmtGtDtreq.fields[j] + " : " + rtrvGtDrResp.instrumentDatas[i].data[j].value);
                            }
                        }

                        //set up investment node(s) for GV load
                        BuildGenevaInvestment(jobKeyCode, dtKickouts, xdocNewInvestmentData, ref xnodeInvestment, assetTypes, htIntlOptions);

                        //add to list of new investments
                        xdocNewInvestmentData.SelectSingleNode("//InvestmentRecords").AppendChild(xnodeInvestment);
                    }

                }
                else if (rtrvGtDrResp.statusCode.code == Bits.ModulesNS.SecMasterDataRetrieveHeavy.REQUEST_ERROR)
                    log.Info(jobKeyCode, "Error in the submitted request");

                #endregion
            }
            catch (Exception e)
            {
                log.Info(jobKeyCode, e.Message + "   " + e.StackTrace);
                return false;
            }
            return true;
        }
Ejemplo n.º 5
0
        public void run(PerSecurityWS ps)
        {
            try
            {
                //Setting request header information
                GetDataHeaders getDataHdrs = new GetDataHeaders();
                getDataHdrs.secmasterSpecified = true;
                getDataHdrs.secmaster = true;

                //Setting instruments for request
                Instruments instrs = new Instruments();
                instrs.macro = new Macro[2];
                instrs.macro[0] = new Macro();
                instrs.macro[0].primaryQualifier = new PrimaryQualifier();
                instrs.macro[0].primaryQualifier.primaryQualifierType = MacroType.SECTYP;
                instrs.macro[0].primaryQualifier.primaryQualifierValue = "OPT_CHAIN";

                instrs.macro[0].secondaryQualifier = new SecondaryQualifier[1];
                instrs.macro[0].secondaryQualifier[0] = new SecondaryQualifier();
                instrs.macro[0].secondaryQualifier[0].secondaryQualifierOperator = SecondaryQualifierOperator.Equals;
                instrs.macro[0].secondaryQualifier[0].secondaryQualifierType = SecondaryQualifierType.SECURITY_DES;
                instrs.macro[0].secondaryQualifier[0].secondaryQualifierValue = "SPX Index";
                instrs.macro[0].overrides = new Override[1];
                //A sample of incorrect macro
                instrs.macro[1] = new Macro();
                instrs.macro[1].primaryQualifier = new PrimaryQualifier();
                instrs.macro[1].primaryQualifier.primaryQualifierType = MacroType.SECTYP;
                instrs.macro[1].primaryQualifier.primaryQualifierValue = "OPTCHAIN";

                instrs.macro[1].secondaryQualifier = new SecondaryQualifier[1];
                instrs.macro[1].secondaryQualifier[0] = new SecondaryQualifier();
                instrs.macro[1].secondaryQualifier[0].secondaryQualifierOperator = SecondaryQualifierOperator.Equals;
                instrs.macro[1].secondaryQualifier[0].secondaryQualifierType = SecondaryQualifierType.SECURITY_DES;
                instrs.macro[1].secondaryQualifier[0].secondaryQualifierValue = "SPX Index";
               
                //Setting fields for the request
                string[] field = new string[] { "NAME", "TICKER", "PX_LAST" };

                //Submit get data request
                Console.WriteLine("Sending submit get data request");
                SubmitGetDataRequest sbmtGtDtreq = new SubmitGetDataRequest();
                sbmtGtDtreq.headers = getDataHdrs;
                sbmtGtDtreq.fields = field;
                sbmtGtDtreq.instruments = instrs;

                SubmitGetDataResponse sbmtGtDtresp = ps.submitGetDataRequest(sbmtGtDtreq);
                System.Console.WriteLine("status " + sbmtGtDtresp.statusCode.description);
                System.Console.WriteLine("Submit Get Data request -  response ID = " + sbmtGtDtresp.responseId);

                //retrieve get data request. The response ID sent for the request is the response ID
                //received from SubmitGetDataRequest()

                Console.WriteLine("Retrieve data request");
                RetrieveGetDataRequest rtrvGtDrReq = new RetrieveGetDataRequest();
                rtrvGtDrReq.responseId = sbmtGtDtresp.responseId;
                RetrieveGetDataResponse rtrvGtDrResp = new RetrieveGetDataResponse();

                //Keep sending the request until status code is "0"(success)
                do
                {
                    System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
                    rtrvGtDrResp = ps.retrieveGetDataResponse(rtrvGtDrReq);
                }
                while (rtrvGtDrResp.statusCode.code == PerSecurity.DATA_NOT_AVAILABLE);

                if (rtrvGtDrResp.statusCode.code == PerSecurity.SUCCESS)
                {
                    Console.WriteLine("Retrieve get data request successful");
                    for (int i = 0; i < rtrvGtDrResp.instrumentDatas.Length; i++)
                    {
                        if (rtrvGtDrResp.instrumentDatas[i].code.Equals("0"))
                        {
                            System.Console.WriteLine("Data for :" + rtrvGtDrResp.instrumentDatas[i].instrument.id +
                                "  " + rtrvGtDrResp.instrumentDatas[i].instrument.yellowkey);
                            for (int j = 0; j < rtrvGtDrResp.instrumentDatas[i].data.Length; j++)
                            {
                                if (rtrvGtDrResp.instrumentDatas[i].data[j].isArray == true)
                                {
                                    //In case this is a bulk field request
                                    for (int k = 0; k < rtrvGtDrResp.instrumentDatas[i].data[j].
                                        bulkarray.Length; k++)
                                    {
                                        Console.WriteLine("-------------------------");
                                        for (int l = 0; l < rtrvGtDrResp.instrumentDatas[i].data[j].
                                            bulkarray[k].data.Length; l++)
                                            Console.WriteLine(rtrvGtDrResp.instrumentDatas[i].data[j]
                                                .bulkarray[k].data[l].value);
                                    }
                                }
                                else

                                    System.Console.WriteLine("	" + sbmtGtDtreq.fields[j] + " : " + 
                                        rtrvGtDrResp.instrumentDatas[i].data[j].value);
                            }
                        }
                        //If an incorrect macro was passed in the request, display the error code and the incorrect macro
                        else
                        {
                            System.Console.WriteLine("\n Error Code " + rtrvGtDrResp.instrumentDatas[i].code +
                                ": incorrect macro. The Macro object is as follows:");
                            Console.WriteLine("Primary Qualifier -");
                            Console.WriteLine("Primary Qualifier type:" + rtrvGtDrResp.instrumentDatas[i].
                                macro.primaryQualifier.primaryQualifierType);
                            Console.WriteLine("Primary Qualifier value:" + rtrvGtDrResp.instrumentDatas[i].
                                macro.primaryQualifier.primaryQualifierValue);
                            Console.WriteLine("Secondary Qualifier -");
                            for (int l = 0; l < rtrvGtDrResp.instrumentDatas[i].macro.secondaryQualifier.Length; l++)
                            {
                                Console.WriteLine("Secondary Qualifier type :" + rtrvGtDrResp.instrumentDatas[i].
                                    macro.secondaryQualifier[l].secondaryQualifierType);
                                Console.WriteLine("Secondary Qualifier Value :" + rtrvGtDrResp.instrumentDatas[i].
                                    macro.secondaryQualifier[l].secondaryQualifierValue);
                                Console.WriteLine("Secondary Qualifier Operator :" + rtrvGtDrResp.instrumentDatas[i].
                                    macro.secondaryQualifier[l].secondaryQualifierOperator);
                            }
                        }

                    }
                    
                }
                else if (rtrvGtDrResp.statusCode.code == PerSecurity.REQUEST_ERROR)
                    Console.WriteLine("Error in the submitted request");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "  " + e.StackTrace);
            }
        }
Ejemplo n.º 6
0
        public void run(PerSecurityWS ps)
        {
            try{
            // Setting headers for the request
            GetDataHeaders getDataHeaders = new GetDataHeaders();
            getDataHeaders.closingvaluesSpecified = true;
            getDataHeaders.closingvalues = true;
            getDataHeaders.secmasterSpecified = true;
            getDataHeaders.secmaster = true;
            getDataHeaders.derivedSpecified = true;
            getDataHeaders.derived = true;

            // Setting list of instruments for data request
            Instrument ticker = new Instrument();
            ticker = new Instrument();
            ticker.id = "IBM US";
            ticker.type= InstrumentType.TICKER;
            ticker.yellowkey = MarketSector.Equity;

            Instrument[] instr = new Instrument[] { ticker };

            String[] field = new String[] { "ID_BB_UNIQUE", "TICKER",
					"PX_LAST", "PX_ASK", "PX_BID", "VWAP_DT" };

            BvalFieldSet fieldset = new BvalFieldSet();
            fieldset.fieldmacro = BvalFieldMacro.BVAL_BOND;


            // Submit get data request
			SubmitGetDataRequest sbmtGetDtReq = new SubmitGetDataRequest();
			sbmtGetDtReq.headers = getDataHeaders;
			sbmtGetDtReq.fields = field;
			sbmtGetDtReq.fieldsets = new BvalFieldSet[] { fieldset };
			Instruments instrmnts = new Instruments();
            instrmnts.instrument = instr;
			sbmtGetDtReq.instruments = instrmnts ;
			Console.WriteLine("Sending submit get data request");
			SubmitGetDataResponse sbmtGetDtResp = ps
					.submitGetDataRequest(sbmtGetDtReq);
            Console.WriteLine("Submit get data request status: " + sbmtGetDtResp.statusCode.description +
					 " responseId: " + sbmtGetDtResp.responseId);

            // Submit retrieve data
			RetrieveGetDataRequest rtvGetDtReq = new RetrieveGetDataRequest();
			rtvGetDtReq.responseId = sbmtGetDtResp.responseId;
			RetrieveGetDataResponse rtvGetDtResp = new RetrieveGetDataResponse();
            Console.WriteLine("Sending retrieve get data request");

			// Keep polling for response till the data is available
			do
			{
                System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
				rtvGetDtResp = ps.retrieveGetDataResponse(rtvGetDtReq);
			} while (rtvGetDtResp.statusCode.code == PerSecurity.DATA_NOT_AVAILABLE);

            // Display data
			if (rtvGetDtResp.statusCode.code == PerSecurity.SUCCESS)
			{
				Console.WriteLine("Retrieve get data request successful.  Response ID:" + rtvGetDtResp.responseId);
				for (int i = 0; i < rtvGetDtResp.instrumentDatas.Length; i++)
				{
					Console.WriteLine("Data for :"
							+ rtvGetDtResp.instrumentDatas[i].instrument.id + " "
                            + rtvGetDtResp.instrumentDatas[i].instrument.yellowkey);
                    for (int j = 0; j < rtvGetDtResp.instrumentDatas[i].data.Length; j++)
					{
						Console.WriteLine("  "
								+ rtvGetDtResp.fields[j]
								+ ": "
                                + rtvGetDtResp.instrumentDatas[i].data[j].value);
					}
				}
			}
			else if (rtvGetDtResp.statusCode.code == PerSecurity.REQUEST_ERROR)
                Console.WriteLine("Error in submitted request");
        }
            catch (Exception e)
		{
            Console.WriteLine(e.Message);
		}
        }