Пример #1
0
        public void run(PerSecurityWS ps)
        {
            try
            {
                //Setting headers
                QuotesHeaders headers = new QuotesHeaders();
                DateRange dr = new DateRange();
                DateTime start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                if (new DateTime().DayOfWeek == DayOfWeek.Saturday)
                {
                    TimeSpan ts1 = new TimeSpan(1, 0, 0, 0);
                    start = start.Subtract(ts1);
                  
                }
                else if (new DateTime().DayOfWeek == DayOfWeek.Sunday)
                {
                    start.AddDays(-2);
                
                }
                // 1 days worth of ticks
                Period dRange = new Period();
                dRange.start = start;
                dRange.end = start;
                dr.period = dRange ;

                headers.daterange = dr;

                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 };
	               
                //Sending Request
                  SubmitGetQuotesRequest req = new SubmitGetQuotesRequest();
                  req.headers = headers;
                  req.instruments = instrs;
			Console.WriteLine("Sending submit get quotes request");
	        SubmitGetQuotesResponse resp = ps.submitGetQuotesRequest(req);
	        String responseId = resp.responseId;
			Console.WriteLine("Submit get quotes request status: " + resp.statusCode.description +
					 " responseId: " + resp.responseId);
	        
	        RetrieveGetQuotesRequest rreq = new RetrieveGetQuotesRequest();
	        rreq.responseId  = responseId;
	        RetrieveGetQuotesResponse rresp = ps.retrieveGetQuotesResponse(rreq);
			Console.WriteLine("Sending retrieve get quotes request");

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

                	// Display data
			if (rresp.statusCode.code == PerSecurity.SUCCESS)
			{
				Console.WriteLine("Retrieve get 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++)
                    {
							Console.WriteLine("price =  "
                                    + rresp.instrumentDatas[i].quotes[j].price
									+ ", volume =  "
                                    + rresp.instrumentDatas[i].quotes[j].volume);
						}
					
				}
			}			
			else if (rresp.statusCode.code == PerSecurity.REQUEST_ERROR)
				Console.WriteLine("Error in submitted request");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }