예제 #1
0
        public void run(PerSecurityWS ps)
        {
            try
            {
                //Setting request header information
                GetFundamentalsHeaders getFundsHdrs = new GetFundamentalsHeaders();
                DateTime start = new DateTime(2008, 1, 1);
                DateTime end = DateTime.Today;
                getFundsHdrs.daterange = new DateRange();
                getFundsHdrs.daterange.period = new Period();
                getFundsHdrs.daterange.period.start = start;
                getFundsHdrs.daterange.period.end = end;
                getFundsHdrs.periodicity = Periodicity.a;

                

                //Setting instruments for request
                FundInstrument ticker = new FundInstrument();
                ticker.id = "JPM US";
                ticker.yellowkey = MarketSector.Equity;
                ticker.yellowkeySpecified = true;
                ticker.type = InstrumentType.TICKER;
                ticker.typeSpecified = true;

                FundInstruments instrs = new FundInstruments();
                instrs.instrument = new FundInstrument[] { ticker};

                //Setting fields for the request
                string[] field = new string[] { "FISCAL_YEAR_PERIOD", "LATEST_PERIOD_END_DT_FULL_RECORD","NET_REV"};

                //Submit get data request
                Console.WriteLine("Sending get Fundamentals request");
                SubmitGetFundamentalsRequest sbmtGtFundsReq = new SubmitGetFundamentalsRequest();
                sbmtGtFundsReq.headers = getFundsHdrs;
                sbmtGtFundsReq.fields = field;
                sbmtGtFundsReq.instruments = instrs;

                SubmitGetFundamentalsResponse sbmtGtFundsResp = ps.submitGetFundamentalsRequest(sbmtGtFundsReq);
                System.Console.WriteLine("status " + sbmtGtFundsResp.statusCode.description);
                System.Console.WriteLine("Submit Get Fundamentals request -  response ID = " + sbmtGtFundsResp.responseId);

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

                Console.WriteLine("Retrieve Fundamentals request");
                RetrieveGetFundamentalsRequest rtrvGtFundsReq = new RetrieveGetFundamentalsRequest();
                rtrvGtFundsReq.responseId = sbmtGtFundsResp.responseId;
                RetrieveGetFundamentalsResponse rtrvGtFundsResp = new RetrieveGetFundamentalsResponse();

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

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

                                    System.Console.WriteLine("	" + sbmtGtFundsReq.fields[j] + " : " +
                                        rtrvGtFundsResp.instrumentDatas[i].data[j].value);
                            }
                        }

                    }

                }
                else if (rtrvGtFundsResp.statusCode.code == PerSecurity.REQUEST_ERROR)
                    Console.WriteLine("Error in the submitted request");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "  " + e.StackTrace);
            }
        }