Пример #1
0
        public void run(PerSecurityWS ps)
        {
            try
            {
                //Setting header information
                QuotesHeaders headers = new QuotesHeaders();
                DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 10, 10, 0);
                DateTime end = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 10, 11, 0);
                if (new DateTime().DayOfWeek == DayOfWeek.Saturday)
                {
                    TimeSpan ts1 = new TimeSpan(1, 0, 0, 0);
                   start= start.Subtract(ts1);
                  end=  end.Subtract(ts1);
                }
                else if (new DateTime().DayOfWeek == DayOfWeek.Sunday)
                {
                    start.AddDays(-2);
                    end.AddDays(-2);
                }

                DateTimeRange dtr = new DateTimeRange();
                dtr.startDateTime = start;
                dtr.endDateTime = end;
				dtr.region = "NY";
                headers.datetimerange = dtr;

                //Setting instruments
                Instrument ticker = new Instrument();
                ticker.id = "IBM US";
                ticker.yellowkeySpecified = true;
                ticker.typeSpecified = true;
                ticker.yellowkey = MarketSector.Equity;
                ticker.type = InstrumentType.TICKER;
                Instruments instrs = new Instruments();
                instrs.instrument = new Instrument[] { ticker };

                 SubmitGetAllQuotesRequest req = new SubmitGetAllQuotesRequest();
                req.headers = headers;
                req.instruments = instrs;
                
			Console.WriteLine("Sending submit get all quotes request");
	        SubmitGetAllQuotesResponse resp = ps.submitGetAllQuotesRequest(req);
	        String responseId = resp.responseId;
            Console.WriteLine("Submit get all quotes request status: " + resp.statusCode.description +
					 " responseId: " + resp.responseId);

            RetrieveGetAllQuotesRequest rreq = new RetrieveGetAllQuotesRequest();
	        rreq.responseId = responseId;
	        RetrieveGetAllQuotesResponse rresp = ps.retrieveGetAllQuotesResponse(rreq);
            Console.WriteLine("Sending retrieve get all quotes request");
			// Keep polling for response till the data is available
			do
			{
                System.Threading.Thread.Sleep(PerSecurity.POLL_INTERVAL);
				rresp = ps.retrieveGetAllQuotesResponse(rreq);
			} while (rresp.statusCode.code == PerSecurity.DATA_NOT_AVAILABLE);


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