예제 #1
0
파일: Cancel.cs 프로젝트: sandykola/BBG
        public void run(PerSecurityWSDL.PerSecurityWS ps)
        {
            try
            {
                // Setting headers
                GetDataHeaders getDataHeaders = new GetDataHeaders();
                getDataHeaders.programflagSpecified = true;
                getDataHeaders.programflag          = ProgramFlag.daily;
                getDataHeaders.rundate             = DateTime.Today.ToString("yyyyMMdd");
                getDataHeaders.time                = "2200";
                getDataHeaders.specialchar         = SpecialChar.fraction;
                getDataHeaders.dateformat          = DateFormat.ddmmyyyy;
                getDataHeaders.dateformatSpecified = true;
                getDataHeaders.secmaster           = true;
                getDataHeaders.derived             = 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;
                Instruments instrs1 = new Instruments();
                instrs1.instrument = new Instrument[] { ticker };
                Instruments instrs2 = new Instruments();
                instrs2.instrument = new Instrument[] { bbUniqueId };

                SubmitGetDataRequest sbmtGtDtReq1 = new SubmitGetDataRequest();
                sbmtGtDtReq1.headers     = getDataHeaders;
                sbmtGtDtReq1.fields      = new string[] { "PX_LAST" };
                sbmtGtDtReq1.instruments = instrs1;

                SubmitGetDataRequest sbmtGtDtReq2 = new SubmitGetDataRequest();
                sbmtGtDtReq2.headers     = getDataHeaders;
                sbmtGtDtReq2.fields      = new string[] { "PX_LAST" };
                sbmtGtDtReq2.instruments = instrs2;

                submitGetDataRequestRequest sbmtGtDtReqReq1 = new submitGetDataRequestRequest(sbmtGtDtReq1);
                submitGetDataRequestRequest sbmtGtDtReqReq2 = new submitGetDataRequestRequest(sbmtGtDtReq2);

                submitGetDataRequestResponse sbmtGtDtReqResp1 = new submitGetDataRequestResponse();
                submitGetDataRequestResponse sbmtGtDtReqResp2 = new submitGetDataRequestResponse();

                sbmtGtDtReqResp1 = ps.submitGetDataRequest(sbmtGtDtReqReq1);
                sbmtGtDtReqResp2 = ps.submitGetDataRequest(sbmtGtDtReqReq1);
                SubmitGetDataResponse sbmtGtDtResp1 = sbmtGtDtReqResp1.submitGetDataResponse;
                SubmitGetDataResponse sbmtGtDtResp2 = sbmtGtDtReqResp2.submitGetDataResponse;

                Console.WriteLine("Scheduled Req 1 GetData --> " + sbmtGtDtResp1.responseId);
                Console.WriteLine("Scheduled Req 2 GetData --> " + sbmtGtDtResp2.responseId);

                System.Threading.Thread.Sleep(30000);

                string[] responseIds = { sbmtGtDtResp1.responseId, sbmtGtDtResp2.responseId, "dummy_id.out" };

                CancelHeaders cancelHeaders = new CancelHeaders();
                cancelHeaders.programflag = ProgramFlag.monthly;

                SubmitCancelRequest submitCancelReq = new SubmitCancelRequest();
                submitCancelReq.headers    = cancelHeaders;
                submitCancelReq.responseId = responseIds;

                submitCancelRequestRequest  submitCancelReqReq  = new submitCancelRequestRequest(submitCancelReq);
                submitCancelRequestResponse submitCancelReqResp = new submitCancelRequestResponse();

                SubmitCancelResponse submitCancelResp;

                Console.WriteLine("Sending submit cancel request");
                do
                {
                    System.Threading.Thread.Sleep(PerSecurity.PollInterval);

                    submitCancelReqResp = ps.submitCancelRequest(submitCancelReqReq);
                    submitCancelResp    = submitCancelReqResp.submitCancelResponse;

                    Console.WriteLine("Submit cancel request status: " + submitCancelResp.statusCode.description +
                                      " responseId: " + submitCancelResp.responseId);
                } while (submitCancelResp.statusCode.code == PerSecurity.DataNotAvailable);

                RetrieveCancelRequest retrieveCancelReq = new RetrieveCancelRequest();
                retrieveCancelReq.responseId = submitCancelResp.responseId;

                retrieveCancelResponseRequest  retrieveCancelRespReq = new retrieveCancelResponseRequest(retrieveCancelReq);
                retrieveCancelResponseResponse retrieveCancelRespResp;

                RetrieveCancelResponse retrieveCancelResp;

                Console.WriteLine("Sending retrieve cancel request");

                // Keep polling for response till the data is available
                do
                {
                    System.Threading.Thread.Sleep(PerSecurity.PollInterval);

                    retrieveCancelRespResp = ps.retrieveCancelResponse(retrieveCancelRespReq);
                    retrieveCancelResp     = retrieveCancelRespResp.retrieveCancelResponse;
                } while (retrieveCancelResp.statusCode.code == PerSecurity.DataNotAvailable);

                // Display data
                if (retrieveCancelResp.statusCode.code == PerSecurity.Success)
                {
                    Console.WriteLine("Retrieve cancel request successful.");
                    CancelResponseStatus[] ls = retrieveCancelResp.cancelResponseStatus;
                    for (int i = 0; i < ls.Length; i++)
                    {
                        Console.WriteLine("The cancel status for response id :"
                                          + ls[i].responseId + " is " + ls[i].cancelStatus.ToString());
                    }
                }
                else if (retrieveCancelResp.statusCode.code == PerSecurity.RequestError)
                {
                    Console.WriteLine("Error in submitted request");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
파일: Scheduled.cs 프로젝트: sandykola/BBG
        public void run(PerSecurityWS ps)
        {
            try
            {
                // Setting the instruments for request
                Instrument bbUniqueId = new Instrument();
                bbUniqueId.id = "EQ0086119600001000";
                bbUniqueId.yellowkeySpecified = false;
                bbUniqueId.type          = InstrumentType.BB_UNIQUE;
                bbUniqueId.typeSpecified = true;

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

                // Setting request header
                GetDataHeaders getDataHeaders = new GetDataHeaders();
                getDataHeaders.secmaster              = true;
                getDataHeaders.secmasterSpecified     = true;
                getDataHeaders.closingvalues          = true;
                getDataHeaders.closingvaluesSpecified = true;
                getDataHeaders.programflagSpecified   = true;
                getDataHeaders.programflag            = ProgramFlag.daily;
                getDataHeaders.rundate             = DateTime.Today.ToString("yyyyMMdd");
                getDataHeaders.time                = "0010";
                getDataHeaders.derived             = true;
                getDataHeaders.specialchar         = SpecialChar.fraction;
                getDataHeaders.dateformat          = DateFormat.ddmmyyyy;
                getDataHeaders.dateformatSpecified = true;

                Instruments instrs = new Instruments();
                instrs.instrument = new Instrument[] { bbUniqueId, ticker };

                // Submit getdata request
                SubmitGetDataRequest sbmtGtDrReq = new SubmitGetDataRequest();
                sbmtGtDrReq.headers     = getDataHeaders;
                sbmtGtDrReq.fields      = new string[] { "ID_BB_UNIQUE", "TICKER", "PX_LAST", "PX_ASK", "PX_BID", "VWAP_DT" };
                sbmtGtDrReq.instruments = instrs;

                Console.WriteLine("Submit getdata request");

                submitGetDataRequestRequest  sbmtGtDrReqReq   = new submitGetDataRequestRequest(sbmtGtDrReq);
                submitGetDataRequestResponse sbmtGetDtReqResp = ps.submitGetDataRequest(sbmtGtDrReqReq);
                SubmitGetDataResponse        sbmtGetDtResp    = sbmtGetDtReqResp.submitGetDataResponse;

                System.Console.WriteLine("Submit getdata response Id = " + sbmtGetDtResp.responseId + "\n");

                // Submit scheduled request for the getdata request sent above
                SubmitScheduledRequest sbmtSchReq = new SubmitScheduledRequest();
                Console.WriteLine("Submit scheduled request");

                submitScheduledRequestRequest  sbmtSchReqReq  = new submitScheduledRequestRequest(sbmtSchReq);
                submitScheduledRequestResponse sbmtSchReqResp = ps.submitScheduledRequest(sbmtSchReqReq);
                SubmitScheduledResponse        sbmtSchResp    = sbmtSchReqResp.submitScheduledResponse;

                Console.WriteLine("Submit Schedule request responseID : " + sbmtSchResp.responseId + "\n");

                // Submit retrieve scheduled request to display all the scheduled files and check to see
                // if the daily job requested was addeds
                Console.WriteLine("Retrieve scheduled request");
                RetrieveScheduledRequest rtrvSchReq = new RetrieveScheduledRequest();
                rtrvSchReq.responseId = sbmtSchResp.responseId;

                retrieveScheduledResponseRequest  rtrvSchRespReq = new retrieveScheduledResponseRequest(rtrvSchReq);
                retrieveScheduledResponseResponse rtrvSchRespResp;

                RetrieveScheduledResponse rtrvSchResp;

                // Keep sending the request until the entire response is received
                do
                {
                    Console.WriteLine("Polling for scheduled request");
                    System.Threading.Thread.Sleep(PerSecurity.PollInterval);
                    rtrvSchRespResp = ps.retrieveScheduledResponse(rtrvSchRespReq);
                    rtrvSchResp     = rtrvSchRespResp.retrieveScheduledResponse;
                }while (rtrvSchResp.statusCode.code == PerSecurity.DataNotAvailable);
                Console.WriteLine(rtrvSchResp.responseId);

                for (int i = 0; i < rtrvSchResp.fileDatas.Length; i++)
                {
                    if (rtrvSchResp.fileDatas[i].responseId == sbmtGetDtResp.responseId)
                    {
                        Console.WriteLine("Response ID requested by submit getdata request: " +
                                          rtrvSchResp.fileDatas[i].responseId);
                    }
                    else
                    {
                        Console.WriteLine("Response ID: " + rtrvSchResp.fileDatas[i].responseId + "\n");
                    }

                    Console.WriteLine("Response Header for retrieve schedule request");

                    Dictionary <string, dynamic> headerRef = new Dictionary <string, dynamic>();
                    headerRef.Add("getdata", rtrvSchResp.fileDatas[i].headers.getdataHeaders);
                    headerRef.Add("gethistory", rtrvSchResp.fileDatas[i].headers.gethistoryHeaders);
                    headerRef.Add("getquotes", rtrvSchResp.fileDatas[i].headers.getquotesHeaders);
                    headerRef.Add("getallquotes", rtrvSchResp.fileDatas[i].headers.getallquotesHeaders);
                    headerRef.Add("getactions", rtrvSchResp.fileDatas[i].headers.getactionsHeaders);
                    headerRef.Add("getcompany", rtrvSchResp.fileDatas[i].headers.getcompanyHeaders);
                    headerRef.Add("getfundamentals", rtrvSchResp.fileDatas[i].headers.getfundamentalsHeaders);

                    foreach (KeyValuePair <string, dynamic> header in headerRef)
                    {
                        if (header.Value != null)
                        {
                            Console.WriteLine("ProgramName: " + header.Key);
                            Console.WriteLine("Date: " + header.Value.rundate +
                                              " Time: " + header.Value.time + " Scheduled: " +
                                              header.Value.programflag);

                            if (rtrvSchResp.fileDatas[i].fields != null)
                            {
                                Console.WriteLine("Fields");
                                for (int j = 0; j < rtrvSchResp.fileDatas[i].fields.Length; j++)
                                {
                                    Console.WriteLine(rtrvSchResp.fileDatas[i].fields[j]);
                                }
                            }

                            if (rtrvSchResp.fileDatas[i].instruments != null)
                            {
                                Console.WriteLine("Instruments");
                                for (int j = 0; j < rtrvSchResp.fileDatas[i].instruments.instrument.Length; j++)
                                {
                                    Console.WriteLine("ID: " + rtrvSchResp.fileDatas[i].instruments.instrument[j].id +
                                                      " Type: " + rtrvSchResp.fileDatas[i].instruments.instrument[j].type);
                                }
                            }
                        }
                    }
                }

                // Sending a request to cancel the request for the daily job

                CancelHeaders cancelHeaders = new CancelHeaders();
                cancelHeaders.programflag = ProgramFlag.daily;

                SubmitCancelRequest sbCancelReq = new SubmitCancelRequest();

                // use the responce id of the original multiday request submitted above.
                sbCancelReq.responseId = new string[] { sbmtGetDtResp.responseId };
                sbCancelReq.headers    = cancelHeaders;

                Console.WriteLine("Submit Cancel request");

                submitCancelRequestRequest  sbCancelReqReq  = new submitCancelRequestRequest(sbCancelReq);
                submitCancelRequestResponse sbCancelReqResp = ps.submitCancelRequest(sbCancelReqReq);
                SubmitCancelResponse        sbCancelResp    = sbCancelReqResp.submitCancelResponse;

                if (sbCancelResp.statusCode.code == 0)
                {
                    Console.WriteLine("Submit Cancel request response ID: " + sbCancelResp.responseId);
                }

                // Checked the scheduled request to check if the daily job has been removed
                SubmitScheduledRequest sbmtSchReqCheck = new SubmitScheduledRequest();

                Console.WriteLine("Submit scheduled request");

                submitScheduledRequestRequest  sbmtSchReqReqCheck  = new submitScheduledRequestRequest(sbmtSchReqCheck);
                submitScheduledRequestResponse sbmtSchReqRespCheck = ps.submitScheduledRequest(sbmtSchReqReqCheck);
                SubmitScheduledResponse        sbmtSchRespCheck    = sbmtSchReqRespCheck.submitScheduledResponse;

                Console.WriteLine("Submit Schedule request responseID : " + sbmtSchRespCheck.responseId + "\n");

                Console.WriteLine("Retrieve scheduled request");
                RetrieveScheduledRequest schReqCheck = new RetrieveScheduledRequest();
                schReqCheck.responseId = sbmtSchRespCheck.responseId;

                retrieveScheduledResponseRequest  schRespReqCheck = new retrieveScheduledResponseRequest(schReqCheck);
                retrieveScheduledResponseResponse schRespRespCheck;

                RetrieveScheduledResponse schRespCheck;
                int pollCnt = 0;
                do
                {
                    System.Threading.Thread.Sleep(PerSecurity.PollInterval);
                    schRespRespCheck = ps.retrieveScheduledResponse(schRespReqCheck);
                    schRespCheck     = schRespRespCheck.retrieveScheduledResponse;
                    pollCnt++;
                }while (schRespCheck.fileDatas == null && pollCnt < 5); // Keep polling for few times

                Console.WriteLine("response ID for retrieveSchedule respone: " + schRespCheck.responseId);

                bool   flag       = false;
                string dispRespId = null;
                if (schRespCheck.fileDatas != null)
                {
                    for (int i = 0; i < schRespCheck.fileDatas.Length; i++)
                    {
                        if (schRespCheck.fileDatas[i].responseId == sbmtGetDtResp.responseId)
                        {
                            flag       = true;
                            dispRespId = schRespCheck.fileDatas[i].responseId;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    Console.WriteLine("The daily job with response ID: " + dispRespId +
                                      " was not cancelled successfully");
                }
                else
                {
                    Console.WriteLine("The daily job was cancelled successfully");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + e.StackTrace);
            }
        }
예제 #3
0
		public void run(PerSecurityWS ps)
		{
			try
			{
				//Setting overrides
				Override[] ovride = new Override[4];
				ovride[0] = new Override();
				ovride[0].field = "VWAP_START_DT";
                DateTime start = DateTime.Today;
                ovride[0].value = start.ToString();// "20080227";
				ovride[1] = new Override();
				ovride[1].field = "VWAP_END_DT";
                DateTime end = DateTime.Today.Subtract(TimeSpan.FromDays(5));
                ovride[1].value = end.ToString();//"20080227";
                ovride[2] = new Override();
				ovride[2].field = "VWAP_START_TIME";
				ovride[2].value = "1000";
				ovride[3] = new Override();
				ovride[3].field = "VWAP_END_TIME";
				ovride[3].value = "1100";
			
				//Setting the instruments for request
				Instrument bbUniqueId = new Instrument();
                bbUniqueId.id = "EQ0086119600001000";
				bbUniqueId.yellowkeySpecified = false;
				bbUniqueId.type = InstrumentType.BB_UNIQUE;
				bbUniqueId.typeSpecified = true;
				bbUniqueId.overrides = ovride;

				Instrument ticker = new Instrument();
				ticker.id = "IBM US";
				ticker.yellowkeySpecified = true;
				ticker.yellowkey = MarketSector.Equity;
				ticker.typeSpecified = false;
				ticker.type = InstrumentType.TICKER;
				ticker.overrides = ovride;
				
				
				//Setting request header
				GetDataHeaders getDataHeaders = new GetDataHeaders();
				getDataHeaders.secmaster = true;
				getDataHeaders.secmasterSpecified = true;
                getDataHeaders.closingvalues = true;
				getDataHeaders.closingvaluesSpecified = true;
			    getDataHeaders.programflag = ProgramFlag.daily;
				getDataHeaders.rundate = DateTime.Today.ToString();
				getDataHeaders.time = "1430";
           		getDataHeaders.derived = true;

				//Submit get data request
				Console.WriteLine("Submit get data request");
				SubmitGetDataRequest sbmtGtDrReq = new SubmitGetDataRequest();
				sbmtGtDrReq.headers = getDataHeaders;
				sbmtGtDrReq.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};
                sbmtGtDrReq.instruments = instrs;
				SubmitGetDataResponse sbmtGetDtResp= ps.submitGetDataRequest(sbmtGtDrReq);
				System.Console.WriteLine("Submit get data response Id = "  + sbmtGetDtResp.responseId + "\n");
			
				System.Threading.Thread.Sleep(100000);
				//Submit scheduled request for the get data request sent above
				Console.WriteLine("Submit scheduled request");
				SubmitScheduledRequest sbmtSchReq =  new SubmitScheduledRequest();
				SubmitScheduledResponse sbmtSchResp = ps.submitScheduledRequest(sbmtSchReq);
				Console.WriteLine("Submit Schedule request responseID : " + sbmtSchResp.responseId + "\n");
		    
				//Submit retrieve scheduled request to display all the scheduled files and check to see
				//if the daily job requested was addeds
				Console.WriteLine("Retrieve scheduled request");
				RetrieveScheduledRequest schReq = new RetrieveScheduledRequest();
				schReq.responseId = sbmtSchResp.responseId;
				RetrieveScheduledResponse schResp = new RetrieveScheduledResponse();
				
				//Keep sending the request until the entire response is received
				do
			   {
					System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
					schResp = ps.retrieveScheduledResponse(schReq);
				}
				while(schResp.statusCode.code==PerSecurity.DATA_NOT_AVAILABLE);
				Console.WriteLine(schResp.responseId);
             
				for(int i=0;i<schResp.fileDatas.Length;i++)
				{
                    if (schResp.fileDatas[i].responseId == sbmtGetDtResp.responseId)
                        Console.WriteLine("Response ID requested by submit get data request: " + 
                            schResp.fileDatas[i].responseId);
                    else
                        Console.WriteLine("Response ID: " + schResp.fileDatas[i].responseId + "\n");
					Console.WriteLine("Response Header for retrieve schedule request");
					Console.WriteLine("Date: " +  schResp.fileDatas[i].headers.getdataHeaders.rundate + 
                        " Time: " + schResp.fileDatas[i].headers.getdataHeaders.time + " Scheduled: " + 
                        schResp.fileDatas[i].headers.getdataHeaders.programflag);
					Console.WriteLine("Fields");
					for(int j=0;j<schResp.fileDatas[i].fields.Length;j++)
					{
						Console.WriteLine(schResp.fileDatas[i].fields[j]);
					}
					Console.WriteLine("Instruments");
					for(int j=0;j<schResp.fileDatas[i].instruments.instrument.Length;j++)
					{
                        Console.WriteLine("ID: " + schResp.fileDatas[i].instruments.instrument[j].id + 
                            "Type: " + schResp.fileDatas[i].instruments.instrument[j].type);
					}
						
				}
				
				//Sending a request to cancel the request for the daily job
				Console.WriteLine("Submit Cancel request");
				CancelHeaders cancelHeaders = new CancelHeaders();
				cancelHeaders.programflag  = ProgramFlag.daily;
				SubmitCancelRequest sbCancelReq = new SubmitCancelRequest();
				sbCancelReq.responseId[0] = sbmtGetDtResp.responseId;
				sbCancelReq.headers = cancelHeaders;
				Boolean flag = true;
				SubmitCancelResponse sbCancelResp = ps.submitCancelRequest(sbCancelReq);
				if(sbCancelResp.statusCode.code==0)
				{
					Console.WriteLine("Submit Cancel request response ID: " + sbCancelResp.responseId);
				}
				
				//Checked the scheduled request to check if the daily job has been removed
				Console.WriteLine("Submit scheduled request");
				SubmitScheduledRequest sbmtSchReqCheck = new SubmitScheduledRequest();
				SubmitScheduledResponse sbmtSchRespCheck = ps.submitScheduledRequest(sbmtSchReqCheck);
				Console.WriteLine("Submit Schedule request responseID : " + sbmtSchRespCheck.responseId + "\n");
				
				Console.WriteLine("Retrieve scheduled request");
				RetrieveScheduledRequest schReqCheck = new RetrieveScheduledRequest();
				schReqCheck.responseId = sbmtSchRespCheck.responseId;
				RetrieveScheduledResponse schRespCheck = new RetrieveScheduledResponse();
				do
				{
					System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
					schRespCheck = ps.retrieveScheduledResponse(schReqCheck);
				}
				while(schRespCheck.fileDatas==null);
				Console.WriteLine("response ID for retrieveSchedule respone: " + schResp.responseId);
				String dispRespId = null;
				for(int i=0;i<schRespCheck.fileDatas.Length;i++)
				{
					
					if(schRespCheck.fileDatas[i].responseId==sbmtGetDtResp.responseId)
					  
					{
						flag= true;
						dispRespId	= schRespCheck.fileDatas[i].responseId;
					}
					else
						flag=false;
						
				}
				if(flag)
					Console.WriteLine("The daily job with response ID: " + dispRespId + 
                        "wasnt cancelled successfully");
				else
					Console.WriteLine("The daily job was cancelled successfully");
			}
			catch(Exception e)
			{
				Console.WriteLine(e.Message + e.StackTrace);
			}

			
		}