コード例 #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
        /// <summary>
        /// This example Bloomberg request starts a session meant for Reference Requests and requests a few fields for several securities.
        /// I pulled this example code almost line-for-line from section C.1 of the Bloomberg API Developer's Guide
        /// </summary>
        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 refDataService = session.GetService("//blp/refdata");
                if (refDataService == null)
                {
                    Console.WriteLine("Cannot get service");
                }
                else
                {
                    Request request = refDataService.CreateRequest("IntradayTickRequest");

                    string security = "SPY US Equity";
                    //security = "ZYZZ US EQUITY";  //the code treats securities that start with a "Z" as non-existent
                    request.Set("security", security);

                    request.Append("eventTypes", "TRADE"); //One of TRADE (default), BID, ASK, BID_BEST, ASK_BEST, MID_PRICE, AT_TRADE, BEST_BID, BEST_ASK (see documentation A.2.6 for explanations)
                    request.Append("eventTypes", "BID");   //A request can have multiple eventTypes
                    //Note 1) refDataService.ToString() using the Bloomberg API indicates an additional eventType called "SETTLE".  "SETTLE" doesn't seem to produce any results.
                    //Note 2) If you request an eventType that isn't supported, the API will throw a KeyNotSupportedException at the "request.Append("eventType", "XXX")" line
                    //Note 3) eventType values are case-sensitive.  Requesting "bid" instead of "BID" will throw a KeyNotSupportedException at the "request.Append("eventType", "bid")" line

                    DateTime dtYesterday = DateTime.Today.AddDays(-1);
                    while (dtYesterday.DayOfWeek == DayOfWeek.Saturday || dtYesterday.DayOfWeek == DayOfWeek.Sunday)
                    {
                        dtYesterday = dtYesterday.AddDays(-1);
                    }

                    request.Set("startDateTime", new Datetime(dtYesterday.AddHours(9.5).ToUniversalTime()));
                    request.Set("endDateTime", new Datetime(dtYesterday.AddHours(11).ToUniversalTime())); //goes back at most 140 days (documentation section 7.2.3)

                    //A comma delimited list of exchange condition codes associated with the event. Review QR<GO> for more information on each code returned.
                    request.Set("includeConditionCodes", false); //Optional bool. Valid values are true and false (default = false)

                    //Returns all ticks, including those with condition codes.
                    request.Set("includeNonPlottableEvents", false); //Optional bool. Valid values are true and false (default = false)

                    //The exchange code where this tick originated. Review QR<GO> for more information.
                    request.Set("includeExchangeCodes", false); //Optional bool. Valid values are true and false (default = false)

                    //Option on whether to return EIDs for the security.
                    request.Set("returnEids", false); //Optional bool. Valid values are true and false (default = false)

                    //The broker code for Canadian, Finnish, Mexican, Philippine, and Swedish equities only.
                    //  The Market Maker Lookup screen, MMTK<GO>, displays further information on market makers and their corresponding codes.
                    request.Set("includeBrokerCodes", false); //Optional bool. Valid values are true and false (default = false)

                    //The Reporting Party Side. The following values appear:
                    //  -B: A customer transaction where the dealer purchases securities from the customer.
                    //  -S: A customer transaction where the dealer sells securities to the customer.
                    //  -D: An inter-dealer transaction (always from the sell side).
                    request.Set("includeRpsCodes", false); //Optional bool. Valid values are true and false (default = false)

                    //The BIC, or Bank Identifier Code, as a 4-character unique identifier for each bank that executed and reported the OTC trade, as required by MiFID.
                    //  BICs are assigned and maintained by SWIFT (Society for Worldwide Interbank Financial Telecommunication).
                    //  The MIC is the Market Identifier Code, and this indicates the venue on which the trade was executed.
                    request.Set("includeBicMicCodes", false); //Optional bool. Valid values are true and false (default = false)

                    CorrelationID corr = new CorrelationID(17);
                    session.SendRequest(request, corr);

                    bool continueToLoop = true;
                    while (continueToLoop)
                    {
                        Event evt = session.NextEvent();

                        switch (evt.Type)
                        {
                        case Event.EventType.RESPONSE:
                            IntradayTickDataRequest.ProcessResponse(evt, security);
                            continueToLoop = false;
                            break;

                        case Event.EventType.PARTIAL_RESPONSE:
                            IntradayTickDataRequest.ProcessResponse(evt, security);
                            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.");
            }
        }