Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }