Example #1
0
        private static void Main(string[] args)
        {
            try
            {
                ProgramFlag programFlag = default(ProgramFlag);
                string      sampleName  = string.Empty;

                Dictionary <string, ProgramFlag> programFlagRef = new Dictionary <string, ProgramFlag>();
                programFlagRef.Add("adhoc", ProgramFlag.adhoc);
                programFlagRef.Add("scheduled", ProgramFlag.oneshot);

                Parser.Default.ParseArguments <Options>(args)
                .WithParsed <Options>(opts =>
                {
                    if (!programFlagRef.ContainsKey(opts.ProgramFlag))
                    {
                        Console.WriteLine("Unrecognized programFlag " + opts.ProgramFlag + "\n");
                        Console.WriteLine(Options.ProgramFlagHelpText);
                        Environment.Exit(1);
                    }
                    programFlag = programFlagRef[opts.ProgramFlag];
                    sampleName  = opts.SampleName;
                })
                .WithNotParsed <Options>(opts =>
                {
                    Environment.Exit(1);
                });

                string           clientCertFilePath = ConfigurationManager.AppSettings["clientCertFilePath"];
                string           clientCertPassword = ConfigurationManager.AppSettings["clientCertPassword"];
                X509Certificate2 clientCert         = new X509Certificate2(clientCertFilePath, clientCertPassword);

                PerSecurity_Dotnet.PerSecurityWSDL.PerSecurityWSClient ps = new PerSecurityWSClient("PerSecurityWSPort");
                ps.ClientCredentials.ClientCertificate.Certificate = clientCert;

                /*Add following lines for proxy
                 * NetworkCredential nc = new NetworkCredential("username", "password", "domain");
                 * WebProxy proxy = new WebProxy("http//webproxyserver:80");
                 * proxy.Credentials = nc;
                 * ps.Proxy = proxy;
                 */
                switch (sampleName)
                {
                case "GetData":
                    // Making request for non-bulk fields
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetData smpReq = new GetData();
                    smpReq.run(ps);
                    break;

                case "GetDataPricingSourceHeader":
                    // Making GetData request with a Pricing Source in header
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetDataPricingSourceHeader getDataPricingSrcHdrReq = new GetDataPricingSourceHeader();
                    getDataPricingSrcHdrReq.run(ps);
                    break;

                case "Scheduled":
                    // Making scheduled request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    Scheduled schReq = new Scheduled();
                    schReq.run(ps);
                    break;

                case "GetDataBulkFields":
                    // Making GetData request with bulk fields
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetDataBulkFields blkReq = new GetDataBulkFields();
                    blkReq.run(ps);
                    break;

                case "GetDataMacro":
                    // Making request for Macro requests
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetDataMacro mcroReq = new GetDataMacro();
                    mcroReq.run(ps);
                    break;

                case "GetHistory":
                    // Making History request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetHistory histReq = new GetHistory();
                    histReq.run(ps);
                    break;

                case "GetHistoryMacro":
                    // Making History request with a macro
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetHistoryMacro histMacrReq = new GetHistoryMacro();
                    histMacrReq.run(ps);
                    break;

                case "GetHistoryPricingSourceHeader":
                    // Making History request with a Pricing Source in header
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetHistoryPricingSourceHeader pricingSrcHdrReq = new GetHistoryPricingSourceHeader();
                    pricingSrcHdrReq.run(ps);
                    break;

                case "GetCompany":
                    // Making a Get Company request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetCompany getCompReq = new GetCompany();
                    getCompReq.run(ps);
                    break;

                case "GetQuotes":
                    // Making a Get Quotes request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetQuotes getQuotesReq = new GetQuotes();
                    getQuotesReq.run(ps, programFlag);
                    break;

                case "GetActions":
                    // Making a Get Actions request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetActions getActionsReq = new GetActions();
                    getActionsReq.run(ps);
                    break;

                case "Cancel":
                    // Making a Cancel request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    Cancel cancelReq = new Cancel();
                    cancelReq.run(ps);
                    break;

                case "PortfolioValidation":
                    // Making a get portfolio validation request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    PortfolioValidation portFolioVldtn = new PortfolioValidation();
                    portFolioVldtn.run(ps);
                    break;

                case "GetDataFieldSet":
                    // Making a getdata request with fieldset
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetDataFieldSet gtDtFldStReq = new GetDataFieldSet();
                    gtDtFldStReq.run(ps);
                    break;

                case "GetAllQuotes":
                    // Making a getallquotes request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetAllQuotes gtAllQtsReq = new GetAllQuotes();
                    gtAllQtsReq.run(ps, programFlag);
                    break;

                case "GetCompanyFieldSet":
                    // Making a getcompany fieldset request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetCompanyFieldSet gtCmpnyFldSet = new GetCompanyFieldSet();
                    gtCmpnyFldSet.run(ps);
                    break;

                case "GetDataOverrides":
                    // Making a simple getdata request with overrides
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetDataOverrides smpReqOvr = new GetDataOverrides();
                    smpReqOvr.run(ps);
                    break;

                case "GetFields":
                    // Making a getFields request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetFields sbmtGtFldsReq = new GetFields();
                    sbmtGtFldsReq.run(ps);
                    break;

                case "GetCorrections":
                    // Making a getCorrections request
                    Console.WriteLine("\n**********Running " + sampleName + " sample**********\n");
                    GetCorrections sbmtGtCorrReq = new GetCorrections();
                    sbmtGtCorrReq.run(ps);
                    break;

                default:
                    Console.WriteLine("Unrecognized sampleName " + sampleName + "\n");
                    Console.WriteLine(Options.SampleNameHelpText);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #2
0
        public void run(PerSecurityWSDL.PerSecurityWS ps, ProgramFlag pf)
        {
            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;
                headers.programflag          = pf;
                headers.programflagSpecified = true;

                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 smtGetQtsReq = new SubmitGetQuotesRequest();
                smtGetQtsReq.headers     = headers;
                smtGetQtsReq.instruments = instrs;

                Console.WriteLine("Sending submit get quotes request");

                submitGetQuotesRequestRequest  smtGetQtsReqReq  = new submitGetQuotesRequestRequest(smtGetQtsReq);
                submitGetQuotesRequestResponse smtGetQtsReqResp = ps.submitGetQuotesRequest(smtGetQtsReqReq);
                SubmitGetQuotesResponse        smtGetQtsResp    = smtGetQtsReqResp.submitGetQuotesResponse;;

                Console.WriteLine("Submit get quotes request status: " + smtGetQtsResp.statusCode.description +
                                  " responseId: " + smtGetQtsResp.responseId);

                RetrieveGetQuotesRequest rtrvGetQtsReq = new RetrieveGetQuotesRequest();
                rtrvGetQtsReq.responseId = smtGetQtsResp.responseId;

                retrieveGetQuotesResponseRequest  rtrvGetQtsRespReq = new retrieveGetQuotesResponseRequest(rtrvGetQtsReq);
                retrieveGetQuotesResponseResponse rtrvGetQtsRespResp;

                RetrieveGetQuotesResponse rtrvGetQtsResp;

                Console.WriteLine("Sending retrieve get quotes request");

                // Keep polling for response till the data is available
                do
                {
                    System.Threading.Thread.Sleep(PerSecurity.PollInterval);
                    rtrvGetQtsRespResp = ps.retrieveGetQuotesResponse(rtrvGetQtsRespReq);
                    rtrvGetQtsResp     = rtrvGetQtsRespResp.retrieveGetQuotesResponse;
                } while (rtrvGetQtsResp.statusCode.code == PerSecurity.DataNotAvailable);

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