Example #1
0
        public bool GetCurrencyRates1(DataTable exchangeRates)
        {
            DataRow dr;
            int     noOfRates;

            PerSecurityWSClient ps = new PerSecurityWSClient("PerSecurityHttpPort");
            //PerSecurityWSClient ps = new PerSecurityWSClient("PerSecurityHttpsPort");
            // PerSecurityWSClient ps = new PerSecurityWSClient("PerSecurityWSPort");

            //X509Certificate2 clientCert = new X509Certificate2(certificatePath);

            X509Certificate2 clientCert = GetBloomBergCertificate();

            ps.ClientCredentials.ClientCertificate.Certificate = clientCert;



            //Setting request header information
            GetDataHeaders getDataHeaders = new GetDataHeaders
            {
                secmaster              = true,
                secmasterSpecified     = true,
                closingvalues          = true,
                closingvaluesSpecified = true
            };

            // Console.WriteLine("test 1 ");
            noOfRates = exchangeRates.Rows.Count;
            if (noOfRates < 1)
            {
                return(true);
            }

            SubmitGetDataRequest sbmtGtDtreq = new SubmitGetDataRequest
            {
                headers = getDataHeaders,
                fields  = CurrencyTypeToFetch(),

                //Old version
                instruments = new Instrument[noOfRates] // { ticker1};
            };

            //sbmtGtDtreq.instruments = new Instruments();
            //sbmtGtDtreq.instruments.instrument = new Instrument[noOfRates];

            for (int i = 0; i < noOfRates; i++)
            {
                dr = exchangeRates.Rows[i];

                //Old version
                sbmtGtDtreq.instruments[i] = new Instrument
                {
                    id                 = dr.ItemArray[0].ToString(),
                    yellowkey          = MarketSector.Curncy,
                    yellowkeySpecified = true
                };
                //sbmtGtDtreq.instruments.instrument[i] = new Instrument();
                //sbmtGtDtreq.instruments.instrument[i].id = dr.ItemArray[0].ToString();
                //sbmtGtDtreq.instruments.instrument[i].yellowkey = MarketSector.Curncy;
                //sbmtGtDtreq.instruments.instrument[i].yellowkeySpecified = true;
            } // end for

            try
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
                SubmitGetDataResponse sbmtGtDtresp = new SubmitGetDataResponse();

                sbmtGtDtresp = ps.submitGetDataRequest(sbmtGtDtreq);
            }
            catch (Exception exx)
            {
                Console.WriteLine(exx.Message);
                return(false);
            }
            return(true);
        }
Example #2
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);
            }
        }