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(); }
/// <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 = "localhost"; sessionOptions.ServerPort = 8194; Session session = new Session(sessionOptions); if (session.Start() && session.OpenService("//blp/refdata")) { Service refDataSvc = session.GetService("//blp/refdata"); if (refDataSvc == null) { Console.WriteLine("Cannot get service"); } else { CorrelationID requestID = new CorrelationID(1); Request request = refDataSvc.CreateRequest("ReferenceDataRequest"); { //append securities //request information for the following securities request.Append("securities", "SPY US EQUITY"); request.Append("securities", "AAPL 150117C00600000 EQUITY"); //this is a stock option: TICKER yyMMdd[C/P]\d{8} EQUITY //request.Append("securities", "ZYZZ US EQUITY"); //the code treats securities that start with a "Z" as non-existent request["securities"].AppendValue("MSFT US EQUITY"); //This is another way to append a security } { //append regular fields //include the following simple fields in the result //request.Append("fields", "ZPX_LAST"); //the code treats a field that starts with a "Z" as a bad field request.Append("fields", "PX_LAST"); request.Append("fields", "BID"); request.Append("fields", "ASK"); request.Append("fields", "TICKER"); request.Append("fields", "TRADEABLE_DT"); //hard-coded to be treated as a datetime to illustrated datetimes request.Append("fields", "OPT_EXPIRE_DT"); //only stock options have this field request["fields"].AppendValue("TICKER"); //This is another way to append a field } { //append an overridable field //request a field that can be overriden and returns bulk data request.Append("fields", "CHAIN_TICKERS"); //only stocks have this field Element overrides = request["overrides"]; //request only puts Element ovrdPutCall = overrides.AppendElement(); ovrdPutCall.SetElement("fieldId", "CHAIN_PUT_CALL_TYPE_OVRD"); ovrdPutCall.SetElement("value", "P"); //accepts either "C" for calls or "P" for puts //request 5 options in the result Element ovrdNumStrikes = overrides.AppendElement(); ovrdNumStrikes.SetElement("fieldId", "CHAIN_POINTS_OVRD"); ovrdNumStrikes.SetElement("value", 5); //accepts a positive integer //request options that expire on Dec. 20, 2014 Element ovrdDtExps = overrides.AppendElement(); ovrdDtExps.SetElement("fieldId", "CHAIN_EXP_DT_OVRD"); ovrdDtExps.SetElement("value", "20141220"); //accepts dates in the format yyyyMMdd (this is Dec. 20, 2014) } session.SendRequest(request, requestID); bool continueToLoop = true; while (continueToLoop) { Event eventObj = session.NextEvent(); switch (eventObj.Type) { case Event.EventType.RESPONSE: // final event continueToLoop = false; ReferenceDataRequest.handleResponseEvent(eventObj); break; case Event.EventType.PARTIAL_RESPONSE: ReferenceDataRequest.handleResponseEvent(eventObj); break; default: ReferenceDataRequest.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."); } }