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(); }
private static void ProcessEvent(Event evt, Session session) { switch (evt.Type) { case Event.EventType.SESSION_STATUS: //use this to open the service foreach (Message message in evt.GetMessages()) { if (message.MessageType.Equals("SessionStarted")) { try { session.OpenServiceAsync("//blp/mktdata", new CorrelationID(-9999)); } catch (Exception) { Console.Error.WriteLine("Could not open //blp/mktdata for async"); } } } break; case Event.EventType.SERVICE_STATUS: //use this to subscribe to ticker feeds List <Subscription> slist = new List <Subscription>(); //Conflate the data to show every two seconds. // Please note that the Bloomberg API Emulator code does not treat this exactly correct: individual subscriptions should each have their own interval setting. // I have not coded that in the emulator. List <string> options = new string[] { "interval=2", "start_time=16:22", "end_time=16:23" }.ToList(); //2 seconds. //Comment this line to receive a subscription data event whenever it happens in the market. //uncomment the following line to see what a request for a nonexistent security looks like //slist.Add(new Subscription("ZYZZ US EQUITY", MarketDataRequest._fields, options)); // My code treats all securities that start with a 'Z' as a nonexistent security slist.Add(new Subscription("SPY US EQUITY", MarketDataRequest._fields, options)); slist.Add(new Subscription("AAPL 150117C00600000 EQUITY", MarketDataRequest._fields, options)); session.Subscribe(slist); break; case Event.EventType.SUBSCRIPTION_DATA: case Event.EventType.RESPONSE: case Event.EventType.PARTIAL_RESPONSE: MarketDataRequest.ProcessEvent(evt); break; case Event.EventType.SUBSCRIPTION_STATUS: foreach (var msg in evt.GetMessages()) { bool fieldExceptionsExist = msg.MessageType.ToString() == "SubscriptionStarted" && msg.HasElement("exceptions", true); bool securityError = msg.MessageType.ToString() == "SubscriptionFailure" && msg.HasElement("reason", true); if (fieldExceptionsExist) { Element elmExceptions = msg["exceptions"]; for (int i = 0; i < elmExceptions.NumValues; i++) { Element elmException = elmExceptions.GetValueAsElement(i); string fieldId = elmException.GetElementAsString("fieldId"); Element elmReason = elmException["reason"]; string source = elmReason.GetElementAsString("source"); //int errorCode = elmReason.GetElementAsInt32("errorCode"); string category = elmReason.GetElementAsString("category"); string description = elmReason.GetElementAsString("description"); Console.Error.WriteLine("field error: "); Console.Error.WriteLine(string.Format("\tfieldId = {0}", fieldId)); Console.Error.WriteLine(string.Format("\tsource = {0}", source)); //Console.Error.WriteLine(string.Format("\terrorCode = {0}", errorCode)); Console.Error.WriteLine(string.Format("\tcategory = {0}", category)); Console.Error.WriteLine(string.Format("\tdescription = {0}", description)); } } else if (securityError) { string security = msg.TopicName; Element elmReason = msg["reason"]; string source = elmReason.GetElementAsString("source"); int errorCode = elmReason.GetElementAsInt32("errorCode"); string category = elmReason.GetElementAsString("category"); string description = elmReason.GetElementAsString("description"); Console.Error.WriteLine("security not found: "); Console.Error.WriteLine(string.Format("\tsecurity = {0}", security)); Console.Error.WriteLine(string.Format("\tsource = {0}", source)); Console.Error.WriteLine(string.Format("\terrorCode = {0}", errorCode)); Console.Error.WriteLine(string.Format("\tcategory = {0}", category)); Console.Error.WriteLine(string.Format("\tdescription = {0}", description)); } } break; default: foreach (var msg in evt.GetMessages()) { Console.WriteLine(msg.ToString()); } break; } }