예제 #1
0
파일: Program.cs 프로젝트: zeta1999/bemux
        static void Main(string[] args)
        {
            Console.WriteLine("Bloomberg API Emulator Examples");
            Console.WriteLine("http://bemu.codeplex.com/");
            Console.WriteLine("By: Robinson664");
            Console.WriteLine();

            Console.WriteLine("To send a historical data request, push 1");
            Console.WriteLine("To send a intraday bar data request, push 2");
            Console.WriteLine("To send a intraday tick data request, push 3");
            Console.WriteLine("To send a market data request, push 4");
            Console.WriteLine("To send a reference data request, push 5");

            string input = Console.ReadLine();

            Console.WriteLine();
            Console.WriteLine();
            bool informationReturned = true;

            switch (input)
            {
            case "1":
                HistoricalDataRequest.RunExample();
                break;

            case "2":
                IntradayBarDataRequest.RunExample();
                break;

            case "3":
                IntradayTickDataRequest.RunExample();
                break;

            case "4":
                MarketDataRequest.RunExample();
                break;

            case "5":
                ReferenceDataRequest.RunExample();
                break;

            default:
                informationReturned = false;
                break;
            }

            if (informationReturned)
            {
                Console.WriteLine();
                Console.WriteLine("Please note that the data in this request is completely random: it is not real data.");
                Console.WriteLine("Do not make any trading or investment decisions using the data shown here.");
            }
            Console.WriteLine();
            Console.WriteLine("Push enter to quit the application.");
            Console.ReadLine();
        }
예제 #2
0
        public static void RunExample()
        {
            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerHost = "127.0.0.1";
            sessionOptions.ServerPort = 8194;

            Session session = new Session(sessionOptions);

            if (session.Start() && session.OpenService("//blp/refdata"))
            {
                Service service = session.GetService("//blp/refdata");
                if (service == null)
                {
                    Console.WriteLine("Service is null");
                }
                else
                {
                    Request request = service.CreateRequest("HistoricalDataRequest");

                    //request information for the following securities
                    request.Append(HistoricalDataRequest._nSecurities, "MSFT US EQUITY");
                    request.Append("securities", "C A COMDTY");
                    request.Append("securities", "AAPL 150117C00600000 EQUITY"); //this is a stock option: TICKER yyMMdd[C/P]\d{8} EQUITY

                    //uncomment the following line to see what a request for a nonexistent security looks like
                    //request.Append("securities", "ZIBM US EQUITY");
                    //  My code treats all securities that start with a 'Z' as a nonexistent security

                    //include the following simple fields in the result
                    request.Append("fields", "BID"); //Note that the API will not allow you to use the HistoricalDataRequest._nBid name as a value here.  It expects a string.
                    request.Append("fields", "ASK"); //ditto

                    //uncomment the following line to see what a request for an invalid field looks like
                    //request.Append("fields", "ZBID");
                    //  My code treats all fields that start with a 'Z' as an invalid field

                    //Historical requests allow a few overrides.  See the developer's guide A.2.4 for more information.

                    request.Set("startDate", DateTime.Today.AddMonths(-1).ToString("yyyyMMdd")); //Request that the information start three months ago from today.  This override is required.
                    request.Set("endDate", DateTime.Today.AddDays(10).ToString("yyyyMMdd"));     //Request that the information end three days before today.  This is an optional override.  The default is today.

                    //Determine the frequency and calendar type of the output. To be used in conjunction with Period Selection.
                    request.Set("periodicityAdjustment", "CALENDAR"); //Optional string.  Valid values are ACTUAL (default), CALENDAR, and FISCAL.

                    //Determine the frequency of the output. To be used in conjunction with Period Adjustment.
                    request.Set("periodicitySelection", "DAILY"); //Optional string.  Valid values are DAILY (default), WEEKLY, MONTHLY, QUARTERLY, SEMI_ANNUALLY, and YEARLY

                    //Sets quote to Price or Yield for a debt instrument whose default value is quoted in yield (depending on pricing source).
                    request.Set("pricingOption", "PRICING_OPTION_PRICE"); //Optional string.  Valid values are PRICING_OPTION_PRICE (default) and PRICING_OPTION_YIELD

                    //Adjust for "change on day"
                    request.Set("adjustmentNormal", true); //Optional bool. Valid values are true and false (default = false)

                    //Adjusts for Anormal Cash Dividends
                    request.Set("adjustmentAbnormal", false); //Optional bool. Valid values are true and false (default = false)

                    //Capital Changes Defaults
                    request.Set("adjustmentSplit", true); //Optional bool. Valid values are true and false (default = false)

                    //The maximum number of data points to return, starting from the startDate
                    //request.Set("maxDataPoints", 5); //Optional integer.  Valid values are positive integers.  The default is unspecified in which case the response will have all data points between startDate and endDate

                    //Indicates whether to use the average or the closing price in quote calculation.
                    request.Set("overrideOption", "OVERRIDE_OPTION_CLOSE"); //Optional string.  Valid values are OVERRIDE_OPTION_GPA for an average and OVERRIDE_OPTION_CLOSE (default) for the closing price

                    CorrelationID requestID = new CorrelationID(1);
                    session.SendRequest(request, requestID);

                    bool continueToLoop = true;
                    while (continueToLoop)
                    {
                        Event eventObj = session.NextEvent();
                        switch (eventObj.Type)
                        {
                        case Event.EventType.RESPONSE:     // final event
                            continueToLoop = false;
                            HistoricalDataRequest.handleResponseEvent(eventObj);
                            break;

                        case Event.EventType.PARTIAL_RESPONSE:
                            HistoricalDataRequest.handleResponseEvent(eventObj);
                            break;

                        default:
                            HistoricalDataRequest.handleOtherEvent(eventObj);
                            break;
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("Cannot connect to server.  Check that the server host is \"localhost\" or \"127.0.0.1\" and that the server port is 8194.");
            }
        }